Constructing an approximate periodical function x(t) giving its Fourier series coefficient?

조회 수: 1 (최근 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
MIRK
MIRK 2014년 12월 28일
i forgot to type +result in the above code
syms result t
for t =0 : 0.01 : 8
for N = -5 : 1 : 5
if( N == 0)
result =result + (0.5* exp(- j*2*pi * N * 0.5 * t));
else
result = result + ((j/2*pi*N)*exp(- j*2*pi * N * 0.5 * t));
end
end
end
ezplot(result,0,1)

댓글을 달려면 로그인하십시오.

답변 (1개)

Shoaibur Rahman
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))

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by