DSP manual-KIOT

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 62

Ex. No.

1 GENERATION OF ELEMENTARY SEQUENCES

Aim:

To write a matlab program for generate the elementary signals.

Software Required:

Matlab 7.1

Algorithm:

Step 1. Start the program


Step 2. Write the formula to generate the sample signals
Step 3. Plot the graph for the output sequence
Step 4. Stop the program.

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…..>');

% UNIT STEP SIGNAL


disp('generation of input signal');
c=input('Enter the length of step signal N:');
d=0:1:c-1;
e=ones(1,c);
subplot(3,2,2);
stem(d,e,'g');
title('UNIT STEP');
xlabel('n…....>');
ylabel('Amplitude…..>');

% UNIT RAMP SIGNAL


f=input('Enter the length of ramp signal N:');
g=0:f;
subplot(3,2,3);
plot(g,g,'m');
title('UNIT RAMP');
xlabel('n…....>');
ylabel('Amplitude…..>');
% EXPONENTIAL SIGNAL
n=input('Enter the length of exponential signal N:');
i=0:0.01:10;
k=3;
j=exp(k*i);
subplot(3,2,4);
plot(i,j,'m');
title('EXPONENTIAL SIGNAL');
xlabel('n…....>');
ylabel('Amplitude…..>');
% SINUSOIDAL SIGNAL
l=input('Enter the length of sinusoidal signal N:');
m=0:0.01:10;
o=3;
n=(o*sin(2*pi*m));
subplot(3,2,5);
plot(m,n,'g');
title('SINUSOIDAL SIGNAL');
xlabel('n…....>');
ylabel('Amplitude…..>');
% COSINE SIGNAL
p=input('Enter the length of cosine signal N:');
q=0:0.01:10;
s=2;
r=(s*cos(2*pi*q));
subplot(3,2,6);
plot(q,r,'r');
title('COSINE SIGNAL');
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:

UNIT IMPULSE UNIT STEP


Amplitude…..>

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:

To write a matlab program for verify the cross correlation.

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 =

16.0000 24.0000 25.0000 20.0000 10.0000 4.0000 1.0000

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:

To write a matlab program for verify the cross correlation.

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:

The resultant signal is

ans =

4.0000 11.0000 20.0000 30.0000 20.0000 11.0000 4.0000

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:

Step1: start the program


Step2: first enter the sequence x (n).
Step3: place the input sequence x (n).
Step4: compute the FFT for the input sequence x (n).
Step5: enter the impulse response h (n).
Step6: plot the impulse response h (n).
Step7: compute the impulse response h (n).
Step8: multiply x (n) and h (n).
Step9: compute IFFT for y (n).
Step10: display the convolued sequence.

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

First array sequence Second array sequence Linear convolution output


6 5 60

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

First array sequence Second array sequence Circular convolution output


7 9 150

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)');

Repeat this expriment with:


f0 = 150;
fs = 600;
In the figure we cannot obtain the two peaks, is called Spectrum
leakage.
Output:
8

-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

S pec trum of s ignal x (t) = A c os (2*pi*f*t+phi)


2500

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

S pectrum of s ignal x (t) = A c os (2*pi*f*t+ phi)


m a g n i t u d e o f D F T c o e f f ic ie n t s

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....>');

% BAND PASS FILTER

disp('Band pass filter');


