Plotting Fourier Series Coefficients
조회 수: 5 (최근 30일)
이전 댓글 표시
Hi, I am trying to find Fourier coefficients of two signals: x(t) = u(t) - u(t-1) [0<t<2] and y(t) = u(t) - u(t-0.5) [0<t<1]. I have found the Fourier series coefficients through this code:
syms t k L n
evalin(symengine,'assume(k,Type::Integer)');
a = @(f,t,k,L) int(f*cos(k*pi*t/L)/L,t,-L,L);
b = @(f,t,k,L) int(f*sin(k*pi*t/L)/L,t,-L,L);
fs = @(f,t,n,L) a(f,t,0,L)/2 + ...
symsum(a(f,t,k,L)*cos(k*pi*t/L) + b(f,t,k,L)*sin(k*pi*t/L),k,1,n);
f = heaviside(t) - heaviside(t-1);
f1 = heaviside(t) - heaviside(t-0.5);
>> [B,how]=simple(b(f,t,k,1)); B
B =
(2*sin((pi*k)/2)^2)/(pi*k)
>> [B,how]=simple(b(f1,t,k,1)); B
B =
(2*sin((pi*k)/4)^2)/(pi*k)
However, I am unsure how to plot the magnitude line spectra of these two in the same figure from 0 to 40*pi rad/sec. I have tried ez plot but keep getting errors. I am new to this and not sure what to do. Thanks!
댓글 수: 0
채택된 답변
Walter Roberson
2012년 6월 4일
bfun = matlabFunction(B, k);
kspan = linspace(0,40,100);
plot(kspan, bfun(kspan));
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!