フィルターのクリア

curves are incorrect. Fourier Series.

2 ビュー (過去 30 日間)
Nabhdeep Bansal
Nabhdeep Bansal 2014 年 8 月 23 日
回答済み: Rick Rosson 2014 年 8 月 24 日
I WANT TO PLOT A FOURIER SERIES FOR DIFFERENT HARMONICS AS PER THE Y~t RELATION DEFINED BELOW. (TIME PERIOD=2 SECS. Y=1 for first 0.8 secs and Y=-1 for next 1.2 secs).
THE CURVES ARE NOT CORRECT,I GUESS.
t=[-1,0,0,0.8,0.8,1]';
Y=[-1,-1,1,1,-1,-1];
f=0;
for n=1:20:40
line(t,Y,'color','r','linewidth',2)
grid on;
hold on;
A=0.5*trapz(t,Y);
P=Y.*(cos(n*pi*t))';
Q=Y.*(sin(n*pi*t))';
Ax=trapz(t,P);
Bx=trapz(t,Q);
f=f+(Ax*cos(pi*n*t)+Bx*sin(pi*n*t));
final=A+f;
plot(t,final,'linewidth',2)
end
  1 件のコメント
Image Analyst
Image Analyst 2014 年 8 月 23 日
and these:
"THE CURVES ARE NOT CORRECT,I GUESS." is not very descriptive. The code (after I fixed the formatting) did run and produce a plot. What would correct curves look like? Come on, make it easy for us to help you, not hard. Post a plot of what the curve should look like. If you can't use the debugger to figure out what's going wrong in this alphabet soup of code, then put in some comments, give the variables descriptive names to help up, and come back with any questions about your lastest, improved code.

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

回答 (1 件)

Rick Rosson
Rick Rosson 2014 年 8 月 24 日
I would recommend using the fft function.

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by