Showing posts with label z transform application. Show all posts
Showing posts with label z transform application. Show all posts

MATLAB program for Z-Transform of finite duration sequence

Program Code
%ztransform of finite duration sequence
clc;
close all;
clear all;
syms 'z';
disp('If you input a finite duration sequence x(n), we will give you its z-transform');
nf=input('Please input the initial value of n = ');
nl=input('Please input the final value of n = ');
x= input('Please input the sequence x(n)= ');
syms 'm';
syms 'y';
f(y,m)=(y*(z^(-m)));
disp('Z-transform of the input sequence is displayed below');
k=1;
for n=nf:1:nl
    answer(k)=(f((x(k)),n));
   k=k+1;
end
disp(sum(answer));



Example of Output
If you input a finite duration sequence x(n), we will give you its z-transform
Please input the initial value of n = 0
Please input the final value of n = 4
Please input the sequence x(n)= [1 0 3 -1 2]
Z-transform of the input sequence is displayed below

3/z^2 - 1/z^3 + 2/z^4 + 1


Explanation of the program code
clc;
It clears all input and output from the Command Window display giving clean screen. It removes items from workspace, freeing up system memory. After using clc, the scroll bar cannot be used to see the history of functions, but still the up arrow can be used to recall statements from the command history.

close all;
It deletes all figures whose handles are not hidden.

clear all;
It removes all variables from the workspace. This frees up system memory.

syms ‘z’;
This statement creates symbolic variable z. syms function is used to creates symbolic variable.

disp(‘If you input a finite duration sequence x(n), we will give you its Z-Transform.’);
This statement displays the sentence
If you input a finite duration sequence x(n), we will give you its Z-Transform.
disp() function displays its arguments.

nf=input(‘Please input the initial value of n ’);
This statement displays the sentence
Please input the initial value of n.
After displaying this sentence, it waits for the user to input the initial value of n using keyboard. The value entered by the user will be stored in nf.

nl=input(‘Please input the final value of n ’);
This statement displays the sentence
Please input the final value of n.
After displaying this sentence, it waits for the user to input the final value of n using keyboard. The value entered by the user will be stored in nl.

x=input(‘Please input the sequence x(n)= ’);
This statement displays the sentence
Please input the sequence x(n)=
After that it waits for the user to input all the elements of the sequence x(n) using keyboard.  The user should type the opening square bracket [  before entering the first element of x(n). After entering the [ the user should input all the elements of the sequence x(n) in the correct order. The user should press the spacebar key after typing each element of the sequence x(n), except the last element.  After typing the last element of the sequence x(n), the user should type the closing square bracket ]. All the elements of the sequence x(n) entered by the user will be stored in the array x, in the same order as they are entered by the user. The first element of x(n) will be stored as the first element of the array x, the second element of x(n) will be stored as the second element of the array x, and so on.

syms ‘m’;
This statement creates symbolic variable m.

syms ‘y’;
This statement creates symbolic variable y.

f(y,m)=(y*(z^(-m)));
This statement defines a function f. This function f defined here, can take two arguments. This function f outputs an expression of the form y*(z^(-m)) in terms of z, in which there is the numerical value of the first argument in the place of y and the numerical value of the second argument in the place of m. For example, if the function f takes 3 as the first argument and 4 as the second argument, we get the output as 3/z^4 . We know that z^(-4) is 1/z^4 . In this program, the same function f(y,m) defined in this statement, will be later used in a for loop, with x(k) as y and n as m to calculate the z-transform of each element of the input sequence x(n).

disp(‘Z-transform of the input sequence is displayed below’);
This statement displays the sentence
Z-transform of the input sequence is displayed below

k=1;
This statement assigns the value 1 to the variable k.

for n=nf:1:nl
answer (k)= (f((x(k)),n));
k=k+1;
end
This for loop calculates the z-transform of each element of the input sequence and stores each of those z-transforms as elements of the array answer. I am going to explain each statement in this for loop.

for n=nf:1:nl
The above mentioned for loop starts with this statement. The value of n will be same as the value of nf during the first iteration of this loop. The value of n is incremented by one for each successive iterations of the loop. The iterations of the loop continues till the value of n becomes equal to the value of nl. The final iteration of the loop takes place when the value of n becomes equal to the value of nl.
The syntax of for loop is
for variable=initial value:increment to/decrement from the initial value during each iteration:final value
statements in the loop
.
.
.
.
end

answer(k)=(f((x(k)),n));
The RHS of this statement calculates the z-transform of one element of the input sequence x using the function f(y,m) with y=k and m=n and stores the z-transform of each element of x(n) as the corresponding element of the array answer. During the first iteration of this for loop, k=1, x(k)=x(1) and n=nf. So during the first iteration of this loop, this statement calculates the z-transform of the first element of the input sequence and stores the result as the first element of the array answer. During the second iteration of this loop, this statement calculates the z-transform of the second element of the input sequence and stores the result as the second element of the array answer and so on till the value of n becomes equal to the value of nf.

k=k+1;
This statement increments the value of k by 1 during each iteration of the for loop.

end
This statement terminates this for loop.

disp(sum(answer));
The final line of output of this program is displayed on the execution of this statement. sum(answer); adds all the elements of the array answer to find their sum, and disp(sum(answer)); displays the sum thus obtained. In this program, the sum of all elements of the array answer is the z-transform of the input sequence.
___________________________

MATLAB program to plot zeros and poles of z-transform

Program Code
%Plotting zeros and poles of z-transform
clc;
close all;
clear all;
disp('For plotting poles and zeros');
b=input('Input the numerator polynomial coefficients');
a=input('Input the denominator polynomial coefficients');
[b,a]=eqtflength(b,a);
[z,p,k]=tf2zp(b,a);
zplane(z,p);
disp('zeros');
disp(z);
disp('poles');
disp(p);
disp('k');
disp(k);



Example of Output
For plotting poles and zeros
Input the numerator polynomial coefficients[1 2 3 4]
Input the denominator polynomial coefficients[1 2 3]
zeros
  -1.6506          
  -0.1747 + 1.5469i
  -0.1747 - 1.5469i

poles
        0          
  -1.0000 + 1.4142i
  -1.0000 - 1.4142i

k

     1



________________________________

For sale

For sale
Indian currency Ten-rupee note in good condition. Issued by the Reserve Bank of India between 22 December 1992 and 21 December 1997. Serial number 52T332603 . Those interested to buy, please contact: Anju K, Email: tc9749@gmail.com . Address: 'Sreyas', House no.7/296, Pulliodi, Kathiroor village, Ponniam east PO, via Ponniam west, Thalassery, Kannur, Kerala - 670641, India.