Plotting Fourier Series Coefficients

조회 수: 5 (최근 30일)
goal24
goal24 2012년 6월 4일
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!

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 4일
bfun = matlabFunction(B, k);
kspan = linspace(0,40,100);
plot(kspan, bfun(kspan));
  댓글 수: 2
goal24
goal24 2012년 6월 4일
When I run this function right after my previous code, i receive an error:
Error using deal (line 38)
The number of outputs should match the number of inputs.
Error in
sym/matlabFunction>makeFhandle/@(k)deal((sin(pi.*k.*(1.0./4.0)).^2.*2.0)./(pi.*k),k)
Any suggestions how to fix this error?
goal24
goal24 2012년 6월 4일
Oh nvm I got it. Thank You!

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by