Sunteți pe pagina 1din 59

DEPARTMENT OF ECE

EC2306-DIGITAL SIGNAL PROCESSING


LABORATORY

LAB MANUAL

EXP.NO:1
DATE :
AIM:

REPRESENTATION OF BASIC SIGNALS

To write a program to generate unit step, unit impulse, unit ramp, exponential, sine and
cosine signal using Matlab.
ALGORITHM:
1. Start the program.
2. Generate unit step, unit impulse, unit ramp, exponential, sine and cosine
Signal.
3. Execute the program.
4. Plot the output for each sequence.
5. Stop the process.
FLOW CHART:

PROGRAM
GENERATION OF SIGNALS
GENERATION OF SINE SIGNAL (DISCRETE)
t=0:.01:pi;
y=sin(2*pi*t);
subplot(2,2,1);
plot(t,y);
xlabel('Time axis------>');
ylabel('Amplitude');
title('SINE SIGNAL');

OUTPUT

SINE SIGNAL

1
0.8
0.6

A m p lit u d e

0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

0.5

1.5
2
Time axis------>

2.5

3.5

GENERATION OF SINE SIGNAL (CONTINUOUS)


t=0:.01:pi;
y=sin(2*pi*t);
subplot(2,2,1);
plot(t,y);
xlabel('Time axis------>');
ylabel('Amplitude');
title('SINE SIGNAL');

OUTPUT
SINE SIGNAL

1
0.8

A m p li t u d e

0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

0.5

1.5
2
Time axis------>

GENERATION OF COSINE SIGNAL (DISCRETE)


t=0:.01:pi;

2.5

3.5

y=cos(2*pi*t);
subplot(2,2,1);
stem(t,y);
xlabel('Time axis------>');
ylabel('Amplitude axis------>');
title('COSINE SIGNAL');
OUTPUT
COSINE SIGNAL

A m p lit u d e a x is ------>

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

0.5

1.5

2
2.5
3
Time axis------>

3.5

4.5

4.5

GENERATION OF COSINE SIGNAL (CONTINUOUS)


t=0:.01:pi;
y=cos(2*pi*t);
subplot(2,2,2);
plot(t,y);
xlabel('Time axis------>');
ylabel('Amplitude axis------>');
title('COSINE SIGNAL');

A m p lit u d e a x is ------>

OUTPUT
COSINE SIGNAL

1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1

0.5

1.5

2
2.5
3
Time ax is------>

3.5

GENERATION OF UNIT IMPULSE SEQUENCE


n=-3:1:3;
y=[zeros(1,3) ones(1,1) zeros(1,3)];
subplot(2,2,1);
stem(n,y);
xlabel('n------>');
ylabel('Amplitude axis------>');
title('unit impulse sequence');
OUTPUT
UNIT IMPULSE

A m p lit u d e a x is ------>

1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-3

-2

-1

0
n------>

% GENERATION OF UNIT STEP SEQUENCE


n=input ('Enter the value of n =');
t=0:1:n-1;
y=ones(1,n);
subplot(2,2,2);
stem(t,y);
xlabel('n------>');
ylabel('Amplitude axis------>');
title('unit step sequence');

A m p lit u d e a x is ------>

OUTPUT:
Enter the value of n=8
unit step sequenc e

1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0

n------>

GENERATION OF RAMP SIGNAL


n1=input('Enter the length of ramp = ');
t=0:n1;
subplot(2,1,1);
stem(t,t);
xlabel('Time axis----->');
ylabel('Amplitude----->');
title('RAMP SEQUENCE');
OUTPUT
Enter the length of ramp = 8

RAMP SEQUENCE

A m p lit u d e ----->

7
6
5
4
3
2
1
0

4
Time axis----->

GENERATION OF EXPONENTIAL SIGNAL


n2=input('Enter the length of exponential sequence = ');
t=0:n2;
a=input('Enter the value of a = ');
y2=exp(a*t);
subplot(2,1,1);
stem(t,y2);
xlabel('Time axis----->');
ylabel('Amplitude----->');
title('EXPONENTIAL SEQUENCE = ');

OUTPUT
Enter the length of exponential sequence = 8
Enter the value of a = 1
EXPONENTIAL SEQUENCE =

A m p lit u d e ----->

3000

2500

2000

1500

1000

500

4
Time axis----->

RESULT:
Thus a program to generate the Sine, Cosine, Unit Impulse, Exponential, Ramp and Unit
step signals using MatLab was written and executed.

EXPT NO.2
DATE :

LINEAR CONVOLUTION AND CIRCULAR CONVOLUTION


( BY NORMAL METHOD AND USING FFT)

AIM:
To write a MATLAB program to perform linear convolution and circular convolution of
the two given sequences.
THEORY:
Linear Convolution:
Convolution is a powerful way of characterizing the input-output relationship of LTI
systems. If the impulse response sequence of a LTI system is known. The response of the
system to any arbitrary input can be obtained by convolving the impulse response with the
h(n)

input.Consider a LTI system with impulse response


x (n)

system to the input

of length Q is given by,

of length P. The response of the

y (n) h(k )x(n k )

N P Q 1

The length of the output sequence is


convolution sum are,

.The steps involved in finding the

h(k )

1. Folding:Fold the signal


h( k )

2. Shifting: Shift

no

about the origin at

to the left by

no

if

no

k 0

at a single time instant

n no

h( no k )

x (k )

3. Multiplication: Multiply

h( k )

is positive or shift

h( no k )

is negative to

by

h( k )

to obtain

.
to the right by

no

if

to obtain the product sequence

yo( k ) x( k ) h( no k )

(k)

yo(k )

4. Summation: Sum all the values of the product sequence


output at time

n no

Circular Convolution:

to obtain the value of

x1 (n)
x 2 ( n)
Consider two signals
and
of finite duration. The circular convolution of two
x 3 ( m)
sequence represented by
is given by
x3 ( m) x1 ( n) x 2 (( m n), (mod N )), m 0,1,..........N 1
x(n)

In general, the linear convolution of two sequence

h(n)

and

with the length N1and

N N1 N 2 1

x(n)

h(n)

N2 respectively will give a sequence with a length of


when
and
have a duration less than N1 for implementing convolution using circular convolution. N2-1,
X (n)

N1 Zeros are padded at the end of

h(n)

and

respectively to increase the length of N.

PROGRAM
LINEAR CONVOLUTION OF TWO SEQUENCES
clc;
clear all;
close all;
x=input('Enter the first sequence : ');
h=input('Enter the second sequence : ');
y=conv(x,h);
figure;
subplot(3,2,1);
stem(x);
ylabel('Amplitude---->');
xlabel('(a)n---->');
subplot(3,2,2);
stem(h);
ylabel('Amplitude---->');
xlabel('(b)n---->');
subplot(3,2,3);
stem(y);
ylabel('Amplitude---->');
xlabel('(c)n---->');
disp('The resultant signal is:');y
OUTPUT
Enter the first sequence : [1 2 3 4]
Enter the second sequence : [1 1 1 1]
The resultant signal is:
y=

