Constructing an approximate periodical function x(t) giving its Fourier series coefficient?
2 views (last 30 days)
Show older comments
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
Answers (1)
Shoaibur Rahman
on 28 Dec 2014
Edited: Shoaibur Rahman
on 28 Dec 2014
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 Comments
See Also
Categories
Find more on Calculus in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!