Digital Signal Processing Matlab Programs
Digital Signal Processing Matlab Programs
MATLAB
DIGITAL SIGNAL PROCESSING LAB
BY: CHHAVI TRIVEDI , ROLL NO : 07213502709, B.TECH(CSE), VI SEMESTER
IGIT
KASHMERE GATE
1/1/2012
Amplitude
1.4
1.2
1
0.8
0.6
0.4
0.2
0
3
n-->
Amplitude
4.4
4.2
4
3.8
3.6
3.4
3.2
3
3
n-->
Amplitude
1.4
1.2
1
0.8
0.6
0.4
0.2
0
-6
-5
-4
-3
n-->
-2
-1
Amplitude
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-1
-0.8
-0.6
-0.4
-0.2
0
n-->
0.2
0.4
0.6
0.8
Amplitude
2
1.5
1
0.5
0
1.5
2.5
n-h(n)
3.5
1.5
2.5
n-->
3.5
Amplitude
2
1.5
1
0.5
0
Amplitude
3
n-->
Amplitude
3
n-->
Amplitude
Amplitude
Amplitude
x(n)
4
2
0
1.5
2.5
n-->
y(n)
3.5
1.5
2.5
n-->
cross-correlation
3.5
4
n-->
4
2
0
40
20
0
1
0.8
0.6
Imaginary Part
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.5
0
Real Part
0.5
Q9. Compute the z-transform of anu(n) and plot its zeros and poles.
CODE:
syms a n;
>> g=a^n;
>> ztrans(g)
ans =
-z/(a - z)
a=input('Enter the value of a ');
Enter the value of a 2
>> num=[1 0];
>> den=[1 -a];
>> zplane(num,den)
>> [z p k]=tf2zp(num,den);
>> m=abs(p);
>> disp('zeros are at ');disp(z);
zeros are at
0
>> disp('poles are at ');disp(p);
poles are at
2
disp('Gain constant ');disp(k);
Gain constant
1
>> disp('Radius of poles ' );disp(m);
Radius of poles
2
FIGURE:
Imaginary Part
0.5
-0.5
-1
-1
-0.5
0.5
Real Part
1.5
Imaginary Part
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-1
-0.5
0
Real Part
0.5
Q11. Find and plot the dft of [1,2,3,4] and hence by the idft of the result obtained.
CODE(I):
x=input('enter the sequene ')
enter the sequene [1 2 3 4]
x=
1
-2.0000 - 2.0000i
FIGURE(I):
2
1.5
1
0.5
0
-0.5
-1
-1.5
-2
1.5
2.5
Real axis -->
3.5
CODE(II):
x=input('enter the sequene ')
enter the sequene [1 2 3 4]
x=
1
>> y=fft(x,4);
>> n=input('enter the length of idft ');
enter the length of idft 4
>> k=ifft(y,n)
k=
1 2 3 4
stem(k);xlabel('n --> ');ylabel('Amplitude --> ')
FIGURE(II):
4
3.5
Amplitude -->
3
2.5
2
1.5
1
0.5
0
1.5
2.5
n -->
3.5
4 12 26 42 61 89
>> stem(y)
FIGURE:
90
80
70
60
50
40
30
20
10
0
FIGURE:
-100
-200
-300
-400
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a) Normalised frequency -->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised frequency-->
0.8
0.9
4
Phase in radians -->
Gain in db -->
2
0
-2
-4
FIGURE:
0
-200
-400
-600
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(a) Normalised frequency -->
0.8
0.9
0.1
0.2
0.3
0.4
0.5
0.6
0.7
(b) Normalised frequency-->
0.8
0.9
4
Phase in radians -->
Gain in db -->
200
2
0
-2
-4
FIGURE:
10
0
-10
Gain in db -->
-20
-30
-40
-50
-60
-70
-80
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalised frequency -->
0.8
0.9
FIGURE:
20
Gain in db -->
-20
-40
-60
-80
-100
-120
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalised frequency -->
0.8
0.9
FIGURE:
20
0
Gain in db -->
-20
-40
-60
-80
-100
-120
-140
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalised frequency -->
0.8
0.9
FIGURE:
0
-5
-10
Gain in db -->
-15
-20
-25
-30
-35
-40
-45
0.1
0.2
0.3
0.4
0.5
0.6
0.7
Normalised frequency -->
0.8
0.9
Q19. Design an all pass filter and locate its poles and zeros.
CODE:
c=[1.5 0.7];
>> hd=dfilt.allpass(c)
hd =
FilterStructure: 'Minimum-Multiplier Allpass'
AllpassCoefficients: [1.5 0.7]
PersistentMemory: false
>> zplane(hd)
FIGURES:
Pole/Zero Plot
1
0.8
Imaginary Part
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
-2
-1.5
-1
-0.5
Real Part
0.5
1.5
Magnitude (dB)
0.2
0.1
0
-0.1
-0.2
-0.3
-0.4
-0.5
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
0.7
0.8
0.9
0.7
0.8
0.9
0.7
0.8
0.9
Phase Response
0
Phase (radians)
-1
-2
-3
-4
-5
-6
0
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
Group Delay
12
10
0
0
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
Phase Delay
2
1.8
1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
0.7
0.8
0.9
Impulse Response
0.7
0.6
0.5
Amplitude
0.4
0.3
0.2
0.1
0
-0.1
-0.2
-0.3
0
10
15
20
25
30
Samples
35
40
45
50
Q20. Design a minimum phase filter and locate its poles and zeros.
CODE:
Fs = 96000;
Fn = Fs/2;
f = [0 17000 20000 28000 31000 Fn]/Fn;
a = [0 0 1 1 0 0];
w = [5 1 5];
b = firgr(44, f, a, w, 'minphase');
legend(fvtool(b),'Min Phase')
FIGURES:
Pole/Zero Plot
1
0.8
0.6
Imaginary Part
0.4
0.2
44
0
-0.2
-0.4
-0.6
-0.8
-1
-1.5
-1
-0.5
0
Real Part
0.5
1.5
Group Delay
20
Min Phase
Group delay (in samples)
18
16
14
12
10
8
6
0
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
0.7
0.8
0.9
-5
Magnitude (dB)
-10
-15
-20
-25
-30
-35
-40
0
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
0.7
0.8
0.9
Impulse Response
0.2
0.15
0.05
0
-0.05
-0.1
-0.15
Min Phase
-0.2
0
10
15
20
Samples
25
30
35
40
Phase Response
6
Min Phase
Phase (radians)
Amplitude
0.1
-2
-4
-6
0
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
0.7
0.8
0.9
Phase Delay
21
20.5
20
Min Phase
19.5
19
18.5
18
17.5
17
16.5
0
0.1
0.2
0.3
0.4
0.5
0.6
Normalized Frequency ( rad/sample)
0.7
0.8
0.9