Fourier Series in matlab with for loop

23 ビュー (過去 30 日間)
Natalie Rolf
Natalie Rolf 2018 年 4 月 16 日
コメント済み: Birdman 2018 年 4 月 16 日
Hello, So I need to plot
with f_0 being constant 5000hz and t ranging 0 to 4 microseconds.
I have to cut the summation off after 1,2,3,4 and 5 iterations and store each in a vector, however I cannot even get the summation to work. I'm absolutely sure I'm doing it all wrong so if anyone could help me out I would appreciate it! Thanks!

回答 (1 件)

Birdman
Birdman 2018 年 4 月 16 日

You do not need a for loop. If you have Symbolic Toolbox, the following code should do it:

syms f(t) n
k=5; %upper limit for series
f0=5000;
f(t)=symsum((4/((2*n-1)*pi))*sin(2*pi*n*f0.*t),n,1,k)
  2 件のコメント
Natalie Rolf
Natalie Rolf 2018 年 4 月 16 日
I have to use a for loop for this assignment unfortunately.
Birdman
Birdman 2018 年 4 月 16 日
res=0;
k=5;f0=5000;
syms t
for i=1:k
res=res+(4/((2*i-1)*pi))*sin(2*pi*i*f0.*t);
end
res=vpa(res,3)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by