10

PROGRAM FOR LINEAR CONVOLUTION


clc;
clear all;
close all;
%linear convolution
h=input ('enter the first input sequence h(n):');
x=input ('enter the second input sequence x(n):');
L=length (h);
m=length(x);
h= [zeros(1, L+m-2), h, zeros(1, m-1)];
x=[x, zeros(1, L-1)];
z=L+m-1;
for n=L+m: 1:L+m+L+m-2
y(n-z)=0;
for k=1:1:L+m-1
y(n-z)=y(n-z)+h(n-k)*x(k);
end
end
subplot(2,2,1);
stem(h);
xlabel('Index n');
title('input sequence h(n)');
subplot(2,2,2);
stem(x);
xlabel('Index n');
ylabel('Amplitude');
title('Input sequence x(n)');
subplot(2,1,2);

stem(y);
xlabel('Index n');
ylabel('Amplitude');
title('output sequence y(n)');
OUTPUT
enter the first input sequence h(n):[1 2 3 4]
enter the second input sequence x(n):[3 4 5 6]
input sequence h(n)

3
2
1
0

Index n

10

15

4
2
0

output sequence y(n)

50

A m p lit u d e

Input sequence x(n)

A m p lit u d e

4
Index n

40
30
20
10
0

4
Index n

PROGRAM FOR CIRCULAR CONVOLUTION


clc; clear all; close all;
g=input('Enter the first sequence: ');
h=input('Enter the second sequence: ');
N1=length(g);
N2=length(h);
N=max(N1,N2);
N3=N1-N2;
%loop for generating equal length
if(N3>=0)
h=[h,zeros(1,N3)];
else
g=[g,zeros(1,-N3)];
end
%computation of circular convolution
for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)

j=N+j;
end
y(n)=y(n)+g(i)*h(j);
end
end
subplot(3,2,1);
stem(g);
ylabel('Amplitude---->');
xlabel('(a)n---->');
subplot(3,2,2);
stem(h);
ylabel('Amplitude---->');
xlabel('(b)n---->');
subplot(3,2,3);
stem(y);
ylabel('Amplitude---->');
xlabel('(c)n---->');
disp('The resultant signal is; ');y
OUTPUT
Enter the first sequence: [1 2 3 4]
Enter the second sequence: [3 4 5 7]
The resultant signal is;
y=

A m p lit u d e ---->

50

41

4
2
0

(a)n---->

A m p lit u d e ---->

51

A m p lit u d e ---->

48

10
5
0

(b)n---->

100
50
0

(c)n---->

PROGRAM FOR CONVOLUTION USING FFT


%Linear convolution
clear

clc
close all
% FIRST SEQUENCE X1
x1 = [1 1 1 1];
nx1 = 0:length(x1)-1;
n1 = length(x1);
subplot(3,1,1);
stem(nx1,x1);
xlabel('n-->');
ylabel('x1-->');
title('First Sequence');
grid on;
% SECOND SEQUENCE X2
x2 = [1 1 1 1];
nx2 = 0:length(x2)-1;
n2 = length(x2);
subplot(3,1,2);
stem(nx2,x2);
xlabel('n-->');
ylabel('x2-->');
title('Second Sequence');
grid on;
N = n1+n2-1;
% IF N > length(x1) or length(x2) ZERO PAD
newx1 = [x1,zeros(1,N-n1)];
newx2 = [x2,zeros(1,N-n2)];
% TAKE DFT OF FIRST SEQUENCE
x1dft = fft(newx1);
% TAKE DFT OF SECOND SEQUENCE
x2dft = fft(newx2);
% MULTIPLY THE TWO DFTS
ydft = x1dft .* x2dft
% TAKE IDFT OF THE PRODUCT OF TWO DFTS
disp('Response obtained by DFTs')
y = ifft(ydft)
n = 0:length(y)-1;
subplot(3,1,3);
stem(n,y);
xlabel('n-->');
ylabel('x2-->');
title('Linearly convoluted Sequence');grid on;
% CIRCULAR CONVOLUTION ORDER
N = 4;

% if N > length(x1) or length(x2) zero pad


newx1 = [x1,zeros(1,N-n1)];
newx2 = [x2,zeros(1,N-n2)];
% TAKE DFT OF FIRST SEQUENCE
x1dft = fft(newx1);
% TAKE DFT OF SECOND SEQUENCE
x2dft = fft(newx2);
% MULTIPLY THE TWO DFTS
ydft = x1dft .* x2dft
% TAKE IDFT OF THE PRODUCT OF TWO DFTS
disp('Response obtained by DFTs')
y = ifft(ydft)
n = 0:length(y)-1;
subplot(3,1,3);
stem(n,y);
xlabel('n-->');
ylabel('x2-->');
title('circularly convoluted Sequence');
grid on;
OUTPUT
ydft =
Columns 1 through 5
16.0000
-4.5489 - 2.1906i 0.1920 + 0.2408i -0.1431 - 0.6270i -0.1431 + 0.6270i
Columns 6 through 7
0.1920 - 0.2408i -4.5489 + 2.1906i
Response obtained by DFTs
y=
1.0000 2.0000 3.0000 4.0000 3.0000 2.0000 1.0000
ydft =
16 0 0 0
Response obtained by DFTs
y=
4 4 4 4

x 1 -->

0.5
0

x 2 -->

First Sequence

0.5

0.5

0.5

1.5
n-->
Second Sequence

2.5

2.5

2.5

0.5

x 2 -->

1.5
2
n-->
circularly convoluted Sequence

2
0

1.5
n-->

RESULT
Thus the Matlab program to perform linear and circular convolution were written and the outputs
were obtained.

EXPT NO: 3
DATE :

SAMPLING AND ALIASING EFFECT

AIM:
To write a MATLAB program to Sampling and aliasing effects in the signal.
INTRODUCTION:
Digital signal processing algorithms are often used to process continuous time signals. To this
end, it is necessary to convert a continuous time signal into an equivalent discrete time signal,
apply the necessary digital signal processing algorithm to it and then convert back the processed
discrete-time signal into an equivalent continuous -time signal, In the ideal case the conversion
of a continuous time signal into a discrete time form is implemented by periodicsampling, and to
prevent aliasing. Analoganti-aliasing filter is often placed before sampling to band limit the
continuous time signal. The conversion of a discrete-time signal into a continuous signal requires
an analog reconstruction filter.
THEORY:

X a (t )

Let

be a continuous -time signal that is sampled uniformly at

t nT

generating

X [n] x a (nT )

x[n]

the
where
-<N With T being the sampling period. The reciprocal of T is
called the sampling frequency FT, ie. FT=1/T.This exercise helps to study the relation in the time
X a (t )

