DSP manual-KIOT
DSP manual-KIOT
DSP manual-KIOT
Aim:
Software Required:
Matlab 7.1
Algorithm:
Program
clc;
clf;
close all;
clear all;
a=-5:1:5;
b=[zeros(1,5),ones(1,1),zeros(1,5)];
subplot(3,2,1);
stem(a,b,'b');
title('UNIT IMPULSE');
xlabel('n…....>');
ylabel('Amplitude…..>');
INPUT:
Generation of input signal:
Enter the length of step signal N: 10
Enter the length of ramp signal N: 10
Enter the length of exponential signal N: 10
Enter the length of sinusoidal signal N: 10
Enter the length of sinusoidal signal N: 10
OUTPUT:
Amplitude…..>
1 1
0.5 0.5
0 0
-5 0 5 0 5 10
n…....> n…....>
13
UNIT RAMP x 10EXPONENTIAL SIGNAL
Amplitude…..>
Amplitude…..>
10 2
5 1
0 0
0 5 10 0 5 10
n…....> n…....>
SINUSOIDAL SIGNAL COSINE SIGNAL
Amplitude…..>
Amplitude…..>
5 2
0 0
-5 -2
0 5 10 0 5 10
n…....> n…....>
Result:
Thus the program for the generation of the elementary signals was executed and verified.
Ex. No. 2 CROSS CORRELATION
Aim:
Software Required:
Matlab 7.1
Algorithm:
1. Get two signals x(m)and h(p)in matrix form
2. The correlated signal is denoted as y(n)
3. y(n)is given by the formula
4. stop.
Program:
% Program for computing cross-correlation of the sequences
x=[1, 2, 3, 4]
h=[4, 3, 2, 1]
clc;
clear all;
close all;
x=input('enter the 1st sequence');
h=input('enter the 2nd sequence');
y=xcorr(x,h);
figure;subplot(3,1,1);
stem(x);
ylabel('Amplitude --.');
xlabel('(a) n --.');
subplot(3,1,2);
stem(h);
ylabel('Amplitude --.');
xlabel('(b) n --.');
subplot(3,1,3);
stem(fliplr(y));
ylabel('Amplitude --.');
xlabel('(c) n --.');
disp('The resultant signal is');
fliplr(y)
Input:
enter the 1st sequence [1 2 3 4]
enter the 2nd sequence [4 3 2 1]
Output:
ans =
4
Amplitude --.
0
1 1.5 2 2.5 3 3.5 4
(a) n --.
4
Amplitude --.
0
1 1.5 2 2.5 3 3.5 4
(b) n --.
40
Amplitude --.
20
0
1 2 3 4 5 6 7
(c) n --.
Result:
Thus the program for the cross correlation was executed and verified.
Ex. No. 3 AUTO CORRELATION
Aim:
Software Required:
Matlab 7.1
Algorithm:
1. Get the signal x(n)of length N in matrix form
2. The correlated signal is denoted as y(n)
3. y(n)is given by the formula
4. stop.
Program:
% Program for computing autocorrelation function
x=input('enter the sequence');
y=xcorr(x,x);
figure;subplot(2,1,1);
stem(x);
ylabel('Amplitude --.');
xlabel('(a) n --.');
subplot(2,1,2);
stem(fliplr(y));
ylabel('Amplitude --.');
xlabel('(a) n --.');
disp('The resultant signal is');
fliplr(y)
Input:
enter the sequence [1 2 3 4]
Output:
ans =
3
Amplitude --.
0
1 1.5 2 2.5 3 3.5 4
(a) n --.
30
Amplitude --.
20
10
0
1 2 3 4 5 6 7
(a) n --.
Result:
Thus the program for the Auto correlation was executed and verified.
Ex. No. 4 LINEAR CONVOLUTION
Aim:
To write a MATLAB program for Computing linear convolution using FFT.
Software Required:
Matlab 7.1
Algorithm:
Program:
clc;
clf;
clear all;
close all;
disp('Linear convolution of two sequence');
a=input('Enter the first array sequence:');
b=input('Enter the second array sequence:');
n1=length(a);
n2=length(b);
n=n1+n2-1;
c=conv(a,b);
disp('c=');
disp(c);
disp('n=');
disp(n);
subplot(1,3,1);
stem(a);
xlabel('X(n).....>');
ylabel('n.......>');
title('First array sequence');
subplot(1,3,2);
stem(b);
xlabel('X(n).....>');
ylabel('n.......>');
title('Second array sequence');
subplot(1,3,3);
stem(c);
xlabel('X(n).....>');
ylabel('n.......>');
title('Linear convolution output');
INPUT:
Linear convolution of two sequence
Enter the first array sequence:[1 2 3 4 5 6]
Enter the second array sequence:[1 2 3 4 5]
Output:
c=
1 4 10 20 35 50 58 58 49 30
n= 10
4.5
5 50
4
3.5
4 40
3
n .......>
n .......>
n .......>
3 2.5 30
2
2 20
1.5
1
1 10
0.5
0 0 0
0 5 10 0 5 0 5 10
X(n).....> X(n).....> X(n).....>
Result:
Thus the MATLAB program to perform linear convolution using FFT has been written and the output
sequence is obtained.
Ex. No. 5 CIRCULAR CONVOLUTION
Aim:
To write a MATLAB program for Computing Circular convolution using FFT.
Software Required:
Matlab 7.1
Algorithm:
Step1: First enter the input sequence x(n).
Step2: Plot the input sequence x(n).
Step3: Compute the FFT for the input sequence x(n).
Step4: Enter the impulse response h(n).
Step5: Plot the impulse response h(n).
Step6: Compute FFT for the impulse response h(n).
Step7: Multiply x(n) and h(n).
Step8: Compute IFFT for y(n).
Step9: Display the convolued sequence.
Step10: Stop the program.
Program:
clc;
clf;
clear all;
close all;
disp('Circular convolution of two sequence');
a=input('Enter the first array sequence:');
b=input('Enter the second array sequence:');
c=fft(a);
d=fft(b);
e=c.*d;
f=ifft(e);
l1=0:length(a)-1;
l2=0:length(b)-1;
l3=0:length(f)-1;
disp('The circular convolution output');
disp(f);
subplot(1,3,1);
stem(l1,a);
xlabel('X(n).....>');
ylabel('n.......>');
title('First array sequence');
subplot(1,3,2);
stem(l2,b);
xlabel('X(n).....>');
ylabel('n.......>');
title('Second array sequence');
subplot(1,3,3);
stem(l3,f);
xlabel('X(n).....>');
ylabel('n.......>');
title('Circular convolution output');
INPUT:
Circular convolution of two sequences:
Enter the first array sequence: [1 2 6 7 3 4]
Enter the second array sequence: [9 6 3 4 9 1]
Output:
The circular convolution output
126 117 119 148 108 118
8
6
7
5
6 100
4 5
n.......>
n.......>
n.......>
3 4
3 50
2
2
1
1
0 0 0
0 5 0 5 0 5
X(n).....> X(n).....> X(n).....>
Result:
Thus the MATLAB program to perform Circular convolution using FFT has been written and the output
sequence is obtained.
Ex. No. 6 SPECTRUM ANALYSIS USING DFT
Aim:
To write a MATLAB program for analyze the spectrum using DFT and verify the spectrum
leakage.
Software Required:
Matlab 7.1
Program:
%Computing the DFT:
A = 10;
f0 = 100;
phi = pi/4;
fs = 400;
Ts = 1/fs;
T = 1;
N = T*fs;
tn = (0:N-1)/fs;
x = A*cos(2*pi*f0*Ts*(0:N-1)+phi);
figure(1);
plot(tn,x);
%Spectrum Analysis with the DFT:plots the magnitude of the DFT coefficients
%over the [0; 1] range and the [1=2; 1=2] range
figure(2);
X = fft(x);
fhata = (0:N-1)/N;
subplot(2,1,1);
plot(fhata,abs(X));
fhatb = (-N/2:N/2-1)/N;
subplot(2,1,2);
plot(fhatb,fftshift(abs(X)));
figure(3);
fHz = (-N/2:N/2-1)/N*fs;
plot(fHz,fftshift(abs(X)));
xlabel('frequency in Hz');
ylabel('magnitude of DFT coefficients');
title('Spectrum of signal x(t) = A cos(2*pi*f*t+phi)');
-2
-4
-6
-8
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
2500
2000
1500
1000
500
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
2500
2000
1500
1000
500
0
-0.5 -0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5
m a g n it u d e o f D F T c o e f f ic ie n t s
2000
1500
1000
500
0
-200 -150 -100 -50 0 50 100 150 200
frequenc y in Hz
When, f0 = 150;fs = 600;
Note: We cannot able to see the two peaks.
3000
2000
1000
0
0 0.1 0.2 0.3 0. 4 0.5 0.6 0. 7 0. 8 0. 9 1
3000
2000
1000
0
-0. 5 -0.4 -0.3 -0.2 -0.1 0 0.1 0. 2 0. 3 0. 4 0. 5
3000
2500
2000
1500
1000
500
0
-300 -200 -100 0 100 200 300
frequenc y in Hz
Result:
Thus the MATLAB program to analyze the spectrum using DFT has been written and the spectrum
leakage is verified.
Ex. No. 7a DESIGN OF FIR FILTER (HANNING WINDOW)
Aim:
To design and plot the FIR filter (LPF,HPF,BPF,BRF) using hanning window technique.
Software Required:
Matlab 7.1
Algorithm:
Step1: For the given length N. calculate alpha= (N-1)/2 and assign eps=0.001 and cut off
frequency wc=0.3*pi.
Step2: Calculate delayed sample response (hd) using sine function.
Step3: Claculate the rectangular window coefficient (wr).
Step4: Calculate the sample response h (n) as hd.*wr’.
Step5: Calculate the frequency of h (n) and plot.
Step6: Calculate the hanning window coefficient (wh) using hanning functions.
Step7: Calculate hn=hd.*wh’.
Step8: Calculate the frequency and plot it.
Program:
clc;
clf;
clear all;
close all;
disp('HANNING WINDOW');
disp('Low pass filter');
N=input('Enter the order of the filter =');
wc=input('Enter the cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc/pi);
else
hd(n)=sin(wc*(n-1-a))/(pi*(n-1-a));
end;
w(n)=0.5-0.5*cos((2*pi*(n-1))/(N-1));
h(n)=hd(n)*w(n);
end;
[h,w]=freqz(h,1,15);
mag=20*log(abs(h));
subplot(2,2,1);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('low pass filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');
% HIGH PASS FILTER
disp('High pass filter');
N=input('Enter the order of the filter =');
wc=input('Enter the cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc/pi);
else
hd(n)=(sin(pi*(n-1-a))-sin(wc*(n-1-a)))/(pi*(n-1-a));
end;
w(n)=0.5-0.5*cos((2*pi*(n-1))/(N-1));
h(n)=hd(n)*w(n);
end;
[h,w]=freqz(h,1,15);
mag=20*log(abs(h));
subplot(2,2,2);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('high pass filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');
Output:
h=
1.0109
-0.8531 - 0.2772i
0.4303 + 0.3127i
-0.0813 - 0.1119i
-0.0008 - 0.0024i
0.0000 - 0.0003i
-0.0000 + 0.0001i
-0.0001 + 0.0001i
-0.0001 + 0.0001i
-0.0001 + 0.0000i
-0.0001 - 0.0000i
-0.0001 - 0.0000i
-0.0000 - 0.0000i
-0.0000 - 0.0000i
-0.0000 - 0.0000i
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
low pass filter high pass filter
100 50
0
gain in db....>
gain in db....>
0
-100
-50
-200
-300 -100
0 1 2 3 0 1 2 3
freq in Hz....> freq in Hz....>
band pass filter band stop filter
50 100
0
gain in db....>
gain in db....> 0
-50
-100
-100
-150 -200
0 1 2 3 0 1 2 3
freq in Hz....> freq in Hz....>
Result:
Thus the FIR filter is designed and plotted using hanning window technique.
Ex. No. 7b DESIGN OF FIR FILTER (HAMMING WINDOW)
Aim:
To design and plot the FIR filter (LPF,HPF,BPF,BRF) using hamming window technique.
Software Required:
Matlab 7.1
Algorithm:
Step 1: For the given length N, calculate alpha= (N-1)/2 and assign eps=0.001 and
wc=0.5*pi.
Step2: Calculate delayed sample response (hd) using sine function.
Step3: Calculate the rectangular window coefficients as resonant frequency (wr).
Step4: Calculate unit sample response (hn) as delayed sample tresponse(hd) multiplied by
resonant frequency wr.
Step5: Calculate the frequency of unit sample response and plot it.
Step6: Calculate the hamming window coefficients (wn) using hamming function.
Step7: Calculate hn=hd*wn.
Step8: Calculate the frequency and plot it.
Program:
clc;
clf;
clear all;
close all;
disp('HAMMING WINDOW');
disp('Low pass filter');
N=input('Enter the order of the filter =');
wc=input('Enter the cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc/pi);
else
hd(n)=sin(wc*(n-1-a))/(pi*(n-1-a));
end;
w(n)=0.54-0.46*cos((2*pi*(n-1))/(N-1));
h(n)=hd(n)*w(n);
end;
[h,w]=freqz(h,1,15);
mag=20*log(abs(h));
subplot(2,2,1);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('low pass filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');
% HIGH PASS FILTER
h=
0.9666
0.5558 - 0.7650i
-0.2724 - 0.8383i
-0.7357 - 0.2391i
-0.5085 + 0.3694i
0.0000 + 0.4636i
0.2460 + 0.1787i
0.1648 - 0.0536i
0.0260 - 0.0799i
-0.0199 - 0.0275i
-0.0109
-0.0006 + 0.0009i
-0.0012 - 0.0037i
-0.0058 - 0.0019i
-0.0037 + 0.0027i
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
gain in db....>
-50
-50
-100
-150 -100
0 1 2 3 0 1 2 3
freq in Hz....> freq in Hz....>
band pass filter band stop filter
20 20
0
gain in db....>
gain in db....>
0
-20
-20
-40
-60 -40
0 1 2 3 0 1 2 3
freq in Hz....> freq in Hz....>
Result:
Thus the FIR filter is designed and plotted using hamming window technique.
Ex. No. 7c DESIGN OF FIR FILTER (BLACKMANN WINDOW)
Aim:
To design and plot the FIR filter (LPF,HPF,BPF,BRF) using hamming window technique.
Software Required:
Matlab 7.1
Algorithm:
Step1:For the given length N,calculatealpha=(N-1)/2 and assign eps=0.001 and
wc=0.7*pi.
Step2:Calculate delayed sample response using sine function.
Step3:Calculate the rectangular window coefficient as wr.
Step4:Calculate unit sample response h(n) as hd.*wr’.
Step5:Calculate the frequency of h(n) and plot.
Step6:Calculate the blackmann window coefficient (wn) using blackmann function.
Step7:Calculate hn=hd.*wp’.
Step8:Calcul;ate the frequency the frequency and plot it.
Program:
clc;
clf;
clear all;
close all;
disp('BLACKMANN WINDOW');
disp('Low pass filter');
N=input('Enter the order of the filter =');
wc=input('Enter the cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc/pi);
else
hd(n)=sin(wc*(n-1-a))/(pi*(n-1-a));
end;
w(n)=0.42-0.5*cos(2*pi*(n-1))/(N-1)+0.08*cos(4*pi*(n-1))/(N-1);
h(n)=hd(n)*w(n);
end;
[h,w]=freqz(h,1,15);
mag=20*log(abs(h));
subplot(2,2,1);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('low pass filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');
% HIGH PASS FILTER
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
High pass filter
Enter the order of the filter =15
Enter the cut off frequency =1
h=
-0.1265
-0.0143 + 0.1357i
0.1576 + 0.0335i
0.0507 - 0.1559i
-0.0748 - 0.0333i
0.0440 - 0.0762i
-0.1981 - 0.1440i
-0.1936 + 0.2150i
0.1652 + 0.1835i
0.1798 - 0.1306i
-0.1246 - 0.2159i
-0.2458 + 0.1094i
0.0766 + 0.2356i
0.2248 - 0.0478i
-0.0260 - 0.2471i
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
Band pass filter
Enter the order of the filter =15
Enter the lower cut off frequency =1
Enter the upper cut off frequency =2
h=
0.0295
0.0004 - 0.0043i
0.0335 + 0.0071i
0.0058 - 0.0178i
0.0698 + 0.0311i
0.1111 - 0.1924i
-0.2962 - 0.2152i
-0.3004 + 0.3337i
0.2805 + 0.3115i
0.2243 - 0.1630i
-0.0516 - 0.0894i
0.0032 - 0.0014i
-0.0059 - 0.0180i
0.0003 - 0.0001i
-0.0005 - 0.0045i
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
Band stop filter
Enter the order of the filter =15
Enter the lower cut off frequency =1
Enter the upper cut off frequency =2
h=
-0.0770
-0.0107 + 0.1017i
0.1377 + 0.0293i
0.0387 - 0.1192i
-0.0276 - 0.0123i
0.0578 - 0.1001i
-0.2099 - 0.1525i
-0.2291 + 0.2545i
0.2092 + 0.2323i
0.1381 - 0.1003i
0.0016 + 0.0028i
0.1005 - 0.0448i
-0.0388 - 0.1194i
-0.1040 + 0.0221i
0.0107 + 0.1014i
w=
0
0.2094
0.4189
0.6283
0.8378
1.0472
1.2566
1.4661
1.6755
1.8850
2.0944
2.3038
2.5133
2.7227
2.9322
OUTPUT:
-50 -30
gain in db....>
gain in db....>
-100 -40
-150 -50
-200 -60
0 1 2 3 0 1 2 3
freq in Hz....> freq in Hz....>
band pass filter band stop filter
0 0
-50
gain in db....>
gain in db....>
-50
-100
-100
-150
-200 -150
0 1 2 3 0 1 2 3
freq in Hz....> freq in Hz....>
Result:
Thus the FIR filter is designed and plotted using blackmann window technique.
Ex. No. 8a DESIGN OF IIR FILTER (CHEBYSHEV-I)
AIM:
To write a MATLAB program to design a chebyshev-1 IIR filter low pass, high pass, band pass and
band reject filter.
Software Required:
Matlab 7.1
Algorithm:
Program:
clc;
clf;
close all;
clear all;
disp('CHEBYSHEW FILTER TYPE-I');
disp('LOW PASS FILTER');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
rp=input('Enter the pass band ripple:');
rs=input('Enter the stop band ripple:');
fs=input('Enter the sampling frequency:');
w1=(2*wp)/fs;
w2=(2*ws)/fs;
[n,wn]=CHEB1ORD(w1,w2,rp,rs);
[B,A]=CHEBY1(n,rp,wn);
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,1);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,2);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');
% HIGH PASS FILTER
Output:
Gain in db
0 5
-500 0
-1000 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot low pass filter Phase plot
Gain in db
0 5
-500 0
-1000 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot low pass filter Phase plot
Gain in db
0 5
-500 0
-1000 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot low pass filter Phase plot
Gain in db
1000 5
0 0
-1000 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
RESULT:
Thus the MATLAB program forchebyshev-1 filter is designed, and the characteristics of the low pass,
high pass, band pass and band reject filters are plotted.
Ex. No. 8b DESIGN OF IIR FILTER (CHEBYSHEW FILTER TYPE-II)
AIM:
To write a MATLAB program to design a chebyshev-2 IIR filter low pass, high pass, band pass and
band reject filter.
Software Required:
Matlab 7.1
Algorithm:
Program:
clc;
clf;
close all;
clear all;
disp('CHEBYSHEW FILTER TYPE-II');
disp('LOW PASS FILTER');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
rp=input('Enter the pass band ripple:');
rs=input('Enter the stop band ripple:');
fs=input('Enter the sampling frequency:');
w1=(2*wp)/fs;
w2=(2*ws)/fs;
[n,wn]=CHEB2ORD(w1,w2,rp,rs);
[B,A]=CHEBY2(n,rp,wn);
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,1);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,2);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');
% HIGH PASS FILTER
Output:
Gain in db...> Gain in db...> Gain in db...> Gain in db...>
Gain in db
100 5
0 0
-100 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot low pass filter Phase plot
Gain in db
0 5
-500 0
-1000 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot low pass filter Phase plot
Gain in db
0 5
-500 0
-1000 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot low pass filter Phase plot
Gain in db
100 2
0 0
-100 -2
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
RESULT:
Thus the MATLAB program forchebyshev-2 filter is designed, and the characteristics of the low pass,
high pass, band pass and band reject filters are plotted.
Ex. No. 8c DESIGN OF IIR FILTER (BUTTERWORTH FILTER)
AIM:
To write a MATLAB program to design the Butterworth low pass, high pass, band pass and band reject
filter.
Software Required:
Matlab 7.1
Algorithm:
Program:
clc;
clf;
close all;
clear all;
disp('BUTTERWORTH FILTER');
disp('LOW PASS FILTER');
wp=input('Enter the pass band frequency:');
ws=input('Enter the stop band frequency:');
rp=input('Enter the pass band ripple:');
rs=input('Enter the stop band ripple:');
fs=input('Enter the sampling frequency:');
w1=(2*wp)/fs;
w2=(2*ws)/fs;
[n,wn]=BUTTORD(w1,w2,rp,rs);
[B,A]=BUTTER(n,wn);
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,1);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,2);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');
% HIGH PASS FILTER
OUTPUT:
Gain in db
0 5
-200 0
-400 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot lowpass filter Phase plot
Gain in db
500 5
0 0
-500 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot lowpass filter Gain in db Phase plot
0 5
-200 0
-400 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
Magnitude plot lowpass filter Phase plot
Gain in db
0 5
-200 0
-400 -5
0 0.5 1 0 0.5 1
Normalized freq.....> Phase in radian
RESULT:
Thus the MATLAB program for design the Butterworth low pass, high pass, band pass and band
reject filter is performed and graph was plotted.
Ex. No. 9 MULTIRATE FILTERS
AIM:
To write a MATlab program to generate the sequence and verify the decimation and interpolation
techniques.
Software Required:
Matlab 7.1
Algorithm:
Step:1 Start
Step:2input signal frequency, sampling frequency, time range, sinusoidal signal
Step:3 Discrete plot of the input sequence, x-axis corresponds to the number of samples
Step:4 factor by which the input sequence is decimated
Step:5 resamples the sample in x with a rate (1/M) times the original rate
Step:6 factor by which the input sequence is interpolated
Step:7 resamples the sample in x with a rate L times the original rate
Step:8 coefficient by which the singal is interpolated
Step:9 resamples the sample in x with a rate L times the original rate
Step:10 Stop.
Program:
clc;
close all;
clear all;
1
0
-1
0 10 20 30 40 50 60 70 80
No. of samples
Decimated Sinusoidal Sequence
Amplitude
1
0
-1
0 5 10 15 20 25 30 35 40
No. of samples
Interpolated Sinuoidal Sequence
Amplitude
2
0
-2
0 50 100 150
No. of samples
Original Signal Obtained After Interpolating the Decimated Signal
Amplitude
1
0
-1
0 10 20 30 40 50 60 70 80
No. of samples
Result:
Thus the MATlab program for generating the input sequence was written, and the decimation,
interpolation techniques are verified.
Ex. No. 10 EQUALIZATION
AIM:
To write a MATlab program to obtain the histogram equalization for a given image.
Software Required:
Matlab 7.1
Algorithm:
Step:1 Start.
Step:2 Find the frequency of each pixel value.
Step:3 Find the probability of each frequency.
Step:4 Find the cumulative histogram of each pixel.
Step:5 Find the cumulative distribution probability of each pixel.
Step:6 Calculate the final value of each pixel by multiplying cdf with(no. of bins).
Step:7 Replace the final values.
Step:8 Stop.
Program:
clc;
clf;
close all;
clear all;
A=imread('tire.tif');
figure,imshow(A);
title('Original image')
%Specify the bin range[0 255]
bin=255;
%Find the histogram of the image.
Val=reshape(A,[],1);
Val=double(Val);
I=hist(Val,0:bin);
%Divide the result by number of pixels
Output=I/numel(A);
%Calculate the Cumlative sum
CSum=cumsum(Output);
%Perform the transformation S=T(R) where S and R in the range [ 0 1]
HIm=CSum(A+1);
%Convert the image into uint8
HIm=uint8(HIm*bin);
figure,imshow(HIm);
title('Histogram Equalization')
%Plot equalization part
J = histeq(A);
figure; imhist(A,64)
title('Histogram of Original image')
figure; imhist(J,64)
title('Histogram of equalized image')
Output:
Result:
Thus the MATlab program for written to obtain the histogram equalization for a given image and the
same was verified.
(TMS 320C5416)
Ex. No. 11 STUDY OF ARCHITECTURE OF DIGITAL SIGNAL PROCESSOR
AIM:
8.12 MEMORY
The 5416 device provides both on-chip ROM and RAM memories to aid in system
performance and integration.
Result: