
Z-Transform With MatLab Code
BASIC
In signal processing, the Z-transform converts a discrete-time signal, which is a sequence of real or complex numbers, into a complex frequency-domain representation.
Z-transform of x(n) is given by,

MATLAB CODE
In z-transform we find a function always that includes z. You cannot ignore z. Moreover you cannot put a value of z. So you should take a variable z that can be calculated. Matlab offer such kind of variable. That is called symbolic variable. If you add two symbolic variable x and y the result will be x+y. not the sum of there value (It is the sum of them). Similarly you multiply symbolic x by 5 that will be 5x. Here we will declare a symbolic variable z.
sym 'z';
NB: Sym doesn’t work in default octave. It needs package. But MatLAB runs.
To find z-transform we need the sequence x(n). We will ask for it to the user.
x = input('Enter the sequence x(n): ');
We need the start value of transform sequence from where we will start z-transform. That is the start value of n. Take it as user input.
n1 = input('Enter the start value of n: ');
We need also the last value of z-transform sequence. That is the end value of n. As our sequence x(n) is limited so we will find from the length of x. Find it as below.
n2 = n1+length(x)-1;
The value of n can be negative or zero. But MatLAB cannot take negative or zero index. So we need an index variable m. Set it’s value to 1. As x has the initial value at index 1 by default.
m = 1;
As the result of z-transform will be sum of product term. So it cannot be null. Because it is needed to at with the previous value. Declare it to 0.
result = 0;
Now run a loop from n1 to n2. FInd the z-transform as the formula above. increase the index value m.
for i=n1:n2 result = result + x(m)*(z^(-i)); m = m + 1; endfor
Display the result.
disp(result);
FULL CODE
sym 'z'; x = input('Enter the sequence x(n): '); n1 = input('Enter the start value of n: '); n2 = n1+length(x)-1; m = 1; result = 0; for i=n1:n2 result = result + x(m)*(z^(-i)); m = m + 1; endfor disp(result);
I think your experience with this tutorial is quite good. If you have to seek anything please ask in comment.
Thanks.