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

조회 수: 11 (최근 30일)
geometry geometry
geometry geometry 2018년 3월 17일
편집: Walter Roberson 2018년 3월 17일
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');

채택된 답변

Walter Roberson
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
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
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
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

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by