Fourier Series plotting in matlab

2 ビュー (過去 30 日間)
Carol
Carol 2015 年 5 月 3 日
コメント済み: Ahmet Cecen 2015 年 5 月 3 日
How do you plot the first ten harmonics of a fourier series that has a dc a0 component of 1 and a bn component of (4/npi)sin(npi/2t) and no an component. This code is giving me the value of the first ten harmonics but I don't know how to plot the summation
x=3/pi;
f=0;
t=linspace(-3,2)
for i=1:1:10
an=x*1/i
f=f+an*sin(i*(pi/2).*t);
end

回答 (1 件)

Ahmet Cecen
Ahmet Cecen 2015 年 5 月 3 日
編集済み: Ahmet Cecen 2015 年 5 月 3 日
Is this what you are looking for? There are better ways to do it, but for now focus on learning how the figure, plot and hold commands interact.
x=3/pi;
f=0;
t=linspace(-3,2)
figure;
hold on;
for i=1:1:10
an=x*1/i
f=f+an*sin(i*(pi/2).*t);
plot(t,f)
end
  2 件のコメント
Carol
Carol 2015 年 5 月 3 日
Ok how would you just plot it if you had it in the standard forurier form and you are trying to find the sum of the first ten harmonics because I don't think it is taking into account the dc
Ahmet Cecen
Ahmet Cecen 2015 年 5 月 3 日
If you just want the final signal:
x=3/pi;
f=0;
t=linspace(-3,2)
for i=1:1:10
an=x*1/i
f=f+an*sin(i*(pi/2).*t); % Summation Term
end
f=f+1; % Add DC A0 component to the final signal.
figure;plot(t,f);

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

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by