How to do Z transform with Z^-1 format?

I want to do the Z transform of which theoretically is .
However, Matlab's Z transform function (ztrans) gives it in Z format and not in Z^-1 format.
The equation that ztrans(f) gives me is: .
I want to know if there is a clean way to get the Z transform in Z^-1 format as shown above.
If the code is generic and not specific to this example will help a lot.

 Accepted Answer

The only option I can think of has nothing to do with the Symbolic Math Toolbox, and is instead the Variable argument in the Control System Toolbox. That will allow you to specify z^-1 as the variable.
Since it woulld be best to use the Control System Toolbox anyway (the Symbolic Math Toolbox is not designed for efficient transfer function analysis), that would be my option.

9 Comments

I made this code with your answer and I think its a better way for displaying the Z transform in Z^-1 format.
syms n
f = (sqrt(9/10)^n)*cos((pi/2)*n);
H = ztrans(f);
[num, den] = numden(H);
H = tf(sym2poly(num), sym2poly(den),-1, 'variable', 'z^-1');
The answer was:
10
-------------
10 + 9z^-2
Great!
I am happy it worked for you!
Do you know how to express the result of tf in fractions? I tried with format rat but it didnt work for tf.
The Symbolic Math Toolbox normally does that on its own, and produces decimal equivalents only with the vpa function. I am not certain that I understand the problem, since none of your constants appear to be fractional.
I tried to do the same with another function.
syms n
format rat
f = n*(1/3)^n + (-1/4)^n
H = ztrans(f);
[num, den] = numden(H);
%Normalize
K = sym2poly(num);
K = K(1)
%Tf in z^-1 format
H = tf(sym2poly(num)/K, sym2poly(den)/K,-1, 'variable', 'z^-1'
The result was correct and was:
I wanted to know if there was an easy way to display the coefficients of this object as fractions.
The tf function is part of the Control System Toolbox, and uses only decimal fractions. You would likely have to do that manually, possibly using the rat or rats function. I have never needed to do that, at lelast with respect to a transfer function, so I have no experience with it.
Ok no problem I did it with rat function and using strings. The thing is that I've been trying using the tf approach with z^-1 as a variable but when I tried using heaviside the tf code gave me the wrong user while the ztrans gave me the right one.
This is the code:
clear;
syms x n
v = 1;
sympref('HeavisideAtOrigin', v);
x = heaviside(n-1);
H = ztrans(x)
[num, den] = numden(H);
H = tf(sym2poly(num), sym2poly(den), -1, 'variable', 'z^-1')
Answers:
Ztrans: (1/(z - 1) + 1)/z which is as well:
tf:
It seems that tf has problems with the delay in heaviside.
The heaviside function may not be correct. The delta function would be more likely to be correct. Consider the Laplace and z-transform versions of both. (Those are the bases of my preferences.)
The problem is that sym2poly returns the polynomial coefficient is descending powers of z. So the tf needs be created in z, and then changed to z^-1. Two step process:
syms x n
v = 1;
sympref('HeavisideAtOrigin', v);
x = heaviside(n-1);
H = ztrans(x)
H = 
[num, den] = numden(H);
H = tf(sym2poly(num), sym2poly(den), -1)
H = 1 ----- z - 1 Sample time: unspecified Discrete-time transfer function.
H.Variable = 'z^-1'
H = z^-1 -------- 1 - z^-1 Sample time: unspecified Discrete-time transfer function.

Sign in to comment.

More Answers (2)

Vinit
Vinit on 2 Nov 2023
Edited: Walter Roberson on 21 Jan 2024
clear all
close all
clc
V = 220;
R = 10;
L = 0.051;
dt = le-3;
t = 0:dt:0.05;
y = [0];
for k =1:length(t)-1
y (K+1)=(1-R*dt/L)*y(k)+dt*(1/L)*V;
end
figure(1)
plot(t,y)
grid on
xlabel ('time (s)')
ylabel ('current (Amp)')
Vinit
Vinit on 2 Nov 2023
Edited: Walter Roberson on 21 Jan 2024
The solution of equation (5) & (8) is obtainedby using MATLABProgram to solve difference equations
%%Program to plot the difference equation to verify
%Results with time domain equations
%Considering the systemof RL Circuit
% The expression is V=Ri+L(di/dt) clear all
close all clc
%System Parameters
V=220; % Maximum valueof the voltage (Volt)
R=10; % Resistance Value(Ohm)
L=0.051; % Inductor value(Henry)
dt=1e-3; % Time period (T)
t=0:dt:0.05; % Samples, k
y=[0]; % Output stack
fork=1:length(t)-1
y(k+1)=(1-R*dt/L)*y(k)+dt*(1/L)*V; end
figure(1)plot(t,y) grid on
xlabel ('Time (s)') ylabel('Current(Amp)')

Community Treasure Hunt

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

Start Hunting!