Plotting Fourier transform with heaviside functions
3 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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.
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!