Plotting Fourier Series Coefficients

6 ビュー (過去 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 Center および File ExchangeSpectral Measurements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by