Constructing an approximate periodical function x(t) giving its Fourier series coefficient?
조회 수: 2 (최근 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/146612/image.png)
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!