Problem seen in discrete transfer function with varable z^-1, when calc ztrans of x(n)=n*u(n)

조회 수: 2 (최근 30일)
Hi dears,
Who knows why X1 and X2 are not the same?
X2 should be (z^-1)/(1-z^-1)^2 or (z^-1)/(1 - 2 z^-1 + z^-2)
Thanks
sympref('HeavisideAtOrigin', 1); % by default u(0)=0.5 so we set U(0)=1
u = @(n) heaviside(n) ; % change function name
u0=u(0)
syms n
x(n)=n*u(n)
X1=ztrans(x)
[num, den] = numden(X1);
X2 = tf(sym2poly(num), sym2poly(den),-1, 'variable', 'z^-1')
X2_var=X2.variable
  댓글 수: 1
Walter Roberson
Walter Roberson 2022년 9월 29일
My tests show it is related to specifying the variable. If you let the variable default to 'z' then you get a z in the numerator

댓글을 달려면 로그인하십시오.

채택된 답변

Paul
Paul 2022년 9월 29일
편집: Paul 2022년 9월 30일
Code works exactly as advertised
u = @(n) heaviside(n) ; % change function name
syms n
x(n)=n*u(n)
x(n) = 
X1=ztrans(x)
X1 = 
[num, den] = numden(X1)
num = 
z
den = 
As documented in sym2poly, it returns the polynomial in descending powers of the variable, in this case z
sym2poly(num)
ans = 1×2
1 0
[1 0] is the poly representation of z.
sym2poly(den)
ans = 1×3
1 -2 1
Here, we are telling tf that sym2poly(num) is the poly representation with variable z^-1. But wrt to z^-1, [1 0] = 1 + 0*z^-1 = 1, which is exactly what we get.
X2 = tf(sym2poly(num), sym2poly(den),-1, 'variable', 'z^-1')
X2 = 1 ----------------- 1 - 2 z^-1 + z^-2 Sample time: unspecified Discrete-time transfer function.
So we need two steps
X2 = tf(sym2poly(num),sym2poly(den),-1)
X2 = z ------------- z^2 - 2 z + 1 Sample time: unspecified Discrete-time transfer function.
X2.Variable = 'z^-1'
X2 = z^-1 ----------------- 1 - 2 z^-1 + z^-2 Sample time: unspecified Discrete-time transfer function.
Finally, be very careful using heaviside. The default value of heaviside(0) is 1/2, which is (almost?) never what you want for discrete-time problems. It didn't matter here becasue u(0) = 0. Use sympref to control the value of heaviside(0).
  댓글 수: 9
Ahmad
Ahmad 2022년 9월 30일
Yes exactly numerator and denominator vectors must be the same size!
Paul
Paul 2022년 9월 30일
They only need to be the same size if that's what the problem requires. For an example of when it's not required
H(z) = (1 + z^-1) / (1 + 2*z^-1 + 3*z^-2)
H = tf([1 1],[1 2 3],-1,'Variable','z^-1')
H = 1 + z^-1 ------------------- 1 + 2 z^-1 + 3 z^-2 Sample time: unspecified Discrete-time transfer function.
You can, of course, zero-pad the numerator if you wish (zero-pad to the right for z^-1)
H = tf([1 1 0],[1 2 3],-1,'Variable','z^-1')
H = 1 + z^-1 ------------------- 1 + 2 z^-1 + 3 z^-2 Sample time: unspecified Discrete-time transfer function.
but you're not obligated to do so. The only reuqirement is that num and den represent the system for the Variable that's being used.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by