Fourier series of a sawtooth wave

3 ビュー (過去 30 日間)
Oscar Kilby
Oscar Kilby 2020 年 12 月 18 日
コメント済み: Pat Gipper 2020 年 12 月 18 日
Hello all,
I've been trying to display a fourier series of a sawtooth wave (first 10 harmonics) using the code below (its fairly poorly written i know)
V = 1;
T = 1;
w = 2*pi*(1/T);
t = linspace(0 , T, 1000);
fourierwave = ((2*V/pi)*sin(w*t)) + ((2*V/2*pi)*sin(2*w*t)) + ((2*V/3*pi)*sin(3*w*t)) + ((2*V/4*pi)*sin(4*w*t)) + ((2*V/5*pi)*sin(5*w*t)) + ((2*V/6*pi)*sin(6*w*t)) + ((2*V/7*pi)*sin(7*w*t)) + ((2*V/8*pi)*sin(8*w*t)) + ((2*V/9*pi)*sin(9*w*t)) + ((2*V/10*pi)*sin(10*w*t));
plot(t, fourierwave, 'g-');
However its giving me an incorrrect output when run and im not sure why, i've got some code that works correctly which ive compared to the code above and im not sure what's causing the difference in outputs.
Would someone be able to explain whats wrong with the code/equation above?

採用された回答

Pat Gipper
Pat Gipper 2020 年 12 月 18 日
You are multiplying by pi on the 2nd through 10th harmonics instead of dividing.
  2 件のコメント
Oscar Kilby
Oscar Kilby 2020 年 12 月 18 日
ah i see, i take it brackets are needed around the value for N and pi to fix this then?
Pat Gipper
Pat Gipper 2020 年 12 月 18 日
Correct. The plot will look much more sawtooth once you make this change.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by