Function for fourier series
显示 更早的评论
hello
I have written a function for fourier series but when i try to plot it ,only the consine one shows up did I forget something ? Danke schön
function ft = signal(S,t,A,M,T,N)
for n=1:N
if S=="square"
ft=M+sum(((4*A)./(n.*pi)).*sin((n.*pi)/2).*cos((2*n.*pi.*t)./T));
elseif S=="triangle"
ft=M+sum(((8*A)./(n.^2*pi^2)).*cos((2*n*pi.*t)./T));
elseif S=="saw"
ft=M+sum(-1^(n+1).*(2*A./n.^pi).*sin((2*n.*pi*t)./T));
elseif S=="cosine"
ft=M+A*cos((2*pi.*t)./T);
end
end
%%plot part
M=0;
A=1;
T=10;
t=0:0.1:60;
N=10;
grid on
ft=signal("square",t,A,M,T,N);
plot(t,ft,'r')
hold on
ft=signal("triangle",t,A,M,T,N);
plot(t,ft,'b')
hold on
ft=signal("saw",t,A,M,T,N);
plot(t,ft,'g')
hold on
ft=signal("cosine",t,A,M,T,N);
plot(t,ft,'k')
%%
采纳的回答
更多回答(1 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