domain between a continuous time signal

x[n]

and the discrete time signal

generatedby a

x a (t )

periodic sampling of

. Since MATLAB cannot strictly generate a continuous - time signal,

{ X a (nTH )}

a sequence
is generated from
samples are very close to each other.

X a (t )

by sampling it at a very high rate T H such that

PROGRAM:
%PROGRAM FOR SAMPLING AND ALIASING IN SIMPLE METHOD
%SAMPLING & ALIASING EFFECT
N=input('ENTER THE NO OF SAMPLES N =');
n=0:N-1;
fm=0.02;
%ANALOG INPUT
x=sin(2*pi*fm*n);
subplot(2,2,1);
plot(n,x);
xlabel('n------>');
ylabel('x-------->');
title('CONTINUOUS TIME SIGNAL');
%fs<fm
fs1=0.02;
x1=sin(2*pi*fm*n/fs1);
subplot(2,2,2);
stem(n,x1);

xlabel('n------>');
ylabel('x1-------->');
title('DISCRETE TIME SIGNAL WHEN fs<2fm');
%fs=2fm
fs2=0.04;
x2=sin(2*pi*fm*n/fs2);
subplot(2,2,3);
stem(n,x2);
xlabel('n------>');
ylabel('x2-------->');
title('DISCRETE TIME SIGNAL WHEN fs=2fm');
%fs>2fm
fs3=0.5;
x3=sin(2*pi*fm*n/fs3);
subplot(2,2,4);
stem(n,x3);
xlabel('n------>');
ylabel('x3-------->');
title('DISCRETE TIME SIGNAL WHEN fs>2fm');

OUTPUT
ENTER THE NO OF SAMPLES N =5

-16
DISCRETE
x 10 TIME SIGNAL WHEN fs<2fm
5

CONTINUOUS TIME SIGNAL

0.8

x1-------->

x-------->

0.6
0.4
0.2

-5

-10
2
3
4
0
1
2
3
4
n------>
n------>
-16
DISCRETE
x 10 TIME SIGNAL WHEN fs=2fm DISCRETE TIME SIGNAL WHEN fs>2fm
10
1
0

x3-------->

x2-------->

0
-5

2
n------>

0.5

2
n------>

RESULT:
Thus the sampled output of the input sinusoidal signal is plotted and the effect of
aliasing studied.

EXPT NO: 4
DATE :

DESIGN AND ANALYSIS OF FIR FILTERS (WINDOW DESIGN)

