ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.
E, TIRUPATI
PROGRAM 1:
A digital Filter has the depicted (in figure below) unit-sample response has
h[n]=[n]+2[n-1]+[n-2]
1.8
1.6
1.4
1.2
0.8
0.6
0.4
0.2
0
1 1.5 2 2.5 3 3.5 4 4.5 5
a) What is the difference equation that defines this filter input-output relationship?
b) What is filters transfer function?
c) What is filters output when input is sin (n/4)?
THEORY:
FILTER TRANSFER FUNCTION: H(Z)=Y(Z)/X(Z)
Y(Z) Is filter output response, X(Z) is filter input and H(Z) is filter transfer function.
MATLAB COMMANDS:
y=conv(x,h);
x=input sequence
h=impulse response
y=output sequence
MATLAB CODE:
clc; close all;clear all;
n=-2:1:2;
x=input('enter the input sequence');% taking input sequence from user
Electronics and communication engineering 1
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
h=input('enter the impluse squence');% taking impulse sequence from user(in this case [1 2 1])
subplot(3,3,1);
stem(x);
title('input squence');
xlabel('n...>');
ylabel('x[n]...>');
subplot(3,3,2);
stem(h);
title('impulse squence');
xlabel('n...>');
ylabel('h[n]...>');
%part(a)
y=conv(x,h);% convolution gives the i/p & o/p relationship.
subplot(3,3,3);
stem(y);
title('input-output relation');
xlabel('n...>');
ylabel('y[n]...>');
%part(b)
H=fft(h);% fft will gives Response of impulse function .
subplot(3,3,4);
stem(H);
disp(H)
title('filter TF');
xlabel('n...>');
ylabel('H(K)...>');
Electronics and communication engineering 2
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
q=zplane(h);% z plane function will give us pole-zero plot in z palne
%part(c)
z=sin((pi*n)/4);% i/p to the system
y1=conv(z,h);
subplot(3,3,5);
stem(z);
title('input to system');
xlabel('n...>');
ylabel('z[n]...>');
subplot(3,3,6);
stem(y1);
title('output of system');
xlabel('n...>');
ylabel('y1[n]...>');
INPUT & OUTPUT:
enter the input squence[1 2 3 4]
enter the impluse squence[1 2 1]
H(k)= 4.0000 + 0.0000i -0.5000 - 0.8660i -0.5000 + 0.8660i
Electronics and communication engineering 3
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOT:
RESULT:
The filters transfer function and its output for sinusoidal input, input-output relation is plotted
using MATLAB
Electronics and communication engineering 4
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 2:
Consider a FIR filter governed by the difference equation
Y(n)=1/3x(n+2)+2/3x(n+1)+x(n)+2/3x(n-1)+1/3x(n-2)
a) Find this filter unit sample response
b) Find their filters TF. Characterize this transfer function
THEORY:
Based on zero locations of pole-zero plot FIR filters are classified into four types as follows.,
(a) Type 1 FIR FILTER: Either an even number or no zeros at z=1 and z=-1. (b) Type 2 FIR
FILTER: Either an even number or no zeros at z=1 and an odd number of zeros at z=-1. (c)
Type 3 FIR FILTER: An odd number of zeros at z=1 and z=-1. (d) Type 4 FIR FILTER: An
odd number of zeros at z=1 and either an even number or no zeros at z=-1.
MATLAB COMMANDS:
IMPZ: Impulse response of digital filter
Syntax: [h,t] = impz(b,a)
Description:
[h,t] = impz(b,a) computes the impulse response of the filter with numerator coefficients b
and denominator coefficients a. impz chooses the number of samples and returns the
response in the column vector h and sample times in the column vector t (where t = [0:n-1]',
and n = length(t) is computed automatically).
ZPLANE: Zero-pole plot
Syntax: zplane(b,a)
Description: This function displays the poles and zeros of discrete-time systems.
Zplane (b,a) where b and a are row vectors, first uses roots to find the zeros and poles of the
transfer function represented by numerator coefficients b and denominator coefficients a. The
transfer function is defined in terms of z-1.
MATLAB CODE:
clc;close all;clear all;
num=input('enter the numerator squence');% in this case [1/3 2/3 3/3 2/3 1/3]
den=input('enter the denominator squence');%[1]
%part(a)
h=impz(num,den);% impz function will give impulse reponse
Electronics and communication engineering 5
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
H=ifft(h);% TF of filter
subplot(1,3,1);
stem(h);
disp(h)
title('filter impule reponse');
xlabel('n...>');
ylabel('h(n)...>');
%part(b)
subplot(1,3,2);
stem(H);
disp(H)
title('filter TF');
xlabel('k...>');
ylabel('H(K)...>');
subplot(1,3,3);
z=zplane(h);
INPUT & OUTPUT:
enter the numerator squence[1/3 2/3 3/3 2/3 1/3]
enter the denominator squence[1]
h[n]=
0.3333
0.6667
1.0000
0.6667
0.3333
H(k)=
0.6000 + 0.0000i
-0.1412 + 0.1026i
0.0079 - 0.0242i
0.0079 + 0.0242i
-0.1412 - 0.1026i
Electronics and communication engineering 6
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOT:
RESULT:
The filter unit sample response and its transfer function is plotted using MATLAB and its
observed that filter category is TYPE-4
Electronics and communication engineering 7
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 3:
A filter has an input-output relationship given by the difference equation
y(n)=1/4x(n)+1/2x(n-1)+1/4x(n-2)
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
0 2 4 6 8 10 12 14 16 18
a) What is filters TF? How would you characterize it?
b) What is filter`s output when the input equals cos (n/4)?
c) What is the filters output when the input is the depicted discrete-time square wave?
MATLAB CODE:
clc;close all;clear all;
num=input('enter the numerator squence');% in this case [1/4 2/4 1/4]
den=input('enter the denominator squence');%[1]
%part(a)
h=impz(num,den);% impz function will give impulse response of filter
subplot(3,3,1);
stem(h);
disp(h)
title('impulse response of filter');
xlabel('n...>');
ylabel('h(n)...>');
H=fft(h);% TF of filter
subplot(3,3,2);
stem(H);
disp(H)
title('filter TF');
xlabel('k...>');
ylabel('H(k)...>');
subplot(3,3,3);
zplane(h);
%part(b)
Electronics and communication engineering 8
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
n=-2:0.5:2;
z1=cos((pi*n)/2);% i/p to the system
y1=conv(z1,h); % o/p of system
subplot(3,3,4);
stem(z1);
title('input to system');
xlabel('n...>');
ylabel('z1[n]...>');
subplot(3,3,5);
stem(y1);
title('output of system');
xlabel('n...>');
ylabel('y1[n]...>');
%part(c)
z2=square(n,50); % i/p to the system
y2=conv(z2,h);% o/p of system
subplot(3,3,6);
stem(z2);
title('input to system');
xlabel('n...>');
ylabel('z2[n]...>');
subplot(3,3,7);
stem(y2);
title('output of system');
xlabel('n...>');
ylabel('y2[n]...>');
INPUT&OUTPUT:
enter the numerator squence[1/4 2/4 1/4]
enter the denominator squence[1]
h(n)=
0.2500
0.5000
0.2500
H(k)=
1.0000 + 0.0000i
-0.1250 - 0.2165i
-0.1250 + 0.2165i
Electronics and communication engineering 9
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOT:
RESULT:
The filters transfer function and its output for sinusoidal input, discrete time square wave is
plotted using MATLAB and its observed that filter category is TYPE-1.
Electronics and communication engineering 10
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 4:
Using MATLAB compute and plot the magnitude response and phase response of a second order
band pass and band stop IIR digital filters for values of say 0.2 ,0.5 ,0.8 with = 0.34 is said
to be constant. Repeat the same by interchanging the values of and
THEORY:
For BANDPASS IIR digital filter:
H BP (Z) = [ ( ( 1 ) / 2 ) * ( 1 Z -2 ) ] / [ 1 ( 1 + ) Z-1 + Z-2 ]
For BANDSTOP IIR digital filter :
H BS (Z) = [ ( ( 1 - ) / 2 ) * ( 1 - 2 Z-1 + Z-2 ] / [ 1 - ( 1 - ) Z-1 + Z-2 ]
MATLAB CODE:
clc;close all;clear all;
%part(a)
beta=input('enter the beta value');
alpha=input('enter the alpha value');
Wo=((acos(beta))/pi)
Bw=(acos((2*alpha)/(1+(alpha^2)))/pi)
Q=Wo/Bw
[b,a]=iirpeak(Wo,Bw)% iirpeak function will give TF of second order BPF(band pass filter) in
Z-Domain
fvtool(b,a);
%part(b)
[y,z]=iirnotch(Wo,Bw)% iirpeak function will give TF of second order BSF(band stop filter) in
Z-Domain
fvtool(y,z);
Electronics and communication engineering 11
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
INPUT & OUTPUT:
enter the beta value0.34 enter the beta value0.34 enter the beta value0.34
enter the alpha value0.2 enter the alpha value0.5 enter the alpha value0.8
Wo = 0.3896 Wo =0.3896 Wo =0.3896
Bw = 0.3743 Bw =0.2048 Bw =0.0704
Q =1.0407 Q =1.9019 Q =5.5300
b = 0.4000 0 -0.4000 b =0.2500 0 -0.2500 b =0.1000 0 -0.1000
a =1.0000 -0.4080 0.2000 a =1.0000 -0.5100 0.5000 a =1.0000 -0.6120 0.8000
y =0.6000 -0.4080 0.6000 y =0.7500 -0.5100 0.7500 y =0.9000 -0.6120 0.9000
z =1.0000 -0.4080 0.2000 z =1.0000 -0.5100 0.5000 z =1.0000 -0.6120 0.8000
enter the beta value0.2 enter the beta value0.5 enter the beta value0.8
enter the alpha value0.34 enter the alpha value0.34 enter the alpha value0.34
Wo =0.4359 Wo =0.3333 Wo =0.2048
Bw =0.2914 Bw =0.2914 Bw =0.2914
Q =1.4961 Q =1.1441 Q =0.7030
b =0.3300 0 -0.3300 b =0.3300 0 -0.3300 b =0.3300 0 -0.3300
a =1.0000 -0.2680 0.3400 a =1.0000 -0.6700 0.3400 a =1.0000 -1.0720 0.3400
y =0.6700 -0.2680 0.6700 y =0.6700 -0.6700 0.6700 y =0.6700 -1.0720 0.6700
z =1.0000 -0.2680 0.3400 z =1.0000 -0.6700 0.3400 z =1.0000 -1.0720 0.3400
Electronics and communication engineering 12
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOTS:
band pass filter: alpha value0.2,0.5,0.8
beta 0.34
Electronics and communication engineering 13
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
band pass filter: beta 0.2,0.5,0.8
alpha value 0.34
Electronics and communication engineering 14
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
band pass filter: alpha value0.2,0.5,0.8
beta 0.34
Electronics and communication engineering 15
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
band pass filter: beta 0.2,0.5,0.8
alpha value 0.34
Electronics and communication engineering 16
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
RESULT:
The magnitude and phase response of a second order band pass and band stop filters are
computed and plotted using MATLAB
Electronics and communication engineering 17
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 5:
a) Using MATLAB compute and plot the magnitude response of a comb filter obtained from a
prototype FIR high pass filter of Hhp(Z)= (1) with M=2 and for different values
of L. Determine the location of the notches and peaks of the magnitude response of this type of
comb filter. Assume L=3, L=4.
b) Using MATLAB compute and plot the magnitude response of a comb filter obtained from a
prototype FIR LPF Hlp(Z)= (1 + ) for diff. values of L Show that the new filter has multiple
notches at w= wk= (2k+1). And has L peaks in its magnitude responses w= wk =
,k=0,1,....,L-1
THEORY:
Comb filter for a prototype FIR highpass filter is
H hp (Z)= (1)
( )
The filter has L notches located at and has L peaks located at 0kL-1
Comb filter for a prototype FIR lowpass filter is HlP (Z) = (1 + Z )
( )
The filter has L peaks located at and has L peaks located at 0kL-1
MATLAB CODE:
clc; clear all; close all;
L=input('enter the L +ve integer value');
%part(a)
M=2;
k=0:1:L-1;
w=0:0.01:2*pi;
wn=w/pi;
z=exp((1j*w));
HcombHPF=(1/M)*(1-z.^((-1)*L));
subplot(2,1,1);
plot(wn,abs(HcombHPF));
title('Comb filter of HP prototype');
xlabel('w/pi...>');
Electronics and communication engineering 18
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
ylabel('magnitude...>');
p=((2*(k+1)*pi))/L;
n=(2*k*pi)/L;
peaksHPF=(p/pi)
notchesHPF=(n/pi)
%part(b)
k=0:1:L-1;
w=0:0.1:2*pi;
wn=w/pi;
z=exp((1j*w));
HcombLPF=0.5*(1+z.^((-1)*L));
subplot(2,1,2);
plot(wn,abs(HcombLPF));
title('Comb filter of LP prototype');
xlabel('w/pi...>');
ylabel('magnitude...>');
p=(2*k*pi)/L;
n=((2*(k+1)*pi))/L;
peaksLPF=(p/pi)
notchesLPF=(n/pi)
INPUT &OUTPUT:
enter the L +ve integer value3 enter the L +ve integer value4
peaksHPF = 0.6667 1.3333 2.0000 peaksHPF =0.5000 1.0000 1.5000 2.0000
notchesHPF = 0 0.6667 1.3333 notchesHPF = 0 0.5000 1.0000 1.5000
peaksLPF =0 0.6667 1.3333 peaksLPF = 0 0.5000 1.0000 1.5000
notchesLPF = 0.6667 1.3333 2.0000 notchesLPF =0.5000 1.0000 1.5000 2.0000
Electronics and communication engineering 19
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOT:
M=2, L=3
M=2, L=4
Electronics and communication engineering 20
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
RESULT:
The magnitude and phase response of a comb filter was computed and plotted and the notches
and the peaks of the magnitude response of the comb filter was determined using MATLAB.
Electronics and communication engineering 21
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 6:
Consider the comb filter
1
( )=
1
a) Sketch the magnitude response and pole zero diagram of this filter for |a|<1 and D=3
take |a| =0.2, |a| =0.5, |a| =0.7.
b) Comment on the following conditions for this filter: All pass, minimum phase and linear
phase which hold and dont hold why?
MATLAB CODE:
clc
clear all
d=3;
a=0.2;
w=0:pi/128:2*pi;
z=exp(j*w);
nr=(1-a*(power(z,-d)));
dr=(1-(power(a,4)*(power(z,-4*d))));
for i=1:257
h(i)=nr(i)/dr(i);
end
subplot(3,2,1);
plot(w/pi,abs(h));
subplot(3,2,2);
zplane(h);
a=0.5;
w=0:pi/128:2*pi;
z=exp(j*w);
nr=(1-a*(power(z,-d)));
dr=(1-(power(a,4)*(power(z,-4*d))));
for i=1:257
h(i)=nr(i)/dr(i);
end
subplot(3,2,3)
plot(w/pi,abs(h));
subplot(3,2,4);
zplane(h);
a=0.7;
w=0:pi/128:2*pi;
z=exp(j*w);
nr=(1-a*(power(z,-d)));
Electronics and communication engineering 22
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
dr=(1-(power(a,4)*(power(z,-4*d))));
for i=1:257
h(i)=nr(i)/dr(i);
end
subplot(3,2,5);
plot(w/pi,abs(h))
subplot(3,2,6)
zplane(h)
PLOT:
1.5
Imaginary Part
1
256
1 0
0.5 -1
0 0.5 1 1.5 2 -2 -1 0 1 2
Real Part
2
Imaginary Part
1
256
1 0
0 -1
0 0.5 1 1.5 2 -2 -1 0 1 2
Real Part
4
Imaginary Part
256
2 0
0 -1
0 0.5 1 1.5 2 -2 -1 0 1 2
Real Part
RESULT:
The magnitude and pole zero diagram of a given comb filter was computed and
plotted using MATLAB.
Electronics and communication engineering 23
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 7:
Consider the comb filter
1
( )=
1
a) Sketch the magnitude response and pole zero diagram of this filter for |a|<1 and D=4
take |a| =0.2, |a| =0.5, |a| =0.7.
b) Comment on the following conditions for this filter: All pass, minimum phase and linear
phase which hold and dont hold why?
MATLAB CODE:
clc
clear all
d=4;
a=0.2;
w=0:pi/128:2*pi;
z=exp(j*w);
nr=(1-(power(a,3))*(power(z,-3*d)));
dr=(1-a*(power(z,-d)));
for i=1:257
h(i)=nr(i)/dr(i);
end
subplot(3,2,1);
plot(w/pi,abs(h));
subplot(3,2,2);
zplane(h);
a=0.5;
w=0:pi/128:2*pi;
z=exp(j*w);
nr=(1-(power(a,3))*(power(z,-3*d)));
dr=(1-a*(power(z,-d)));
for i=1:257
h(i)=nr(i)/dr(i);
end
subplot(3,2,3)
plot(w/pi,abs(h));
subplot(3,2,4);
zplane(h);
a=0.7;
w=0:pi/128:2*pi;
z=exp(j*w);
nr=(1-(power(a,3))*(power(z,-3*d)));
dr=(1-a*(power(z,-d)));
Electronics and communication engineering 24
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
for i=1:257
h(i)=nr(i)/dr(i);
end
subplot(3,2,5);
plot(w/pi,abs(h))
subplot(3,2,6)
zplane(h)
PLOTS:
RESULT:
The magnitude and pole zero diagram of a given comb filter was computed and plotted using
MATLAB.
Electronics and communication engineering 25
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 8:
Using matlab, determine if given TF is double complimentary or not
!" !"
H(Z)= and G(Z)= also test if given TFs are
#!" #!"
a) Delay complimentary and
b) Power complimentary or not
THEORY:
Delay complementary: A set of M transfer functions {Hi (Z)}, 0iM-1, is defined to be
Delay complementary of each other if the sum of their transfer functions is equal to some
integer multiple of the unit delay.
All pass complementary: A set of M transfer functions {Hi (Z)}, 0iM-1, is defined to be
All pass complementary of each other if the sum of their transfer functions is equal to an All
pass function A(Z).
Power complementary: A set of M stable digital transfer functions {Hi (Z)}, 0iM-1, is
defined to be Power complementary of each other if the sum of the squares of their
magnitude responses is equal to a constant K.
Doubly complementary: A set of M stable digital transfer functions satisfying both the All
pass complementary property and the Power complementary property is known as Doubly
complementary.
Power symmetry: A real coefficient causal digital filter with a transfer function H(Z) is said
to be a power symmetry filter if it satisfies the condition H(Z)H(Z-1)+H(-Z)H(-Z-1)=K,
where K>0 is a constant.
MATLAB CODE:
clc;
clear all;
num=[2 2];
den=[3 1];
h=num./den;
a=impz(num,den);
num1=[1 -1];
den1=[3 1];
g=num1./den1;
b=impz(num1,den1);
Electronics and communication engineering 26
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
% verification of ALL-PASSS and DELAY COMPLEMENTARY
c=(abs(a)+abs(b));
disp('c =');
disp(sum(c));
% verification of POWER COMPLEMENTARY
n=((abs(a).*abs(a))+(abs(b).*abs(b)));
disp('n =');
disp(sum(n));
OUTPUT:
c =2.3331
n =1.0000
RESULT:
Doubly Complementary, Delay complementary and Power complementary functions for a given
transfer functions are verified using MATLAB.
Electronics and communication engineering 27
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 9:
Using MATLAB determine if or not all the roots of following polynomial are inside the unit
circle if
)
D (Z) =1 + 2.5 + 2.5 + 1.25 + 0.3125 + 0.03125
Test the stability of the all-pass filter A(Z) based on the stability test parameters also
THEORY:
Stability Test: The BIBO stability of a causal rational transfer function requires that all its poles
be inside the unit circle. For very high order transfer functions, it is difficult to determine the
pole locations analytically, and the use of some type of roots finding computer program is
necessary. We outline here a simple algebraic stability test procedure that does not require the
determination of the pole locations. The algorithm is based on the realization of an all pass
transfer function with a denominator that is the same as that of the transfer function of interest.
MATLAB CODE:
clc;
clear all;
dr=[1 2.5 2.5 1.25 0.3125 0.03125];
k=poly2rc(dr);%finding stability test parameters
knew=fliplr(k');%to display parameters in correct order
disp('stability parameters are:');
disp(knew);
stable=all(abs(k)<1)
if(stable==1)
disp('filter is stable');
else disp('filter unstable');
end
OUTPUT:
stability parameters are:
0.0313 0.2346 0.6225 0.8726 0.9630
stable =1
filter is stable
RESULT:
The stability of the all-pass filter based on stability test parameters is predicted successfully
using MATLAB
Electronics and communication engineering 28
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 10:
State Space Representation: The system transfer function for a discrete time digital system is
given by
.*++, ., ,, !" . , !- ., ,, !. .*++, !/
H (Z) =
. .0+,+ !" .,0 * !- .* 0 !. .0 !/
Develop a state space representation for the system using the form Q[n]=AQ[n-1]+B x[n] and
y[n]= CQ[n-1]+D x[n]. Clearly identify the A,B,C,D matrices for your implementation.
MATLAB CODE:
clc; clear all; close all;
a=input('enter the numerator squence');% in this case [0.7996 -1.6066 2.4061 -1.6066 0.7996]
b=input('enter the denominator squence');%[0.8124 -1.7084 2.6817 -1.8969 1]
[A B C D]=tf2ss(a,b)
INPUT & OUTPUT:
enter the numerator squence[0.7996 -1.6066 2.4061 -1.6066 0.7996]
enter the denominator squence[0.8124 -1.7084 2.6817 -1.8969 1]
A=
2.1029 -3.3010 2.3349 -1.2309
1.0000 0 0 0
0 1.0000 0 0
0 0 1.0000 0
B=
1
0
0
0
C = 0.0922 -0.2872 0.3205 -0.2273
D = 0.9842
RESULT:
State Space Representation of the system transfer function for a discrete time digital system
using MATLAB
Electronics and communication engineering 29
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 11:
Cascade realization of both IIR and FIR transfer functions
MATLAB CODE:
%Cascade Realization
clc;
clear all;
n=input('enter nr');
d=input('enter dr');
[b,a]=eqtflength(n,d); %make lengths equal
[z,p,k]=tf2zp(b,a); %transfer filter parameters to zero-pole gain form
sos=zp2sos(z,p,k) %zero-pole gain filter parameters to second order sections
For FIR TF:
INPUT
enter nr[2 10 23 34 31 16 4]
enter dr[1]
OUTPUT
sos =
2.0000 6.0000 4.0000 1.0000 0 0
1.0000 1.0000 2.0000 1.0000 0 0
1.0000 1.0000 0.5000 1.0000 0 0
For IIR TF:
INPUT
enter nr[3 8 12 7 2 -2]
enter dr[16 24 24 14 5 5]
OUTPUT
sos =
0.1875 -0.0625 0 1.0000 0.9290 0
1.0000 2.0000 2.0000 1.0000 -0.3662 0.3491
1.0000 1.0000 1.0000 1.0000 0.9372 0.9636
RESULT:
By using MATLAB,cascade realization of both IIR and FIR transfer functions are obtained
Electronics and communication engineering 30
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 12:
Parallel realization of given transfer function
MATLAB CODE:
%parallel Realization
clc;
clear all;
nr=input('enter nr');
dr=input('enter dr');
[r,p,k]=residuez(nr,dr)
disp('parallel form 1');
[r1,p1,k1]=residuez(nr,dr)
Disp(parallel form 2);
[r2,p2,k2]=residue(nr,dr)
INPUT
enter nr[2 10 23 34 31 16 4]
enter dr[36 78 87 59 26 7 1]
OUTPUT
parallel form 1
r=
-0.5556 - 2.2785i
-0.5556 + 2.2785i
-0.5952 - 0.7561i
-0.5952 + 0.7561i
-0.8214 + 4.3920i
-0.8214 - 4.3920i
p=
-0.3333 + 0.4714i
-0.3333 - 0.4714i
-0.5000 + 0.2887i
-0.5000 - 0.2887i
-0.2500 + 0.4330i
-0.2500 - 0.4330i
k =4
Electronics and communication engineering 31
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
parallel form 2
r1 =
1.2593 + 0.4976i
1.2593 - 0.4976i
0.5159 + 0.2062i
0.5159 - 0.2062i
-1.6964 - 1.4537i
-1.6964 + 1.4537i
p1 =
-0.3333 + 0.4714i
-0.3333 - 0.4714i
-0.5000 + 0.2887i
-0.5000 - 0.2887i
-0.2500 + 0.4330i
-0.2500 - 0.4330i
k1 =
0.0556
RESULT:
The parallel form realizations (I & II) for a given transfer function is realized using MATLAB
Electronics and communication engineering 32
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 13:
Gray-Markel realization of a casual IIR transfer function
MATLAB CODE:
%Gray Markel Cascade
clc;
clear all;
n=input('enter nr');
d=input('enter dr');
n=n/d(1);
d=d/d(1);
[k,alpha]=tf2latc(n,d)
disp('check of lattice/ladder inversion');
[n,d]=latc2tf(k,alpha)
INPUT
enter nr[.22 1.1 2.2 2.2 1.1 .22]
enter dr[1 -.9853 .9738 -.3864 .1112 -.1113]
OUTPUT
k = -0.4545
0.7219
-0.2800
0.0016
-0.1113
alpha =-1.1515
1.7038
4.2767
3.2829
1.3168
0.2200
check of lattice/ladder inversion
n = 0.2200 1.1000 2.2000 2.2000 1.1000 0.2200
d = 1.0000 -0.9853 0.9738 -0.3864 0.1112 -0.1113
RESULT:
Gray markel realization for given causual IIR TF is realized
Electronics and communication engineering 33
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 14:
Realizing All-pass transfer function in its cascade lattice structure using poly2rc
MATLAB CODE:
%Cascade Lattice Realization
clc;
clear all;
n=input('enter numerator coefficients');
d=[1];
k=poly2rc(n,d); %converts prediction filter coefficients to reflection coefficients
knew=fliplr(k'); %to display lattice parameters in correct order
disp(knew);
INPUT
enter nr[1 .9853 .9738 -.3864 .1112 -.1113]
OUTPUT
-0.1113 0.2236 -0.5341 1.9219 0.7379
RESULT: Given All-pass transfer function in its cascade lattice structure using poly2rc is
realized by MATLAB
Electronics and communication engineering 34
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 15:
(a) Realize the following IIR transfer function G(z) in the form of parallel allpass atructure
G(Z)= 0.1327(1-Z-2)2 / (1+0.2377 Z-1+0.8152 Z-2+0.1294Z-3+0.3618 Z-4)
(b) From the allpass decomposition ,determine its power-complimentary transfer function
H(Z)
(c) Plot the square of the magnitude response of the original transfer function G(Z) and its
power-complimentary transfer function H(Z) derived in part(b) ,and verify that thir sum
is equal to one at all frequencies
MATLAB CODE:
clc;
clear all;
n1=input('enter numerator coefficients');
d1=input('enter denominator coefficients');
[h,w]=freqz(n1,d1);
[n2,d2]=iirpowcomp(n1,d1);% power complimentary transfer function of G(Z)
[g,w]=freqz(n2,d2);
hold all;
plot(w/pi,abs(h.^2),'r');
plot(w/pi,abs(g.^2),'g');
plot(w/pi,(abs(h.^2)+abs(g.^2)),'y');
INPUT
enter numerator coefficients [.1327 0 -.2654 0 0.1327]
enter denominator coefficients[1 0.2377 0.8152 0.1294 0.3618]
Electronics and communication engineering 35
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOT:
1.4
1.2
0.8
magnitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
w/pi
RESULT:
The power complimentary TF for given IIR band pass filter is obtained and square of the
magnitude response of the original transfer function G(Z) and its power-complimentary transfer
function H(Z) is plotted ,and verify that their sum is equal to one at all frequencies.
Electronics and communication engineering 36
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 16:
Using matlab simulate a one-multiplier structure of sine-cosine generator of the equation
S1(n+1) = 0 -cos()/ sin() s1(n+1) + 0 -/ sin() s1(n)
S2(n+2) 0 0 s2(n+1) -/ sin() cos() s2(n)
Then choosing and properly with =0.9 and plot for first 50 samples of its two output
sequences.Scale the output so that both have maximum amplitude of 1. What is effect of initial
conditions of variables Si[n]?
MATLAB CODE:
%Sine Cosine generator
clc;
clear all;
s1=.1,s2=1,a=.9;
y1=zeros(1,50);
y2=y1;
for n=1:50
y1(n)=-s2+a*s1;
y2(n)=-a*y1(n)+s1;
s1=y1(n),s2=y2(n);
end
k=1:1:50
stem(k-1,y1/y1(11));axis([0 50 -1.1 1.1]);
xlabel('n');ylabel('amplitude');
pause
stem(k-1,y2/y2(14));axis([0 50 -1.1 1.1]);
xlabel('n');ylabel('amplitude');
Electronics and communication engineering 37
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOT
0.8
0.6
0.4
0.2
amplitude
-0.2
-0.4
-0.6
-0.8
-1
0 5 10 15 20 25 30 35 40 45 50
n
RESULT:
The sine cosine generator is simulated with one multiliper structure for given specifications of
maximum amplitude 1 , and =0.9 using MATLAB
It is observed that output is zero for zero initial conditions ,non zero initial conditions of equal
values appear to have no effects on the output,however unequal initial conditions have effects on
the amplitudes and phase of two output sequences
Electronics and communication engineering 38
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 17:
Computing prime DFT,cooley-tukey frequency domain FFT
MATLAB CODE:
%FFT or IFFT
x=input('enter the sequence');
swtch=input('enter 0 for fft or 1 for ifft:');
X=edufft(x,swtch);%calling edufft function
disp(X);
% defining functions
function X=ctrecur(x,W);
N=length(x);
Q=N;
for i=2:floor(sqrt(N))
if(rem(N,i)==0)
Q=i;
break
end
end
if(Q==N)
X=primedft(x,W);%calling primedft function
else
P=N/Q
tmp=reshape(x,P,Q);
for p=0:P-1
tmp(p+1,:)=primedft(tmp(p+1,:),W(1:P:N));
if(p>0)
tmp(p+1,2:Q)=tmp(p+1,2:Q).*W(rem(p*(1:Q-1),N)+1)
end
end
for q=1:Q
tmp(:,q)=(ctrecur(tmp(:,q).',W(1:Q:N))).';
end
X=reshape(tmp.',1,N);
end
function X=edufft(x,swtch)
N=length(x);
x=reshape(x,1,N);
if(swtch)
W=exp((j*2*pi/N)*(0:N-1));
else
W=exp((-j*2*pi/N)*(0:N-1));
end
X=ctrecur(x,W);%calling ctrecur function
Electronics and communication engineering 39
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
if(swtch)
X=(1/N)*X;
end
function y=primedft(x,W)
disp(x);
N=length(x);
n=1:N-1;
y=zeros(1,N);
y(1)=sum(x);
for k=1:N-1
y(k+1)=x(1)+sum(x(2:N).*W(rem(k*n,N)+1));
end
INPUT
enter the sequence[1 2 3 4 5]
enter 0 for fft or 1 for ifft:0
OUTPUT
15.0000 -2.5000 + 3.4410i -2.5000 + 0.8123i -2.5000 - 0.8123i -2.5000 - 3.4410i
INPUT
enter the sequence[1 6 7 8 3 8 9]
enter 0 for fft or 1 for ifft:1
OUTPUT
6.0000 -0.4137 - 0.1644i -1.2849 - 0.9143i -0.8014 + 0.6221i -0.8014 - 0.6221i -1.2849
+ 0.9143i -0.4137 + 0.1644i
RESULT:
The prime DFT,cooley-tukey frequency domain FFT are computed using MATLAB
Electronics and communication engineering 40
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 18:
Finding sliding DFT for a given input sequence
MATLAB CODE:
%Sliding DFT
clc;
x=[1,1,1,1,1,1,1,1];
N=length(x);X=fft(x,N);
m=2;n=[0:N-1];n=mod(n-m,N);
y=x(n+1)
Y=fft(y)
k=[0:N-1];
X.*exp(-j*2*pi*m*k/N);
z=[2,3,4,5,6];
Z=fft(z);
k=[0:N-1];(X(k+1)-x(1)+z(end)).*exp(j*2*pi*k/N)
k=4;(X(k+1)-x(1)+z(end)).*exp(j*2*pi*k/N);
OUTPUT
y=1 1 1 1 1 1 1 1
Y =8 0 0 0 0 0 0 0
ans =
Columns 1 through 7
13.0000 3.5355 + 3.5355i 0.0000 + 5.0000i -3.5355 + 3.5355i -5.0000 + 0.0000i -3.5355 -
3.5355i -0.0000 - 5.0000i
Column 8
3.5355 - 3.5355i
RESULT:
sliding DFT for a given input sequence is computed using MATLAB
Electronics and communication engineering 41
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 19:
Finding quantization error for a signal
MATLAB CODE:
%Quantisation Error
clc;
clear all;
L=10000;
x=2*rand(L,1)-1;
Rfs=2;
b=8;
Q=Rfs/2.^b;
y=Q*round(x/Q);
e=x-y;
figure;
subplot(2,1,1);
stem(e(1:100),'.');
title('quantisation error signal');
subplot(2,1,2);
hist(e,10);
colormap([1 1 1]*1);
title('quantisation error histogram');
axis([-Q Q 0 2*L/10]);
Electronics and communication engineering 42
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PLOT
-3 quantisation error signal
x 10
4
-2
-4
0 10 20 30 40 50 60 70 80 90 100
quantisation error histogram
2000
1500
1000
500
0
-6 -4 -2 0 2 4 6
-3
x 10
RESULT:
The quantization error of given signal was computed and plotted using MATLAB.
Electronics and communication engineering 43
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 20:
Finding Chirp Z-transform for given input sequence
MATLAB CODE:
%chirp Transform
clc;
clear all;
x=input('enter x');
X=chirpf(x,64,8,32);
function X=chirpf(x,theta,dtheta,k);
N=length(x);
x=reshape(x,1,N);n=0:N-1;
g=x.*exp(-j*(.5*dtheta*n+theta).*n);
L=1;
while(L<N+k-1)
L=2*L;
end
g=[g,zeros(1,L-N)];
h=[exp(j*.5*dtheta*(0:k-1).^2),....
exp(j*.5*dtheta*(-L+k:-1).^2)];
X=ifft(fft(g).*fft(h));
X=x(1:k).*exp(-j*.5*dtheta*(0:k-1).^2);
RESULT:
The Chirp Z-transform for given input sequence was computed using MATLAB.
Electronics and communication engineering 44
ADSP LAB REPORT 1st year I sem- M.Tech , S.V.U.C.E, TIRUPATI
PROGRAM 21:
From given Taylor coefficients find
MATLAB CODE:
%Taylors
clc;
clear all;
a=input('enter taylors coe');
N=length(a);
A=zeros(N-1,N-1);
m=3;n=N-1-m;
for i=1:m
A(i:(N-1),i)=a(1:N-i);
end
A(1:n,m+(1:n))=-eye(n)
b=-a(2:N);
c=A/b;
Q=[1;c(1:m)];
P=[a(1);c((m+1):(m+n))];
INPUT
enter taylors coe[1 2 3 4]
OUTPUT
A=
1 0 0
2 1 0
3 2 1
RESULT:
The Taylor coefficients of a given sequence were computed using MATLAB.
Electronics and communication engineering 45