Constructing an approximate periodical function x(t) giving its Fourier series coefficient?
9 次查看(过去 30 天)
显示 更早的评论
I want to Constructing a code for periodical function x(t) for example from -5 to 5 and then plot it
Fourier series coefficient is a piece wise function
and the time increment is 0.01 from 0 up to 8
for me I am not expert in cooding and matlab I write this code
syms result t
for t =0 : 0.01 : 8
for N = -5 : 1 : 5
if( N == 0)
result = (0.5* exp(- j*2*pi * N * 0.5 * t));
else
result = ((j/2*pi*N)*exp(- j*2*pi * N * 0.5 * t));
end
end
end
ezplot(result,0,1)
The problem is the plot. it does not make sense its just a line increasing !!! for those who know matlab well. where is the problem in the code thank you
回答(1 个)
Shoaibur Rahman
2014-12-28
编辑:Shoaibur Rahman
2014-12-28
You can use a vectorized code to get the periodic signal:
f0 = 1; % set the frequency of desired signal
t = 0:0.01:8;
n = -5:5; % change as required
Xn = 1j./(2*pi*n);
Xn(n==0) = 1/2;
x = Xn * exp(-(1j*2*pi*n'*f0*t)); % n' in exp automatically does the sum!
plot(t,abs(x))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!