Plotting Fourier transform with heaviside functions

조회 수: 3 (최근 30일)
Mario
Mario 2014년 7월 17일
답변: Star Strider 2014년 7월 17일
Hi, when running this code
syms s(t)
syms j(w)
s(t) = 2 * cos(2*t + 1) * heaviside(t - 2*fix(t/2)) * heaviside(-t + 2/10 + 2*fix(t/2));
j(w) = fourier(s, t, w);
ezplot(j);
I get the following output
Error using inlineeval (line 15) Error in inline expression ==> 2.*fourier(heaviside(2.*fix(t./2) - t + 1./5).*cos(2.*t + 1).*heaviside(t - 2.*fix(t./2)), t, w) Undefined function 'fourier' for input arguments of type 'double'.
Error in inline/feval (line 34) INLINE_OUT_ = inlineeval(INLINE_INPUTS_, INLINE_OBJ_.inputExpr, INLINE_OBJ_.expr);
Error in ezplotfeval (line 54) z = feval(f,x(1),y(1));
Error in ezplot>ezimplicit (line 258) u = ezplotfeval(f, X, Y);
Error in ezplot (line 154) hp = ezimplicit(cax, f{1}, vars, labels, args{:});
Error in sym/ezplot (line 61) h = ezplot(fhandle(f));
Error in Untitled5 (line 7) ezplot(j);
Could anyone help me?

답변 (1개)

Star Strider
Star Strider 2014년 7월 17일
Using the fix function is well-intended but not necessary in symbolic operations. To use heaviside, you need to cast the arguments as symbolic to get a symbolic result. (You can always use matlabFunction to create an anonymous function out of it to use outside of the Symbolic Math Toolbox.)
This works:
syms s(t)
syms j(w)
s(t) = 2 * cos(2*t + 1) * heaviside(sym(t - 2*(t/2))) * heaviside(sym(-t + 2/10 + 2*(t/2)));
j(w) = fourier(s, t, w);
ezplot(j);
although the plot is not informative.

카테고리

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