how can I write a function y(n) in terms of function x(n)?

5 views (last 30 days)
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');

Accepted Answer

Walter Roberson
Walter Roberson on 17 Mar 2018
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 Comments
Walter Roberson
Walter Roberson on 17 Mar 2018
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
Walter Roberson on 17 Mar 2018
Edited: Walter Roberson on 17 Mar 2018
"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)

Sign in to comment.

More Answers (1)

elham kreem
elham kreem on 17 Mar 2018
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

Categories

Find more on Price and Analyze Financial Instruments in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!