I want to Fourier transform the 'y' function using Euler's formulas.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
'y' is
x = [-pi:pi/10:pi];
sum=0;
y1=0;
for k=1:100
y1=(((cos(k*pi)-1).*cos(k*x))./(-pi*(k^2)));
sum=sum +y1;
end
y=sum+pi/2;
figure(1)
plot(x,y)
axis([-4 4 0.5 2.7])
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1557729/image.png)
I want to Fourier transform the 'y' function using Euler's formulas.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1557734/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1557739/image.png)
One cycle is 2pi. I'm not sure how to express this in Matlab. I need help.
0 commentaires
Réponse acceptée
Mathieu NOE
le 1 Déc 2023
here you are my friend :
clc
x = [-pi:pi/10:pi];
sum=0;
y1=0;
for k=1:100
y1=(((cos(k*pi)-1).*cos(k*x))./(-pi*(k^2)));
sum=sum +y1;
end
y=sum+pi/2;
% fourier series
a0 = trapz(x,y)/(2*pi);
m = 8;
for n = 1:m
a(n) = trapz(x,y.*cos(n*x))/pi;
b(n) = trapz(x,y.*sin(n*x))/pi;
end
% let's prove the fourier sum approximate y
yf = a0;
for n = 1:m
yf = yf + a(n)*cos(n*x) + b(n)*sin(n*x);
end
figure(1)
plot(x,y,'b',x,yf,'*--r')
axis([-4 4 0.5 2.7])
1 commentaire
Dyuman Joshi
le 1 Déc 2023
@Mathieu NOE - A request from me, would you please shift your answer to this thread? https://in.mathworks.com/matlabcentral/answers/2054864-incorrect-number-or-types-of-inputs-or-outputs-for-function-int
This one is duplicate of the question I linked. And it would be better if all discussion was on a single thread.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Surface and Mesh Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!