AIM:
To write a program to design the FIR lowpass, Highpass, Bandpass and Band stop filters
using RECTANGULAR window and find out the response of the filter by using MATLAB.
ALGORITHM:
1. Start the program.
2. Get the input sequence for pass band ripple, stop band ripple, pass band
Frequency and stop band frequency and sampling frequency.
3. Convert the frequency into radians/sec.
4. Compute the order and cut off frequency of the filter and display it.
5. Design the analog filter and find the Rectangular window coefficient.
6. Find out the frequency response of the filter.
8. Compute the magnitude and phase response of the filter.
9. Repeat the process for highpass, bandpass and band stop filters.
10. Execute the program, display the result and verify it.
11. Plot the output graph for each sequence for lowpass and Highpass filters.
12. Stop the process.
PROGRAM:
%PROGRAM TO DESIGN A FIR DIGITAL FILTER USING RECTANGULAR WINDOW
clear all;
rp=input('Enter the PB ripple rp =');
rs=input('Enter the SB ripple rs =');
fp=input('Enter the PB frequency fp =');
fs=input('Enter the SB frequency fs =');
f=input('Enter the sampling frequency f =');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=boxcar(n1);
%LPF
b=fir1(n,wp,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF LPF');

%HPF
b=fir1(n,wp,'high',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF HPF');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BPF');
%BSF
b=fir1(n,wn,'stop',y);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(o/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BSF');
OUTPUT
Enter the PB ripple rp =.03
Enter the SB ripple rs =.05
Enter the PB frequency fp =2000
Enter the SB frequency fs =3000
Enter the sampling frequency f =9000

0
-50
-100

0
-50
-100

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BSF
20

Gain in db--------.

Gain in db--------.

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BPF
50
0

-50
-100

MAGNITUDE RESPONSE OF HPF


50
Gain in db--------.

Gain in db--------.

MAGNITUDE RESPONSE OF LPF


50

0.5
Normalized freqency------>

0
-20
-40
-60

0.5
Normalized freqency------>

RESULT:
Thus a program to design the FIR lowpass, highpass, bandpass and band stop
Filters using RECTANGULAR Window was written and response of the filter using
Matlab was executed.

DESIGN OF FIR FILTERS (WINDOW DESIGN)


AIM:
To write a program to design the FIR lowpass, Highpass, Bandpass and Band stop filters
using HANNING window and find out the response of the filter by using MATLAB.
ALGORITHM:
1. Start the program.
2. Get the input sequence for pass band ripple, stop band ripple, pass band
Frequency and stop band frequency and sampling frequency.
3. Convert the frequency into radians/sec.
4. Compute the order and cut off frequency of the filter and display it.
5. Design the analog filter and find the Hanning window coefficient.
6. Find out the frequency response of the filter.
8. Compute the magnitude and phase response of the filter.
9. Repeat the process for highpass, bandpass and band stop filters.
10. Execute the program, display the result and verify it.
11. Plot the output graph for each sequence for lowpass and Highpass filters.
12. Stop the process.

PROGRAM:
%PROGRAM TO DESIGN A FIR DIGITAL FILTER USING HANNING WINDOW
clear all;
rp=input('Enter the PB ripple rp =');
rs=input('Enter the SB ripple rs =');
fp=input('Enter the PB frequency fp =');
fs=input('Enter the SB frequency fs =');
f=input('Enter the sampling frequency f =');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=hanning(n1);
%LPF
b=fir1(n,wp,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF LPF');
%HPF
b=fir1(n,wp,'high',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF HPF');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');

title('MAGNITUDE RESPONSE OF BPF');


%BSF
b=fir1(n,wn,'stop',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BSF');
OUTPUT:
Enter the PB ripple rp =.03
Enter the SB ripple rs =.02
Enter the PB frequency fp =1500
Enter the SB frequency fs =2000
Enter the sampling frequency f =9000

0
-50
-100
-150

0
-50
-100

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BSF
5

Gain in db--------.

Gain in db--------.

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BPF
0

-50

-100

MAGNITUDE RESPONSE OF HPF


50

Gain in db--------.

Gain in db--------.

MAGNITUDE RESPONSE OF LPF


50

0.5
Normalized freqency------>

0
-5
-10

0.5
Normalized freqency------>

RESULT:
Thus a program to design the FIR lowpass, highpass, bandpass and band stop
Filters using HANNING Window was written and response of the filter using Matlab
was executed.

DESIGN OF FIR FILTERS (WINDOW DESIGN)


AIM:
To write a program to design the FIR lowpass, Highpass, Bandpass and Band stop filters
using HAMMING window and find out the response of the filter by using MATLAB.
ALGORITHM:
1. Start the program.
2. Get the input sequence for pass band ripple, stop band ripple, pass band
Frequency and stop band frequency and sampling frequency.
3. Convert the frequency into radians/sec.
4. Compute the order and cut off frequency of the filter and display it.
5. Design the analog filter and find the Hamming window coefficient.
6. Find out the frequency response of the filter.
8. Compute the magnitude and phase response of the filter.
9. Repeat the process for highpass, bandpass and band stop filters.
10. Execute the program, display the result and verify it.
11. Plot the output graph for each sequence for lowpass and Highpass filters.
12. Stop the process.
PROGRAM:
%PROGRAM TO DESIGN A FIR DIGITAL FILTER USING HAMMING WINDOW
clear all;
rp=input('Enter the PB ripple rp =');
rs=input('Enter the SB ripple rs =');
fp=input('Enter the PB frequency fp =');
fs=input('Enter the SB frequency fs =');
f=input('Enter the sampling frequency f =');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=hamming(n1);
%LPF
b=fir1(n,wp,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');

title('MAGNITUDE RESPONSE OF LPF');


%HPF
b=fir1(n,wp,'high',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF HPF');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BPF');
%BSF
b=fir1(n,wn,'stop',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BSF');
OUTPUT
Enter the PB ripple rp =.02
Enter the SB ripple rs =.01
Enter the PB frequency fp =1200
Enter the SB frequency fs =1700
Enter the sampling frequency f =9000

0
-50
-100
-150

0
-50
-100

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BSF
5

Gain in db--------.

Gain in db--------.

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BPF
0

-50
-100
-150

MAGNITUDE RESPONSE OF HPF


50

Gain in db--------.

Gain in db--------.

MAGNITUDE RESPONSE OF LPF


50

0.5
Normalized freqency------>

0
-5
-10
-15

0.5
Normalized freqency------>

RESULT:
Thus a program to design the FIR lowpass, highpass, bandpass and band stop
Filters using HAMMING Window was written and response of the filter using Matlab
was executed.
DESIGN OF FIR FILTERS (WINDOW DESIGN)
AIM:
To write a program to design the FIR lowpass, Highpass, Bandpass and Band stop filters
using BLACKMAN window and find out the response of the filter by using MATLAB.
ALGORITHM:
1. Start the program.
2. Get the input sequence for pass band ripple, stop band ripple, pass band
Frequency and stop band frequency and sampling frequency.
3. Convert the frequency into radians/sec.
4. Compute the order and cut off frequency of the filter and display it.
5. Design the analog filter and find the Blackman window coefficient.
6. Find out the frequency response of the filter.
8. Compute the magnitude and phase response of the filter.
9. Repeat the process for highpass, bandpass and band stop filters.
10. Execute the program, display the result and verify it.
11. Plot the output graph for each sequence for lowpass and Highpass filters.
12. Stop the process.
PROGRAM:
%PROGRAM TO DESIGN A FIR DIGITAL FILTER USING BLACKMAN WINDOW
clear all;
rp=input('Enter the PB ripple rp =');

rs=input('Enter the SB ripple rs =');


fp=input('Enter the PB frequency fp =');
fs=input('Enter the SB frequency fs =');
f=input('Enter the sampling frequency f =');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=blackman(n1);
%LPF
b=fir1(n,wp,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF LPF');
%HPF
b=fir1(n,wp,'high',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF HPF');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BPF');
%BSF
b=fir1(n,wn,'stop',y);

[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(O/pi,m);
xlabel('Normalized freqency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BSF');
OUTPUT

0
-50
-100

G a in in d b --------.

-150

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BPF
0

-50
-100
-150

0.5
Normalized freqency------>

G a in in d b --------.

MAGNITUDE RESPONSE OF LPF


50

MAGNITUDE RESPONSE OF HPF


50
0
-50
-100
-150

G a in in d b --------.

G a in in d b --------.

Enter the PB ripple rp =.03


Enter the SB ripple rs =.01
Enter the PB frequency fp =2000
Enter the SB frequency fs =2500
Enter the sampling frequency f =7000

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BSF
5
0

-5
-10

0.5
Normalized freqency------>

RESULT:
Thus a program to design the FIR lowpass, highpass, bandpass and band stop
Filters using Blackman Window was written and response of the filter using Matlab
was executed.
DESIGN OF FIR FILTERS (WINDOW DESIGN)
AIM:
To write a program to design the FIR lowpass, Highpass, Bandpass and Band stop filters
using KAISER window and find out the response of the filter by using MATLAB.

ALGORITHM:
1. Start the program.
2. Get the input sequence for pass band ripple, stop band ripple, pass band
Frequency and stop band frequency and sampling frequency.
3. Convert the frequency into radians/sec.
4. Compute the order and cut off frequency of the filter and display it.
5. Design the analog filter and find the Kaiser Window coefficient.
6. Find out the frequency response of the filter.
8. Compute the magnitude and phase response of the filter.
9. Repeat the process for highpass, bandpass and band stop filters.
10. Execute the program, display the result and verify it.
11. Plot the output graph for each sequence for lowpass and Highpass filters.
12. Stop the process.
PROGRAM:
%PROGRAM TO DESIGN A FIR DIGITAL FILTER USING KAISER WINDOW
clc;
close all;
clear all;
rp=input('Enter the PB ripple rp =');
rs=input('Enter the SB ripple rs =');
fp=input('Enter the PB frequency fp =');
fs=input('Enter the SB frequency fs =');
f=input('Enter the sampling frequency f =');
b=input('Enter the beeta value =')
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=kaiser(n1);
%LPF
b=fir1(n,wp,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF LPF');

%HPF
b=fir1(n,wp,'high',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF HPF');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BPF');
%BSF
b=fir1(n,wn,'stop',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,4);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BSF');
OUTPUT:
Enter the PB ripple rp =.03
Enter the SB ripple rs =.02
Enter the PB frequency fp =1500
Enter the SB frequency fs =2500
Enter the sampling frequency f =9000
Enter the beeta value =5
b= 5

MAGNITUDE RESPONSE OF HPF


20

Gain in db--------.

Gain in db--------.

MAGNITUDE RESPONSE OF LPF


50
0
-50
-100

Gain in db--------.

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BPF
20

Gain in db--------.

0
-20
-40
-60

0.5
Normalized freqency------>

0
-20
-40
-60

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BSF
50
0

-50
-100

0.5
Normalized freqency------>

RESULT:
Thus a program to design the FIR lowpass, highpass, bandpass and band stop
Filters using Kaiser Window was written and response of the filter using Matlab was
executed.
DESIGN OF FIR FILTERS (WINDOW DESIGN)
AIM:
To write a program to design the FIR lowpass, Highpass, Bandpass and Band stop filters
using TRIANGULAR window and find out the response of the filter by using MATLAB.
ALGORITHM:
1. Start the program.
2. Get the input sequence for pass band ripple, stop band ripple, pass band
Frequency and stop band frequency and sampling frequency.
3. Convert the frequency into radians/sec.
4. Compute the order and cut off frequency of the filter and display it.
5. Design the analog filter and find the Triangular window coefficient.
6. Find out the frequency response of the filter.
8. Compute the magnitude and phase response of the filter.
9. Repeat the process for highpass, bandpass and band stop filters.
10. Execute the program, display the result and verify it.
11. Plot the output graph for each sequence for lowpass and Highpass filters.
12. Stop the process.
PROGRAM:
%PROGRAM TO DESIGN A FIR DIGITAL FILTER USING TRIANGULAR WINDOW
clc;
close all;
clear all;
rp=input('Enter the PB ripple rp =');

rs=input('Enter the SB ripple rs =');


fp=input('Enter the PB frequency fp =');
fs=input('Enter the SB frequency fs =');
f=input('Enter the sampling frequency f =');
wp=2*fp/f;
ws=2*fs/f;
num=-20*log10(sqrt(rp*rs))-13;
den=14.6*(fs-fp)/f;
n=ceil(num/den);
n1=n+1;
if(rem(n,2)~=0)
n=n1;
n=n-1;
end;
y=bartlett(n1);
%LPF
b=fir1(n,wp,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF LPF');
%HPF
b=fir1(n,wp,'high',y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,2);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF HPF');
%BPF
wn=[wp ws];
b=fir1(n,wn,y);
[h,O]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,3);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BPF');
%BSF
b=fir1(n,wn,'stop',y);
[h,O]=freqz(b,1,256);

m=20*log10(abs(h));
subplot(2,2,4);
plot(O/pi,m);
xlabel('Normalized frequency------>');
ylabel('Gain in db--------.');
title('MAGNITUDE RESPONSE OF BSF');
OUTPUT

-10
-20
-30
-40

G ain in d b--------.

G a in in db --------.

MAGNITUDE RESPONSE OF LPF


0

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BPF
20
0

-20
-40

0.5
Normalized freqency------>

MAGNITUDE RESPONSE OF HPF


10
0
-10
-20
-30

G a in in db --------.

G ain in d b--------.

Enter the PB ripple rp =.04


Enter the SB ripple rs =.02
Enter the PB frequency fp =1500
Enter the SB frequency fs =2000
Enter the sampling frequency f =8000

0.5
1
Normalized freqency------>
MAGNITUDE RESPONSE OF BSF
5
0

-5
-10

0.5
Normalized freqency------>

RESULT:
Thus a program to design the FIR lowpass, highpass, bandpass and band stop
Filters using Triangular Window was written and response of the filter using Matlab
was executed.

GENERATE SINE, COSINE, UNIT


PLOT THE
SINE
ANDRAMP
COSINE
IMPULSE,
UNIT
STEP,
AND
STOP
SIGNALS
(t, y) . DATA
EXPONENTIAL
SIGNALS
GET
THE REQUIRED
INPUT

EXPT NO: 5
EXPT NO: 5(a)

DESIGN OF BUTTERWORTH IIR FILTERS


DESIGN OF BUTTERWORTH IIR FILTER USING IMPULSE
INVARIANT TRANSFORMATION

DATE :
AIM:

To write a program to design the IIR BUTTERWORTH Low Pass Filter using Impulse
Invariant Transformation method and find out the Magnitude response and Pole Zero Plot by
using MATLAB.
ALGORITHM:
1. Start the program.
2. Get the order of the filter value N.
3. Choose the frequency fs, fc and wc = 2 * pi * fc.
4. Calculate the Gain by using the formula Gain = 20 * log (abs (h)).
5. Plot the Magnitude response by using filter co-efficient values.
6. Plot the Ploe-Zero plots by using roots (n, d) from Z-plane.
7. Stop the process.
PROGRAM
%TO DESIGN A DIGITAL IIR BUTTERWORTH LPF
%USING IMPULSE INARIANT TRANSFORMATION
N=input('ENTER THE FILTER ORDER N = ');
fs=input('ENTER THE SAMPLING FREQUENCY fs = ');
fc=input('ENTER THE CUT-OFF FREQUENCY fc = ');
wc=2*pi*fc;
[na,da]=butter(N,wc,'s');
[n,d]=impinvar(na,da,fs);
[h,f]=freqz(n,d,512,fs);
gain=20*log10(abs(h));
subplot(2,1,1);
plot(f,gain);
xlabel('Frequency---->');
ylabel('Magnitude---->');
title('AMPLITUDE RESPONSSE');
subplot(2,1,2);
zplane(n,d);
z=roots(n);
p=roots(d);
xlabel('Real part---->');
ylabel('Imaginary part---->');
title('POLE-ZERO PLOT');
OUTPUT
ENTER THE FILTER ORDER N = 2
ENTER THE SAMPLING FREQUENCY fs = 1280
ENTER THE CUT-OFF FREQUENCY fc = 150

M a g n it u d e - -- - >

-5
-10
-15
-20

I m a g in a r y p a r t - -- - >

AMPLITUDE RESPONSSE

100

200

300
400
Frequency---->
POLE-ZERO PLOT

500

600

700

1
0.5
0
-0.5
-1

-3

-2

-1

0
Real part---->

RESULT:

Thus a program to design the IIR BUTTERWORTH Low Pass Filter using
Impulse Invariant Transformation method and find out the Magnitude response and Pole
Zero Plot by using MATLAB was executed.
EXP.NO:5(b)DESIGN OF IIR FILTERS(BILINEAR TRANSFORMATION)
AIM:
To write a program to design the IIR BUTTERWORTH Band Pass Filter using Bilinear
Transformation method and find out the Magnitude response and Pole Zero Plot by using
MATLAB.
ALGORITHM:
1. Start the program.
2. Obtain the Pass Band and stop Band frequency.
3. Obtain the Pass Band and stop Band Ripple.
4. Obtain the Sampling frequency.
5. Calculate the Gain by using the formula Gain = 20 * log(abs(h)).
6. Obtain the filter co-efficient.
7. Plot the Magnitude response by using filter co-efficient values.
8. Plot the Ploe-Zero plots.
9. Stop the process.
PROGRAM
%TO DESIGN A DIGITAL IIR BUTTERWORTH BPF
%USING BILINEAR TRANSFORMATION
wp=input('ENTER THE PASSBAND EDGE FREQUENCIES wp= ');
ws=input('ENTER THE STOPBAND EDGE FREQUENCIES ws= ');
rp=input('ENTER THE PASSBAND RIPPLE rp= ');
rs=input('ENTER THE STOPBAND RIPPLE rs= ');
fs=input('ENTER THE SAMPLING FREQUENCY fs= ');
wpn=wp/(fs/2);

wsn=ws/(fs/2);
[N,fc]=buttord(wpn,wsn,rp,rs);
disp('ORDER OF THE FILTER');
disp(N);
[n,d]=butter(N,wpn);
[h,f]=freqz(n,d,512,fs);
gain=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(f,gain);
xlabel('FREQUENCY---->');
ylabel('MAGNITUDE');
title('AMPLITUDE RESPONSE');
subplot(2,1,2);
zplane(n,d);
z=roots(n);
p=roots(d);
xlabel('RREAL PART---->');
ylabel('IMAGINARY PART');
title('POLE-ZERO PLOT');

M A G N IT U D E

OUTPUT
ENTER THE PASSBAND EDGE FREQUENCIES wp= [200 300]
ENTER THE STOPBAND EDGE FREQUENCIES ws= [50 450]
ENTER THE PASSBAND RIPPLE rp= 3
ENTER THE STOPBAND RIPPLE rs= 20
ENTER THE SAMPLING FREQUENCY fs= 1000
ORDER OF THE FILTER
2
AMPLITUDE RESPONSE

0
-50
-100

IM A G IN A R Y P A R T

-150

50

100

150

200
250
300
FREQUENCY---->
POLE-ZERO PLOT

350

400

450

500

1
0.5
2

-0.5
-1

-3

-2

-1

0
1
RREAL PART---->

RESULT:

Thus a program to design IIR BUTTERWORTH Band Pass Filter using


Bilinear Transformation method and find out the Magnitude response and Pole Zero Plot
by using MATLABwas executed.

EXPT NO.5(c)
DATE :

DESIGN OF BUTTERWORTH IIR FILTER

AIM:
To design a Butterworth digital IIR filter using MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using
log [10 kp 1 / 10 kp 1]
N = ------------------------------------log s / p
5.Find the filter co-efficient.
6.Draw the magnitude and phase response.
PROGRAM:
clear all;
clc;
close all;
format long
rp=input(enter the pass band ripple);
rs=input(enter the stop band ripple);
wp=input(enter the pass band frequency );
ws=input(enter the stop band frequency );
fs=input(enter the sampling frequency );
w1=2*wp/fs;
w2=2*ws/fs;
%LOW PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs];
[b,a]=butter(n,wn);
%[b,a]=zp2tf(z,p,k);
[b,a]= butter(n,wn);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
%figure(1);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
%figure(1);
Subplot(2,1,2);

Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
%HIGH PASS FILTER
[n,wn]=buttord(w1,w2,rp,rs];
[b,a]=butter(n,wn,high);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(2);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
figure(2);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
%BAND PASS FILTER
[n]=buttord(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=butter(n,wn,band pass);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(3);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
figure(3);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
%BAND STOP FILTER
[n]=buttord(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=butter(n,wn,band stop);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));

an=angle(h);
figure(4);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
figure(4);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
Sample Input :
Enter the pass band ripple: 0.5
Enter the stop band ripple: 50
Enter the pass band freq: 1200
Enter the stop band freq: 2400
Enter the sampling freq: 10000
OUTPUT

RESULT:
Thus a program to design the Chebyshev IIR lowpass, highpass, bandpass and
band stop Filters was written and response of the filter using Matlab was executed.

EXPT NO.5(d)
DATE :

DESIGN OF CHEBYSHEV DIGITAL IIR FILTER

AIM:
To design a digital IIR filter using Chebyshev filter with MATLAB 7.0.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM:
1. Get the pass band and stop band ripples.
2. Get the pass band and stop band frequencies.
3. Get the sampling frequency.
4. Calculate the order of the filter using
log [10 kp 1 / 10 kp 1]
N = ------------------------------------log s / p
5.Find the filter co-efficient.
6.Draw the magnitude and phase response.
PROGRAM:
clear all;
clc;
close all;
rp=input(enter the pass band ripple);
rs=input(enter the stop band ripple);
wp=input(enter the pass band frequency );
ws=input(enter the stop band frequency );
fs=input(enter the sampling frequency );
w1=2*wp/fs;
w2=2*ws/fs;
%LOW PASS FILTER
[n,wn]=cheb ord(w1,w2,rp,rs];
[b,a]=cheby 1(n,wn);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
%HIGH PASS FILTER
[n,wn]= cheb1 ord(w1,w2,rp,rs];

[b,a]=cheby 1(n,rp,wn,high);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(2);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
figure(2);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
%BAND PASS FILTER
[n]=cheb1 ord(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=cheby 1(n,rs,wn,band pass);
W=0:0.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(3);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);
Xlabel((a)normalized frequency>);
figure(3);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
%BAND STOP FILTER
[n]=cheb 1 ord(w1,w2,rp,rs];
Wn=[w1,w2];
[b,a]=cheby 1(n,rp,wn,band stop);
W=0:0.1/pi:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(4);
Subplot(2,1,1);
Plot(om/pi,m);
Ylabel(gain in db>);

Xlabel((a)normalized frequency>);
figure(4);
Subplot(2,1,2);
Plot(om/pi,an);
Xlabel((b)normalized frequency>);
Ylabel(phase in radians>);
Sample Input :
Enter the pass band ripple:0.35
Enter the stop band ripple:35
Enter the pass band frequency:1500
Enter the stop band frequency:2000
Enter the sampling frequency:8000
OUTPUT

RESULT:
Thus a program to design the Chebyshev IIR lowpass, highpass, bandpass and
band stop Filters was written and response of the filter using Matlab was executed.

EXPT NO.(6)FINDING FAST FOURIER TRANSFORM


DATE :
AIM:
To write a program to find out the Fast Fourier Transform and Inverse Fast Fourier
Transform of the sequence using Matlab and display the magnitude and phase spectrum.
ALGORITHM:
1. Start the program.
2. Get the two input sequence x (n) and type of the FFT.
3. Compute the Fast Fourier transform (FFT) of the given sequence.
4. Find out the magnitude and phase response of the given sequence.
5. Execute the program, display the result and verify it.
6. Plot the output graph for magnitude and phase.
7. Compute the inverse Fast Fourier Transform (FFT) of the given
sequences.
8. Display the results verify it and plot the result.
9. Stop the process.
PROGRAM:
%COMPUTATION OF DFT USING FFT
clc;
clear all;
close all;
x=input('ENTER THE INPUT SEQUENCE x(n) = ');
y=fft(x);
y1=real(y);
y2=imag(y);
subplot(3,1,1);
stem(y1);
xlabel('n----->');
ylabel('REAL PART');
title('Magnitude plot');
grid on;
subplot(3,1,2);
stem(y2);
xlabel('n----->');
ylabel('IMAG PART');
title('Phase plot');
grid on;
subplot(3,1,3);
stem(y);
grid on;
xlabel('REAL PART');
ylabel('IMAG PART');

title('FAST FOURIER TRANSFORM');


disp('y1 =');
disp(y1);
disp('y2 =');
disp(y2);
disp('y=');
disp(y);
OUTPUT
ENTER THE INPUT SEQUENCE x (n) = [0 1 2 3 4 5 6 7]
y1 =
28 -4 -4 -4 -4 -4 -4 -4
y2 =
0

9.6569

4.0000

1.6569

0 -1.6569 -4.0000 -9.6569

y=
Columns 1 through 4
28.0000

-4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i

Columns 5 through 8
-4.0000
>>

-4.0000 - 1.6569i -4.0000 - 4.0000i -4.0000 - 9.6569i

REAL PART
IMAG PART
IMAG PART

Magnitude plot

50
0
-50

5
6
n----->
FAST FOURIER TRANSFORM

4
5
REAL PART

10

5
n----->
Phase plot

0
-10

10
0
-10

RESULT:
Thus a program to find out the Fast Fourier Transform (FFT) of the sequence using
MatLab was written and executed.

EXPT NO.(7)
DECIMATION BY POLYPHASE DECOMPOSITION
DATE :
AIM:
To write a MATLAB program to decimate the signal using Polyphase decomposition.
APPARATUS REQUIRED:
System with MATLAB 7.0.
ALGORITHM :
1. Start the program.
2. Generate the input signal and decimate the input signal using Polyphase
decomposition.
3. Execute the program.
4. Plot the output.
5. Stop the process.
PROGRAM :
%analog signal
t=-0.005:0.00005:0.005;
xa=exp(-1000*abs(t));
%discrete time signal
fs=input('enter the sampling frequency(fs)= ');
ts=1/fs;
n=-25:1:25;
xn=exp(-1000*abs(n*ts));
%discrete time fourier transform
N=500;
k=0:1:N;
w=(2*pi*k/N);
X=xn*exp(-1j*n'*w);
x=abs(X);
%omega range from -wmax to wmax
w=[-fliplr(w),w(2:N+1)];
%x over -wmax to wmax interval
x=[fliplr(x),x(2:N+1)];
subplot(1,1,1);
plot(t*1000,xa>'k');
grid;
hold on;
stem(n*ts*1000,xn,'k');
xlabel('time in sec');
ylabel('time in sec');
ylabel('x(n)');
title('discrete time signal');
gtext('ts.1msec');
hold off
SAMPLE INPUT :
Enter the sampling frequency(fs) = 1000

OUTPUT :
discrete time signal

1
0.9
0.8
0.7

x(n)

0.6
0.5
0.4
0.3
0.2
0.1
0
-25

-20

-15

-10

-5

0
5
time in sec

10

15

20

25

RESULT:
Thus a program to decimate the input signal using Polyphase decomposition
method was written and response using Matlab was executed.

EXPT NO.(9)
DATE :

GENERATION OF SIGNALS USING TMS320C5416 PROCESSOR

AIM :
To write an Assembly Language program to generate the basic signals using
TMS320C5416 Processor kit.
APPARATUS REQUIRED:
TMS320C5416 DSP Processor kit
CC studio version_3.1
PROCEDURE:

PROGRAM
Sine Generation
.mmregs
.text
stm #1200h,ar1
stm data,ar4
stm #03h,ar6
loop:
stm data,ar4
stm #15,ar3
loop1: ld *ar4+,a
stl a,*ar1+
banz loop1,*ar3stm #15,ar3

loop2: ld *ar4+,a
stl a,*ar1+
banz loop2,*ar3banz loop,*ar6nop
nop
.end
data.word 0,207,406,587,743,866,951,994,1000
.word 994,951,866,743,587,406,207,0
.word -207,-406,-587,-743,-866,-951,-994,-1000
.word -994,-951,-866,-743,-587,-406,-207
Sawtooth Generation
.mmregs
.text
stm #1200h,ar1
stm #5h,ar7
loop:
stm #0fh,ar4
ld #0h,b
loop1: stl b,*ar1+
add #1h,b
banz loop1,*ar4nop
nop
nop
banz loop,*ar7nop
nop
nop
.end
Sinewave Generation
.mmregs
.text
stm data,ar3
stm #1500h,ar1
stm #10,ar6
ld #0h,a
loop:
stm data,ar1
mar *+ar3(5)
banz loop,*ar6nop
nop

.data
data .word 20252,38521,53020,62328,65536,62328,53020,38521,20252,00000
.mmregs
.text
stm #1200h,ar1
stm #5h,ar7
loop:
stm #0fh,ar4
ld #0h,b
loop1: stl b,*ar1+
add #1h,b
banz loop1,*ar4banz loop,*ar7nop
nop
.end

Square Wave Generation


.mmregs
.text
stm #1200h,ar1
stm #3h,ar6
ld #0h,b
loop:
stm #5h,ar5
loop1: stl b,*ar1+
nop
banz loop1,*ar5stm #5h,ar5
neg b
loop2: stl b,*ar1+
nop
banz loop2,*ar5banz loop,*ar6nop
nop
.end
Triangular Wave Generation
.mmregs
.text
stm #2200h,ar1
stm #3h,ar6

loop:
stm #0fh,ar5
ld #0h,b
loop1: stl b,*ar1+
add #1h,b
banz loop1,*ar5stm #0fh,ar5
loop2: sub #1h,b
stl b,*ar1+
banz loop2,*ar5banz loop,*ar6nop
nop
nop
.end
OUTPUT :

RESULT :
Thus the Assembly Language program was written to generate basic signals using the
TMS320C5416 Processor kit was performed and executed.
EXPT NO.(10)

LINEAR AND CIRCULAR CONVOLUTION USING TMS320C5416

PROCESSOR
DATE :
AIM :
To write an Assembly Language program to perform Convolution using TMS320C5416
Processor kit.
APPARATUS REQUIRED:
TMS320C5416 DSP Processor kit
CC studio version_3.1
PROCEDURE:

PROGRAM :
Linear Convolution
.mmregs
.text
stm data1+3,ar3
stm data2,ar4
stm #1500h,ar1
stm #5h,ar6
loop1:
ld #0h,a
stm #3h,ar5
loop2:
mpy *ar3-,*ar4+,b
add b,a

banz loop2,*ar5stl a,*ar1+


stm data2,ar4
mar *+ar3(5)
banz loop1,*ar6nop
nop
.data
data2 .word 1,3,4,5,0,0
data1 .word 0,0,0,2,1,3,0,0,0

Circular Convolution
.mmregs
.text
stm data1+3,ar3
stm #1400h,ar2
stm #2h,ar4
loop1:
ld #0h,b
rpt #2h
macp *ar3-,data2,b
stl b,*ar2+
mar *+ar3(4)
banz loop1,*ar4data2 .word 1,3,4
.data
data1 .word 2,1,3,2,1,3

RESULT :
Thus the Assembly Language program was written to perform convolution using the
TMS320C5416 Processor kit was performed and executed.

EXPT NO.(11)

SAMPLING OF SIGNALS USING TMS320C5416

PROCESSOR
DATE :
AIM :
To write an C program to perform Sampling using TMS320C5416 Processor kit.
APPARATUS REQUIRED:
TMS320C5416 DSP Processor kit
CC studio version_3.1
PROCEDURE:
1.Connect a Signal Generatorinput to the LINE IN socket .
2.Switch on the DSK and bring up Code Composer studio on the PC.
3. Use the Debug -> Connect option to open a debug connection to the DSK board.
4.Create a new project .
5.Open the File Menu -> new -> DSP/BIOS Configuration -> select dsk5416.cdb and save the
file with extension .cdb.
6. Open the File Menu -> new -> source file -> type program and save with .C extension.
7.Add the source file to the project.
8.Add configuration file to project.
9.Add following file to the project. Go to Add files to project -> CCStudio -> C5400 ->
dsk5416.
10.Add library files to project.Add files to project -> lib -> dsk5416 ->open.
11.In the generated file, copy header file and paste in header file of source file.
12.Compile the project and view the output.
PROGRAM :

Decimation
#include<stdio.h>
#include<math.h>
#define FREQ 100
#define sample 500 /* sine samples*/
#define downsample 125 /* downsample by 4 means 500/4 */
#define D 4 /* decimation by 4 */
float h[405]={-0.0012,-0.0021,-0.0021,0.0000,0.0048,0.0099,0.0100,-0.0000,-0.0190,-0.0363,0.0348,0.0000, 0.0686 , 0.1533 , 0.2235 , 0.2507,
0.2235, 0.1533, 0.0686 , 0.0000 , -0.0348, -0.0363, -0.0190 , -0.0000,
0.0100, 0.0099, 0.0048 , 0.0000 , -0.0021 , -0.0021, -0.0012};
float m[sample],n[downsample],p[sample],t[405]=0,y[405];
main()
{
int i=0,k=0,s=0,r=0,d=0,j=0;
//input signal

for(i=0;i<=sample;i++)
{
m[i]=sin(2*3.14*FREQ*i/8000);//calculating sine samples
// printf("\n%f\n",m[i]);
}
//low pass filtering
for(i=31;i<=405;i++)
{
h[i]=0;
}
/*convolution*/
for(r=0;r<405;r++)
{
y[r]=0;
for(d=0;d<=r;d++)
y[r]+=m[d] * h[r-d];
}
/* for down sample by 4 ie decimation by 4*/
for(k=0,i=0,s=0;k<=downsample-1,i<=sample-1,s<=sample-1;k++,i=i+D,s=s+D)
{
n[k]=y[i];
/*for ploatting purpose holding the samples*/
p[s]=n[k];
p[s+1]=n[k];
p[s+2]=n[k];
p[s+3]=n[k];
//p[s+4]=n[k];
//printf("\n%f,%d,%d\n",n[k],i,k);
}
}

Interpolation

#include<stdio.h>
#include<math.h>
#define FREQ 10
#define sample 48 /* sine samples*/
float m[sample],n[];
main()
{
int i=0,k=0,s=0,r=0,d=0,j=0;
for(i=0;i<=sample;i++)
{
m[i]=sin(2*3.14*FREQ*i/100);//calculating sine samples
// printf("\n%f\n",m[i]);
}
for(i=0,k=0;i<30,k<96;i++,k=k+2)
{
n[k]=m[i];
n[k+1]=0;
}
}

RESULT :
Thus the C program was written to perform Sampling using the TMS320C5416 Processor
kit was performed and executed.

EXPT NO.(12)
DATE :

DESIGN OF FIR FILTER USING TMS320C5416 PROCESSOR

AIM :
To write a C program to design a FIR fiter using TMS320C5416 Processor kit.
APPARATUS REQUIRED:
TMS320C5416 DSP Processor kit
CC studio version_3.1
PROCEDURE:

PROGRAM :

FIR Filter
#include "fircfg.h"
#include "C:\CCStudio_v3.1\C5400\dsk5416\include\dsk5416.h"
#include "C:\CCStudio_v3.1\C5400\dsk5416\include\dsk5416_pcm3002.h"
Int16 left_input;
Int16 left_output;
Int16 right_input;
Int16 right_output;
static short in_buffer[100];
float filter_Coeff[] ={-0.000019,-0.000170,-0.000609,-0.001451,-0.002593,-0.003511,0.003150,0.000000,0.007551,0.020655,
0.039383,0.062306,0.086494,0.108031,0.122944,0.128279,0.122944,0.108031,0.086494,0.0623
06,

0.039383,0.020655,0.007551,0.000000,-0.003150,-0.003511,-0.002593,-0.001451,-0.000609,0.000170,
-0.000019};
/*Select particular set of co-efficients different Cut-off frequencies from given Tables */
DSK5416_PCM3002_Config setup = {
0x1ff,
0x1ff,
0x000,
0x000

// Set-Up Reg 0 - Left channel DAC attenuation


// Set-Up Reg 1 - Right channel DAC attenuation
// Set-Up Reg 2 - Various ctl e.g. power-down modes
// Set-Up Reg 3 - Codec data format control

};

void main ()
{
DSK5416_PCM3002_CodecHandle hCodec;
// Initialize the board support library
DSK5416_init();
// Start the codec
hCodec = DSK5416_PCM3002_openCodec(0, &setup);
// Set codec frequency
DSK5416_PCM3002_setFreq(hCodec,8000);
// Endless loop IO audio codec
while(1)
{
// Read 16 bits of codec data, loop to retry if data port is busy
while(!DSK5416_PCM3002_read16(hCodec, &left_input));
while(!DSK5416_PCM3002_read16(hCodec, &right_input));
left_output=FIR_FILTER(&filter_Coeff ,left_input);
right_output=left_output;
// Write 16 bits to the codec, loop to retry if data port is busy
while(!DSK5416_PCM3002_write16(hCodec, left_output));
while(!DSK5416_PCM3002_write16(hCodec, left_output));
}
}
signed int FIR_FILTER(float * h, signed int x)
{
int i=0;
signed long output=0;

in_buffer[0] = x; /* new input at buffer[0] */


for(i=30;i>0;i--)
in_buffer[i] = in_buffer[i-1]; /* shuffle the buffer */
for(i=0;i<31;i++)
output = output + h[i] * in_buffer[i];
return(output);
}

RESULT :
Thus the C program was written to design the FIR filetr using the TMS320C5416
Processor kit was performed and executed.

S-ar putea să vă placă și