curves are incorrect. Fourier Series.
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Image Analyst
le 23 Août 2014
I fixed your formatting. Please read this: http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
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.
Réponses (1)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!