how can I write a function y(n) in terms of function x(n)?
6 次查看(过去 30 天)
显示 更早的评论
I run this code and I get error. (the error is for function y which contains function x in its defenition). how can i fix this error? (The functions x and y are discrete signals)
syms n y x
n=-10:1:10;
x=dirac(n+1)+dirac(-n+4)-2*heaviside(n+3);
y(n)=x(n)-x(2*n+3);
plot(x,'o');
plot(y,'o');
0 个评论
采纳的回答
Walter Roberson
2018-3-17
syms n y x
x(n) = dirac(n+1)+dirac(-n+4)-2*heaviside(n+3);
y(n) = x(n)-x(2*n+3);
N=-10:1:10;
plot(N, subs(x,n,N), 'ko', N, subs(y,n,N), 'bo')
It will not look like much, since dirac() is only ever 0 or infinity.
4 个评论
Walter Roberson
2018-3-17
Calls of the form
plot(x1, y1, x2, y2)
are the same as
ax = gca;
curhold = get(ax, 'NextPlot');
plot(ax, x1, y1);
set(gca, 'NextPlot', 'add')
plot(x2, y2);
set(ax, 'NextPlot', curhold)
That is, passing multiple x, y pairs into plot() causes both lines to be plotted.
So the N, subs(x,n,N) part causes x to be plotted, and the N, subs(y,n,N) causes y to be plotted.
This might have given you the impression that y was not plotted because the y values consist only of 0s and infinities.
Walter Roberson
2018-3-17
编辑:Walter Roberson
2018-3-17
"which function should I use for discrete dirac signals? (i.e the function that is only one in time zero)"
You can use
Dirac = @(x) not(x)
if you can be certain that none of the values are nan. If nan is a possibility then use
Dirac = @(x) x == 0;
However, if you are working with symbolic values, then you need
Dirac = @(x) piecewise(x == 0, 1, 0)
更多回答(1 个)
elham kreem
2018-3-17
if you run x , it is a vector 1x21 , then when you used for y(n) , you will get for x a subscript more
than 21 ,such as if you have n=10 then you have x(23) , and this is not found.the result, it is not run
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Price and Analyze Financial Instruments 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!