N=input('Enter the order of the filter =');
wc1=input('Enter the lower cut off frequency =');
wc2=input('Enter the upper cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc2/pi)-(wc1/pi);
else
hd(n)=(sin(wc2*(n-1-a))-sin(wc1*(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,3);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('band pass filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');
% BAND STOP FILTER

disp('Band stop filter');


N=input('Enter the order of the filter =');
wc1=input('Enter the lower cut off frequency =');
wc2=input('Enter the upper cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc2/pi)-(wc1/pi);
else
hd(n)=(sin(wc2*(n-1-a))+sin(pi*(n-1-a))-sin(wc1*(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,4);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('band stop filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');

Input: Hanning Window


Low pass filter
Enter the order of the filter =28
Enter the cut off frequency =13
High pass filter
Enter the order of the filter =28
Enter the cut off frequency =13
Band pass filter
Enter the order of the filter =28
Enter the lower cut off frequency =4
Enter the upper cut off frequency =20

Band stop filter


Enter the order of the filter =20
Enter the lower cut off frequency =5
Enter the upper cut off frequency =10

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

High pass filter


Enter the order of the filter =28
Enter the cut off frequency =13
h=
-0.0109
-0.0980 - 0.0318i
0.3787 + 0.2751i
-0.5065 - 0.6971i
0.3098 + 0.9536i
-0.0000 - 0.9995i
-0.3090 + 0.9512i
0.5877 - 0.8090i
-0.8091 + 0.5879i
0.9509 - 0.3090i
-1.0001 - 0.0000i
0.9512 + 0.3091i
-0.8077 - 0.5869i
0.5928 + 0.8159i
-0.2353 - 0.7242i

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 =28
Enter the lower cut off frequency =4
Enter the upper cut off frequency =20
h=
-1.9993
1.9030 + 0.6183i
-1.6167 - 1.1746i
1.1782 + 1.6216i
-0.6095 - 1.8758i
0.0000 + 1.7125i
0.3962 - 1.2193i
-0.6030 + 0.8299i
0.8055 - 0.5852i
-0.9540 + 0.3100i
0.8530 + 0.0000i
-0.4337 - 0.1409i
0.0769 + 0.0559i
0.0034 + 0.0046i
0.0004 + 0.0012i

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 =20
Enter the lower cut off frequency =5
Enter the upper cut off frequency =10
h=
-1.0015
0.4062 + 0.9124i
0.6688 - 0.7428i
-0.9574 - 0.3111i
0.1017 + 0.9673i
0.7104 - 0.4102i
-0.4374 - 0.3178i
-0.0500 + 0.2352i
0.0501 - 0.0106i
-0.0002 - 0.0002i
0.0085 - 0.0147i
-0.1504 - 0.0158i
0.1335 + 0.4110i
0.4833 - 0.4351i
-0.4665 - 0.2077i

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

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.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,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....>');

% BAND PASS FILTER

disp('Band pass filter');


N=input('Enter the order of the filter =');
wc1=input('Enter the lower cut off frequency =');
wc2=input('Enter the upper cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc2/pi)-(wc1/pi);
else
hd(n)=(sin(wc2*(n-1-a))-sin(wc1*(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,3);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('band pass filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');

% BAND STOP FILTER

disp('Band stop filter');


N=input('Enter the order of the filter =');
wc1=input('Enter the lower cut off frequency =');
wc2=input('Enter the upper cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc2/pi)-(wc1/pi);
else
hd(n)=(sin(wc2*(n-1-a))+sin(pi*(n-1-a))-sin(wc1*(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,4);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('band stop filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');

INPUT - HAMMING WINDOW


Low pass filter
Enter the order of the filter =10
Enter the cut off frequency =1
High pass filter
Enter the order of the filter =10
Enter the cut off frequency =2
Band pass filter
Enter the order of the filter =10
Enter the lower cut off frequency =4
Enter the upper cut off frequency =6
Band stop filter
Enter the order of the filter =10
Enter the lower cut off frequency =3
Enter the upper cut off frequency =5
Output:

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

High pass filter


Enter the order of the filter =10
Enter the cut off frequency =2
h=
-0.0193 - 0.0021i
0.0147 + 0.0143i
0.0018 - 0.0143i
-0.0049 + 0.0089i
0.0081 + 0.0040i
0.0028 + 0.0128i
0.0451 + 0.0396i
0.1481 - 0.0374i
0.0866 - 0.2653i
-0.2512 - 0.3315i
-0.5463 + 0.0061i
-0.3722 + 0.5125i
0.1888 + 0.6063i
0.4994 + 0.1709i
0.2435 - 0.1815i

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 =10
Enter the lower cut off frequency =4
Enter the upper cut off frequency =6
h=
-0.5578 + 1.1144i
0.0955 + 0.0570i
-0.0065 + 0.5361i
0.5417 + 0.3665i
1.0270 - 0.3120i
-0.0545 - 1.3433i
-1.0050 - 0.3175i
-0.6884 + 0.3493i
-0.2180 + 0.6830i
0.2178 + 0.6057i
0.7967 + 0.2814i
0.4127 - 0.6838i
-0.3365 - 0.2655i
-0.1244 + 0.0957i
0.1510 - 0.0078i

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 =10
Enter the lower cut off frequency =3
Enter the upper cut off frequency =5
h=
1.9014 - 0.5801i
-0.2352 - 1.1321i
-0.1685 - 0.2644i
-0.4893 - 0.5509i
-0.9041 + 0.2197i
-0.2416 + 1.0051i
0.9083 + 0.3857i
0.1111 - 0.5810i
-0.1415 + 0.2036i
0.2594 - 0.1209i
-0.0860 - 0.2023i
-0.2934 - 0.0019i
0.1496 + 0.4487i
0.3707 - 0.4750i
-0.6606 - 0.0252i

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


0 0
gain in db....>

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

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.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,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....>');

% BAND PASS FILTER

disp('Band pass filter');


N=input('Enter the order of the filter =');
wc1=input('Enter the lower cut off frequency =');
wc2=input('Enter the upper cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=(wc2/pi)-(wc1/pi);
else
hd(n)=(sin(wc2*(n-1-a))-sin(wc1*(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,3);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('band pass filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');

% BAND STOP FILTER

disp('Band stop filter');


N=input('Enter the order of the filter =');
wc1=input('Enter the lower cut off frequency =');
wc2=input('Enter the upper cut off frequency =');
a=((N-1)/2);
for n=1:N
if(n-1)==a
hd(n)=1-(wc2/pi)-(wc1/pi);
else
hd(n)=(sin(wc2*(n-1-a))+sin(pi*(n-1-a))-sin(wc1*(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,4);
plot(w,mag);
disp('h=');
grid on;
disp(h);
disp('w=');
disp(w);
title('band stop filter');
xlabel('freq in Hz....>');
ylabel('gain in db....>');

INPUT - BLACKMANN WINDOW


Low pass filter
Enter the order of the filter =15
Enter the cut off frequency =1
h=
0.3748
0.0402 - 0.3826i
-0.4005 - 0.0851i
-0.1274 + 0.3920i
0.3016 + 0.1343i
0.0801 - 0.1388i
-0.0027 - 0.0020i
0.0274 - 0.0305i
0.0009 + 0.0010i
0.0211 - 0.0153i
0.0005 + 0.0009i
0.0189 - 0.0084i
0.0002 + 0.0005i
0.0181 - 0.0038i
0.0000 + 0.0002i

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:

low pass filter high pass filter


0 -20

-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:

LOW PASS FILTER:


Step1: Start the program
Step2: Assign alphap=1, alphas=15
Step3: Perform the function wp=0.2*pi,ws=0.3*pi
Step4: Calculate the cutoff frequency and the order of the filter.
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log(abs(h)) and an=angle(h)
Step8: Display the chebyshev low pass filter function
Step9: Stop the program.

HIGH PASS FILTER:


Step1: Start the program
Step2: Assign alphap=1, alphas=15
Step3: Perform the function wp=0.2*pi,ws=0.3*pi
Step4: Calculate the cutoff frequency and the order of the filter.
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log(abs(h)) and an=angle(h)
Step8: Display the chebyshev low pass filter function
Step9: Stop the program.

BAND PASS FILTER:

Step1: Start the program


Step2: Assign alphap=2, alphas=20
Step3: Perform the function wp=0.2*pi, 0.4*pi ws=0.1*pi, 0.5*pi
Step4: Calculate the cutoff frequency and the order of the function
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log(abs(h)) and an=angle(h)
Step8: Display the chebyshev band pass filter function
Step9: Stop the program.

BAND REJECT FILTER:

Step1: Start the program.


Step2: Assign alphap=2, alphas=20
Step3: Perform the function wp=0.2*pi, 0.4*pi ws=0.1*pi, 0.5*pi
Step4: Calculate the cutoff frequency and the order of the function.
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log (abs (h)) and an=angle (h)
Step8: Display the chebyshev band pass filter function
Step9: Stop the program.

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

disp('HIGH 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,'high');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,3);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,4);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

% BAND PASS FILTER

disp('BAND 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]=CHEB1ORD(w1,w2,rp,rs);
wn=[w1,w2];
[B,A]=CHEBY1(n,rp,wn,'bandpass');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,5);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,6);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

% BAND STOP FILTER


disp('BAND STOP 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]=CHEB1ORD(w1,w2,rp,rs);
wn=[w1,w2];
[B,A]=CHEBY1(n,rp,wn,'stop');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,7);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,8);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

Input - Chebyshew Filter Type-I

LOW PASS FILTER:


Enter the pass band frequency: 100
Enter the stop band frequency: 120
Enter the pass band ripple: 1
Enter the stop band ripple: 15
Enter the sampling frequency: 500

HIGH PASS FILTER:


Enter the pass band frequency: 100
Enter the stop band frequency: 120
Enter the pass band ripple: 1
Enter the stop band ripple: 15
Enter the sampling frequency: 500

BAND PASS FILTER:


Enter the pass band frequency: 100
Enter the stop band frequency: 120
Enter the pass band ripple: 1
Enter the stop band ripple: 15
Enter the sampling frequency: 500
BAND STOP FILTER:
Enter the pass band frequency: 100
Enter the stop band frequency: 120
Enter the pass band ripple: 1
Enter the stop band ripple: 15
Enter the sampling frequency: 500

Output:

Magnitude plot low pass filter Phase plot


Gain in db...> Gain in db...> Gain in db...> Gain in db...>

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:

LOW PASS FILTER:


Step1: Start the program
Step2: Assign alphap=1, alphas=15
Step3: Perform the function wp=0.2*pi,ws=0.3*pi
Step4: Calculate the cutoff frequency and the order of the filter.
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log(abs(h)) and an=angle(h)
Step8: Display the chebyshev low pass filter function
Step9: Stop the program.

HIGH PASS FILTER:


Step1: Start the program
Step2: Assign alphap=1, alphas=15
Step3: Perform the function wp=0.2*pi,ws=0.3*pi
Step4: Calculate the cutoff frequency and the order of the filter.
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log(abs(h)) and an=angle(h)
Step8: Display the chebyshev low pass filter function
Step9: Stop the program.

BAND PASS FILTER:


Step1: Start the program
Step2: Assign alphap=2, alphas=20
Step3: Perform the function wp=0.2*pi, 0.4*pi ws=0.1*pi, 0.5*pi
Step4: Calculate the cutoff frequency and the order of the function
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log(abs(h)) and an=angle(h)
Step8: Display the chebyshev band pass filter function
Step9: Stop the program.
BAND REJECT FILTER:
Step1: Start the program.
Step2: Assign alphap=2, alphas=20
Step3: Perform the function wp=0.2*pi, 0.4*pi ws=0.1*pi, 0.5*pi
Step4: Calculate the cutoff frequency and the order of the function.
Step5: Assign the value w=0:0.01:pi
Step6: Calculate the z-transform using the frequency function.
Step7: Perform m=20*log (abs (h)) and an=angle (h)
Step8: Display the chebyshev band pass filter function
Step9: Stop the program.

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

disp('HIGH 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,'high');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,3);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,4);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

% BAND PASS FILTER

disp('BAND 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]=CHEB2ORD(w1,w2,rp,rs);
wn=[w1,w2];
[B,A]=CHEBY2(n,rp,wn,'bandpass');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,5);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,6);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

% BAND STOP FILTER

disp('BAND STOP 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]=CHEB2ORD(w1,w2,rp,rs);
wn=[w1,w2];
[B,A]=CHEBY2(n,rp,wn,'stop');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,7);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,8);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

Input- Chebyshew Filter Type-II

LOW PASS FILTER:


Enter the pass band frequency: 200
Enter the stop band frequency: 300
Enter the pass band ripple: 2
Enter the stop band ripple: 20
Enter the sampling frequency: 800

HIGH PASS FILTER:


Enter the pass band frequency: 200
Enter the stop band frequency: 300
Enter the pass band ripple: 2
Enter the stop band ripple: 20
Enter the sampling frequency: 800

BAND PASS FILTER:


Enter the pass band frequency: 200
Enter the stop band frequency: 300
Enter the pass band ripple: 2
Enter the stop band ripple: 20
Enter the sampling frequency: 800

BAND STOP FILTER:


Enter the pass band frequency: 200
Enter the stop band frequency: 300
Enter the pass band ripple: 2
Enter the stop band ripple: 20
Enter the sampling frequency: 800

Output:
Gain in db...> Gain in db...> Gain in db...> Gain in db...>

Magnitude plot low pass filter Phase plot

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:

Butterworth low pass filter:


Step1: Start the program.
Step2: Assign alphap=4, alphas=30, fp=400, fs=800, f=2000.
Step3: Perform omp=2*fp/f &oms=2*fs/f.
Step4: Calculate cutoff frequency and order of the filter using buttord function.
Step5: Butter function is used to calculate system function.
Step6: Assign w=0:0.01: pi.
Step7: Calculate z transform using freqz function.
Step8: Perform m=abs (h) & an=angle (h).
Step9: Stop the program.

Butterworth high pass filter:


Step1: Start the program.
Step2: Assign alphap=0.4, alphas=30, fp=400, fs=800, f=2000.
Step3: Perform omp=2*fp/f &oms=2*fs/f.
Step4: Calculate cutoff frequency and order of the filter using buttord function.
Step5: Butter function is used to calculate system function.
Step6: Assign w=0:0.01: pi.
Step7: Calculate z transform using freqz function.
Step8: Perform m=20*log(abs (h)) & an=angle (h).
Step9: Stop the program.

Butterworth band pass filter:


Step1: Start the program.
Step2: Assign alphap=2, alphas=20,wp=[0.2*pi,0.4*pi],ws=[0.1*pi,0.5*pi].
Step3: Calculate cutoff frequency and order of the filter using buttord function.
Step4: Butter function is used to calculate system function.
Step5: Assign w=0:0.01: pi.
Step6: Calculate z transform using freqz function.
Step7: Perform m=20*log(abs (h)) & an=angle (h).
Step8: Plot phase in radians in y axis and normalized frequency in x axis.
Step9:Stop the program.
Butterworth bandstop filter:
Step1: Start the program.
Step2: Assign alphap=2, alphas=20,wp=[0.2*pi,0.4*pi],ws=[0.1*pi,0.5*pi].
Step3: Calculate cutoff frequency and order of the filter using buttord function.
Step4: Butter function is used to calculate system function.
Step5: Assign w=0:0.01: pi.
Step6: Calculate z transform using freqz function.
Step7: Perform m=20*log(abs (h)) & an=angle (h).
Step8: Plot phase in radians in y axis and normalized frequency in x axis.
Step9:Stop the program.

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

disp('HIGH 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,'high');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,3);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,4);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

% BAND PASS FILTER

disp('BAND 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]=BUTTORD(w1,w2,rp,rs);
wn=[w1,w2];
[B,A]=BUTTER(n,wn,'bandpass');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,5);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,6);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

% BAND STOP FILTER

disp('BAND STOP 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]=BUTTORD(w1,w2,rp,rs);
wn=[w1,w2];
[B,A]=BUTTER(n,wn,'stop');
w=0:0.01:pi;
[H,w]=FREQZ(B,A,w);
mag=20*log(abs(H));
c=angle(H);
subplot(4,2,7);
plot(w/pi,mag);
title('Magnitude plot low pass filter');
grid on;
xlabel('Normalized freq.....>');
ylabel('Gain in db...>');
subplot(4,2,8);
plot(w/pi,c);
title('Phase plot');
grid on;
xlabel('Phase in radian');
ylabel('Gain in db');

INPUT - BUTTERWORTH FILTER

LOW PASS FILTER:


Enter the pass band frequency: 800
Enter the stop band frequency: 400
Enter the pass band ripple: 4
Enter the stop band ripple: 30
Enter the sampling frequency: 2000

HIGH PASS FILTER:


Enter the pass band frequency: 800
Enter the stop band frequency: 400
Enter the pass band ripple: 4
Enter the stop band ripple: 30
Enter the sampling frequency: 2000

BAND PASS FILTER:


Enter the pass band frequency: 800
Enter the stop band frequency: 400
Enter the pass band ripple: 4
Enter the stop band ripple: 30
Enter the sampling frequency: 2000

BAND STOP FILTER:


Enter the pass band frequency: 800
Enter the stop band frequency: 400
Enter the pass band ripple: 4
Enter the stop band ripple: 30
Enter the sampling frequency: 2000

OUTPUT:

Magnitude plot lowpass filter Phase plot


Gain in db...> Gain in db...> Gain in db...> Gain in db...>

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;         

% Generating Input sequence

fm = 10;            %  input signal frequency


Fs = 140;           %  sampling frequency
t = 0:1/Fs:0.5;     % time range for the input sequence
x = sin(2*pi*fm*t); % input sinusoidal signal
figure(1)
subplot(4,1,1)
stem(x);  % Discrete plot of the input sequence, x-axis corresponds to the number of samples
xlabel('No. of samples');   % labelling x-axis
ylabel('Amplitude');        % labelling y-axis
title('input discrete sinusoidal sequence'); % giving title to the plot
% Decimation of the Input sequence

M = 2;              % factor by which the input sequence is decimated


xd = decimate(x,M); % resamples the sample in x with a rate (1/M) times the original rate
subplot(4,1,2)
stem(xd);           
xlabel('No. of samples');
ylabel('Amplitude');     
title('Decimated Sinusoidal Sequence');

% Interpolation of the Input sequence

L = 2;              % factor by which the input sequence is interpolated


xI = interp(x,L);   % resamples the sample in x with a rate L times the original rate
subplot(4,1,3);
stem(xI);          
xlabel('No. of  samples'); 
ylabel('Amplitude');       
title('Interpolated Sinuoidal Sequence');  

% Interpolation of the Decimated Signal

L = 2;              % coefficient by which the singal is interpolated


xI = interp(xd,L);  % resamples the sample in x with a rate L times the original rate
subplot(4,1,4)
stem(xI);          
xlabel('No. of  samples');
ylabel('Amplitude');      
title('Original Signal Obtained After Interpolating the Decimated Signal');
Output:

input discrete sinusoidal sequence


Amplitude

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.

DSP PROCESSOR BASED


IMPLEMENTATION

(TMS 320C5416)
Ex. No. 11 STUDY OF ARCHITECTURE OF DIGITAL SIGNAL PROCESSOR

AIM:

To study the architecture of digital signal processor.

8.1 History, Development, and Advantages of TMS320 DSPs


In 1982, Texas Instruments introduced the TMS320 - the first fixed-point DSP in the
TMS320 DSPfamily. Before the end of the year, Electronic Products magazine awarded the
TMS32010 the title“Product of the Year”. The TMS32010 became the model for future TMS320
DSP generations.Today, the TMS320 DSP family consists of three supported DSP platforms
TMS320C2000,TMS320C5000, and TMS320C6000. Within the C5000 DSP platform there are
three generations,the TMS320C5x, TMS320C54x, and TMS320C55x. Devices within the C5000
DSP platform usea similar CPU structure that is combined with a variety of on-chip memory and
peripheralconfigurations. These various configurations satisfy a wide range of needs in the
worldwideelectronics market. When memory and peripherals are integrated with a CPU onto a
single chip,overall system const is greatly reduced and circuit board space is reduced.

8.2 APPLICATIONS FOR THE TMS320 DSP FAMILY


The TMS320 DSPs offer more adaptable approaches to traditional signal-processing
problems suchas vocoding and filtering than standard microprocessor microcomputer devices.
They also supportcomplex applications that often require multiple operations to be performed
simultaneously.

8.3 TMS320C54x DSP OVERVIEW


The C54x DSP has a high degree of operational flexibility and speed. It combines an
advancedmodified Harvard architecture (with one program memory bus, three data memory
buses, and fouraddress buses,) a CPU with application-specific hardware logic, on-chip memory,
on-chipperipherals, and a highly specialized instruction set. Spinoff devices that combine the
C54xCPUwith customized on-chip memory and peripheral configurations have been, and
continue to be,developed for specialized areas of the electronics market.

8.4 The C54x devices offer these advantages:


 Enhanced Harvard architecture built around one program bus, three data buses, and four
address buses for increased performance and versatility.
 Advanced CPU design with a high degree of parallelism and application specific
hardware logic for increased performance.
 A highly specialized instruction set for faster algorithms and for optimized high-level
language operation.
 Modular architecture design for fast development of spinoff devices
 Advanced IC processing technology for increased performance and low power
consumption.
 Low power consumption and increased radiation hardness because of new static design
techniques.

8.5 TMS320VC5416 FUNCTIONAL OVERVIEW

8.6 C54X ARCHITECTURAL OVERVIEW


This chapter provides an overview of the architectural structure of the TMS320C54x
DSP, which comprises the central processing unit (CPU), memory, and on-chip peripherals. The
C54x DSPs use an advanced modified Harvard architecture that maximizes processing power
with eight buses.
Separate program and data space allow simultaneous access to program instructions and
data,providing a high degree of parallelism. For example, three reads and one write can be
performedin a single cycle. Instructions with parallel store and application-specific instructions
fully utilize thisarchitecture. In addition, data can be transferred between data and program
spaces. Suchparallelism supports a powerful set of arithmetic, logic, and bit-manipulation
operations that can allbe performed in a single machine cycle. Also, the C54x DSP includes the
control mechanisms tomanage interrupts, repeated operations, and function calling. The
following figure shows afunctional block diagram of the C54x DSP, which includes the principal
blocks and bus structure.
The C54x DSP architecture is built around eight major 16-bit buses (four program/dat
buses and four address buses):
 The program bus (PB) carries the instruction code and immediate operands from program
memory.
 Three data buses (CB, DB, and EB) interconnect to various elements, such as the CPU,
data address generation logic, program address generation logic, on-chip peripherals, and
data memory.
- The CB and DB carry the operands that are read form data memory.
- The EB carries the data to be written to memory.
 Four address buses (PAB, CAB, DAB, and EAB) carry the addresses needed for
instruction execution.
The C54x DSP can generate up to two data-memory addresses per cycle using the two
auxiliaryregister arithmetic units (ARAU0 AND ARAU1).
The C54x DSP also has an on-chip bidirectional bus for accessing on-chip
peripherals.This bus isconnected to DB and EB through the bus exchanger in the CPU interface.
Accesses that use thisbus can require two or more cycles for reads and writes, depending on the
peripheral’s structure.

8.7 CENTRAL PROCESSING UNIT (CPU)


The CPU is common to all C54x devices. The C54x DSP contains:
 CPU status and control registers
 40-bit arithmetic logic unit (ALU)
 Two 40-bit accumulators.
 Barrel shifter
 17 × 17-bit multiplier
 40-bit adder
 Compare, select, and store unit (CSSU)
 Data address generation unit
 Program address generation unit

8.8 ARITHMETIC LOGIC UNIT (ALU)


The C54x DSP performs 2s-complement arithmetic with a 40-bit arithmetic logic unit (ALU)
and two 40-bit accumulators (accumulators A and B). The ALU can also perform Boolean
operations.
The ALU uses these inputs:
 16-bit immediate value
 16-bit word from data memory
 16-bit value in the temporary register, T
 Two 16-bit words from data memory
 32-bit word from data memory
 40-bit word from either accumulator.
The ALU can also function as two 16-bit ALUs and perform two 16-bit operations
simultaneously.

8.9 DATA ADDRESSING


The C54x DSP offers seven basic data addressing modes:
 Immediate addressing uses the instruction to encode a fixed value.
 Absolute addressing uses the instruction to encode a fixed address.
 Accumulator addressing uses accumulator A to access a location in program memory as
data.
 Direct addressing uses seven bits of the instruction to encode the lower seven bits of
anaddress. The seven bits are used with the data page pointer (DP) or the stack pointer
(SP)to determine the actual memory address.
 Indirect addressing uses the auxiliary registers to access memory.
 Memory-mapped register addressing uses the memory-mapped registers without
modifying
 either the current DP value or the current SP value.
 Stack addressing manages adding and removing items from the system stack.
During the execution of instructions using direct, indirect, or memory-mapped register
addressing, the data-address generation logic (DAGEN) computes the addresses of data-memory
operands.

8.10 PIPELINE OPERATION


An instruction pipeline consists of a sequence of operations that occur during the execution of an
instruction. The C54x DSP pipeline has six levels: pre fetch, fetch, decode, access, read,
andexecute. At each of the levels, an independent operation occurs. Because these operations
areindependent, form one to six instructions can be active in any given cycle, each instruction at
adifferent stage of completion. Typically, the pipeline is full with a sequential set of instructions,
eachat one of the six stages. When a PC discontinuity occurs, such as during a branch, call, or
return,one or more stages of the pipeline may be temporarily unused.

8.11 ON-CHIP PERIPHERALS


The 5416 device has the following peripherals:
 Software-programmable wait-state generator
 Programmable bank-switching logic
 A clock generator with a multiple phase - locked loop (PLL)
 A hardware timer
 Direct memory access (DMA) controller
 Enhanced external parallel interface (XIO2)
 Three multichannel buffered serial ports (McBSPs)
 A host-port interface (HPI18/16)

8.12 MEMORY
 The 5416 device provides both on-chip ROM and RAM memories to aid in system
performance and integration.

8.13 DATA MEMORY


 The data memory space addresses up to 64K of 16-bit words. The device automatically
accessesthe on-chip RAM when addressing within its bounds. When an address is
generated outside the
 RAM bounds, the device automatically generates an external access. The advantages of
operatingfrom on-chip memory are as follows:
 Higher performance because no wait states are required
 Higher performance because of better flow within the pipeline of the central arithmetic
logicunit (CALU)
 Lower cost than external memory
 Lower power than external memory
The advantage of operating from off-chip memory is the ability to access a larger address space.

8.14 INSTRUCTION SET SUMMARY


The TMS320C54xE DSP instruction set can be divided into four basic types of operations:
 Arithmetic operations
 Logical operations
 Program-control operations
 Load and store operations

8.15 ARITHMETIC OPERATIONS


 Add instructions
 Subtract instructions
 Multiply instructions
 Multiply-Accumulate and Multiply-Subtract instructions
 Multiply-Accumulate and Multiply-Subtract instructions (Continued)

8.16 LOGICAL OPERATIONS


 AND Instructions
 OR Instructions
 XOR Instructions
 Shift Instructions
 Test Instructions

8.17 PROGRAM-CONTROL OPERATIONS


 Branch Instructions
 Call Instructions
 Interrupt Instructions
 Return Instructions
 Repeat Instructions
 Stack-Manipulating Instructions
 Miscellaneous Program-Control Instructions

8.18 LOAD AND STORE OPERATIONS


 Load Instructions
 Store Instructions
 Conditional Store Instructions
 Parallel Load and Store Instructions
 Parallel Load and Multiply Instructions
 Parallel Store and Add/Subtract Instructions
 Parallel Store and Multiply Instructions
 Miscellaneous Load-Type and Store-Type Instructions

Result:

Thus the architecture of digital signal processor was studied.

You might also like