DSP Lab 3
DSP Lab 3
>> syms n z;
>> x(z)=z/(z-0.5);
>> x(n)=iztrans(x(z))
x(n)=(1/2)^n
Plot Pole-zero diagram in Z-Domain
%Finding the residues, poles and direct
terms of the partial-fraction expansion
b=[2 1 -2];
a=[1 1 -2];
[r,p,k]=residuez(b,a);
z=roots(b);
p=roots(a);
zplane(b,a)
grid on
title('Plot pole-zero diagram on z-plane')
More on Pole-zero diagram in z-domain
%Pole-zero diagram in z-plane
%Given D.E y(n)-3/4y(n-1)+1/8y(n-2)=x(n)-x(n-1)
%Taking z-transform on both sides and
find the impulse response H(z)=Y(z)/X(z)
%H(z)=(1-z^-1)/(1-3/4z^-1+1/8z^-2)
b=[1 -1];%numerator
a=[1 -3/4 1/8];%denumerator
zplane(b,a)%compute and display the
pole-zero diagram
z=roots(b); %to display the zero values
p=roots(a); %to display the pole values
Finding DFT of a given sequence
%Computation of N-ponit DFT of a given sequence
%Plotting the magnitude and phase spectrum
N=input('Enter the N values of N-point DFT N=
');
X=input('Enter the sequence to be calculated X= ');
n=[0:1:N-1]; k=[0:1:N-1]; WN=exp(-1j*2*pi/N);
nk=k'*n; WNnk=WN.^nk; Xk=X*WNnk;
magX=abs(Xk);%Magnitude of the calculated DFT
phaseX=angle(Xk)*180/pi;%Phase of calculated DFT
subplot(2,1,1); plot(k,magX);
title('Plotting Magnitude of calculated DFT');
subplot(2,1,2); plot(k,phaseX,'r');
title('Phase spectrum of the calculated DFT');
disp('The calculated DFT is =');Xk;
Finding IDFT of a given sequence
>> DFT
Enter the N values of N-point DFT N= 4
Enter the sequence to be calculated X=
[1 2 3 4]
The calculated DFT is =Xk
>> disp(Xk)
10.0000 + 0.0000i -2.0000 + 2.0000i
-2.0000 - 0.0000i -2.0000 - 2.0000i
>>a=ifft(Xk);
>> disp(a)
1.0000 - 0.0000i 2.0000 - 0.0000i
3.0000 + 0.0000i 4.0000 + 0.0000i
Implementation of FFT of DT signals
% Computation of FFT for defined
sequence
x=[0 1 2 3 4 5 6 7]; %Given sequence
n=0:7; %Length of given sequence
a=fft(x); %FFT of x
disp(a)
>> x=[1 0 1 0 1 0 1 0];
>> n=0:7;
>> b=fft(x);
>> disp(b)
4 0 0 0 4 0 0 0
>> c=ifft(b);
>> disp(c)
1 0 1 0 1 0 1 0
More on FFT Analysis
%Computation of Fast Fourier Transform
clc; clear all; close all;
x=input('ENTER THE SEQUENCE X= ');
n=input('ENTER THE LENGTH OF THE SEQUENCE N= ');
disp('Fourier Transformed signal is X');
X=fft(x,n);
subplot(2,1,1);
stem(x); xlabel('n...>');ylabel('x(n)...>');
title('INPUT SIGNAL');
subplot(2,1,2);
stem(X,'r'); xlabel('Real axis....>');
ylabel('Imaginary axis...>>');
title('FFT of x');
grid on
TH E
O F
END E
I D
SL U!
YO
N K
H A
T