필터 지우기
필터 지우기

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 CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by