0% found this document useful (0 votes)
45 views107 pages

Digital Signal Processing Lab Manual MS

DSP Lab Manual
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views107 pages

Digital Signal Processing Lab Manual MS

DSP Lab Manual
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

Dr. Biju V.G.

Digital Signal Processing Lab Manual

COLLEGE OF ENGINEERING MUNNAR-685612

Department of Electronics & Communication

LABORATORY RECORD

Month & Year..........................................


.
.G
.V

Name......................................................
r.B

Roll Number.................................................
D

Branch..........................................................
University Reg. No...........................................

Certified that this is a Bonafide record of the work done by


Mr/Ms............................................................................................
in the ECL 333 Digital Signal Processing Laboratory

Staff in Charge HoD

Internal Examiner External Examiner

1
Contents

0.1 FAMILIARIZATION OF MATLAB BASIC TOOL


BOX FUNCTION. . . . . . . . . . . . . . . . . 3
0.2 FAMILIARIZATION OF DSP TOOL BOX FUNC-
TION. . . . . . . . . . . . . . . . . . . . . . . 15
0.3 MATLAB PROGRAM TO PERFOM ARITHMETIC
OPERATION . . . . . . . . . . . . . . . . . . 20
0.4 GENERATION OF BASIC SIGNALS USING MAT-
LAB . . . . . . . . . . . . . . . . . . . . . . . 24
0.5 COMPUTATION OF LINEAR CONVOLUTION. 31
.
.G

0.6 COMPUTATION OF CIRCULAR CONVOLUTION. 37


.V
r.B

0.7 COMPUTATION OF LINEAR CONVOLUTION


D

USING CIRCULAR CONVOLUTION. . . . . . . 42


0.8 COMPUTATION OF DFT . . . . . . . . . . . . 48
0.9 COMPUTATION OF IDFT . . . . . . . . . . . 53
0.10 COMPUTATION OF CONVOLUTION USING DFT 58
0.11 IMPLEMENTATION OF IIR LOW PASS, HIGH PASS,
BAND PASS, BAND REJECT FILTER . . . . . 65
0.12 IMPLEMENTATION OF FIR LOW AND HIGH
PASS FILTER WITH AND WITHOUT USING WIN-
DOW . . . . . . . . . . . . . . . . . . . . . . 84
0.13 COMPUTATION OF BLOCK CONVOLUTION US-
ING OVERLAP SAVE METHOD . . . . . . . . 94
0.14 COMPUTATION OF BLOCK CONVOLUTION US-
ING OVERLAP ADD METHOD . . . . . . . . . 101

2
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.1 FAMILIARIZATION OF MATLAB BASIC TOOL BOX FUNC-


TION.

Cycle:-1
Experiment No:-1 Date:———————–
1. AIM : To familiarize matlab tool box basic funtion
2. OBJECTIVES:
(a) To study the basic matlab tool box function from the
command promt.
MATLAB
• MATLAB is a software package for high performance
numerical computation and visualization provides an in-
teractive environment with hundreds of built in func-
tions for technical computation, graphics and anima-
.
.G

tion.
.V
r.B

• The MATLAB name stands for MATrixLABoratory.


D

• The diagram shows the main features and capabilities


of MATLAB At its core, MATLAB is essentially a set (a
”toolbox¨) of routines (called m files or mex files) that
sit on your computer and a window that allows you to
create new variables with names (e.g. voltage and time)
and process those variables with any of those routines
(e.g. plot voltage against time, find the largest voltage,
etc.)
• M AT LAB is a high-level language and interactive en-
vironment that enables you to perform computationally
intensive tasks faster than with traditional programming
languages such as C, C++, and Fortran.

3
Dr. Biju V.G. Digital Signal Processing Lab Manual

.
.G
.V
r.B
D

4
Dr. Biju V.G. Digital Signal Processing Lab Manual

• Key Features:
– High-level language for technical computing.
– Development environment for managing code, files,
and data.
– Interactive tools for iterative exploration, design, and
problem solving.
– Mathematical functions for linear algebra, statistics,
Fourier analysis,
– Filtering, optimization, and numerical integration.
– 2-D and 3-D graphics functions for visualizing data.
– Tools for building custom graphical user interfaces.
– Functions for integrating MATLAB based algorithms
with external applications and languages, such as C,
.
.G

C++, Fortran, Java, COM, and Microsoft Excel.


.V
r.B

• MATLAB Windows:- MATLAB works with through three


D

basic windows
– Command Window:- This is the main window .It is
characterized by MATLAB command prompt(>>) when
you launch the application program MATLAB puts
you in this window all commands including those
for userwritten programs ,are typed in this window
at the MATLAB prompt.

5
Dr. Biju V.G. Digital Signal Processing Lab Manual

– Graphics window:- The output of all graphics com-


mands typed in the command window are flushed to
the graphics or figure window, a separate gray win-
dow with white background color the user can create
as many windows as the system memory will allow.
– Edit window:- This is where you write edit, create and
save your own programs in files called M files.
– Input-output:- MATLAB supports interactive compu-
tation taking the input from the screen and flushing
the output to the screen. In addition it can read input
files and write output files.
– Data Type:- The fundamental data-type in MATLAB
is the array. It encompasses several distinct data
objects- integers, real numbers, matrices. Charac-
ter strings, structures and cells. There is no need to
.
.G

declare variables as real or complex, MATLAB auto-


.V
r.B

matically sets the variable to be real.


D

– Dimensioning:- Dimensioning is automatic in MAT-


LAB. No dimension statements are required for vec-
tors or arrays. We can find the dimensions of an
existing matrix or a vector with the size and length
commands.

6
Dr. Biju V.G. Digital Signal Processing Lab Manual

Basic Instructions & functions in Matlab

1. T = 0:1:10

This instruction indicates a vector T which as initial value


0 and final value 10 with an increment of 1.Therefore,
T =0 1 2 3 4 5 6 7 8 9 10
2. linspace():-

Linearly spaced vector.


linspace(X1, X2) generates a row vector of 100 linearly
equally spaced points between X1 and X2.

linspace(X1, X2, N) generates N points between X1 and


X2. For N = 1, linspace returns X2.
.
.G
.V

3. T= zeros (2, 3)
r.B
D

The above instruction creates a vector of two rows and


three columns whose values are zero.

T=
000
000

7
Dr. Biju V.G. Digital Signal Processing Lab Manual

4. T=ones (3,2)
The above instruction creates a vector of three rows and
two columns whose values are one.

T=
11
11
11

5. a = [1 2 3] b = [4 5 6]

a.*b= [4 10 18], which is the result of individual elements.


6. Concatenation:

Concatenation is the process of joining arrays to make


.

larger ones. In fact, you made your first array by con-


.G
.V

catenating its individual elements. The pair of square


r.B

brackets A = [a, a] & A = [a; a] are concatenation opera-


D

tion.
7. plot(t,m):-

This function will display a figure window which indi-


cates the continuous plot of m versus t.
8. stem(t,m)

This function will display a figure window which indi-


cates the discrete plot of m versus t.

8
Dr. Biju V.G. Digital Signal Processing Lab Manual

9. subplot():-

This function divides the figure window into rows and


Columns.
Example: subplot(3,1,2)—–3-rows, 1-column, 2-location.
10. title(’text’) :- Graph title.

adds text at the top of the current axis.


11. xlabel X-axis label.

xlabel(’text’) adds text beside the X-axis on the current


axis.
12. ylabel Y-axis label.

ylabel(’text’) adds text beside the Y-axis on the current


axis.
.
.G
.V

13. grid Grid lines.


r.B
D

grid ON adds major grid lines to the current axes.


grid OFF removes major and minor grid lines from the
current axes.
grid MINOR toggles the minor grid lines of the current
axes.
grid, by itself, toggles the major grid lines of the current
axes.
grid(AX,...) uses axes AX instead of the current axes.

14. clc :-

Clear command window


clc clears the command window and homes the cursor.

9
Dr. Biju V.G. Digital Signal Processing Lab Manual

15. clear:-

clear variables and functions from memory.


clear removes all variables from the workspace.
clear all removes all variables, globals and functions .
16. Close figure.

close all closes all the open figure windows.


17. who:-

who List current variables. who lists the variables in the


current workspace.
18. whos:-

whos is a long form of WHO. It lists all the variables in


the current workspace, together with information about
.
.G

their size, bytes, class, etc.


.V
r.B

19. pwd :-
D

pwd displays the current working directory.


20. round()

round towards nearest integer.


round(X) rounds the elements of X to the nearest inte-
gers.

10
Dr. Biju V.G. Digital Signal Processing Lab Manual

21. ceil() :-

ceil, Round towards plus infinity.


ceil(X) rounds the elements of X to the nearest integers
towards infinity.
22. floor():-

floor, Round towards minus infinity.


floor(X) rounds the elements of X to the nearest integers
towards minus infinity.
23. fix():-

fix, Round towards zero.


fix(X) rounds the elements of X to the nearest integers
towards zero.
24. size():-
.
.G
.V
r.B

Size of array.
D

D = size(X), for M-by-N matrix X, returns the two-element


row vector.
D = [M,N] containing the number of rows and columns
in the matrix.
For N-D arrays, size(X) returns a 1-by-N vector of dimen-
sion lengths.

11
Dr. Biju V.G. Digital Signal Processing Lab Manual

25. length() :-

Length of vector.
length(X) returns the length of vector X.
It is equivalent to MAX(SIZE(X)) for non-empty arrays
and 0 for empty ones.
26. abs():-

Absolute value.
abs(X) is the absolute value of the elements of X.
When X is complex, abs(X) is the complex modulus (mag-
nitude) of the elements of X.
27. angle ():-

Phase angle.
.

angle(H) returns the phase angles, in radians, of a ma-


.G
.V

trix with complex elements.


r.B

28. disp():-
D

Display array.
disp(X) displays the array, without printing the array name.
29. min():-

Smallest component.
For vectors, min(X) is the smallest element in X.
For matrices, min(X) is a row vector containing the min-
imum element from each column.

12
Dr. Biju V.G. Digital Signal Processing Lab Manual

30. max():-

Largest component.
For vectors, max(X) is the largest element in X.
For matrices, max(X) is a row vector containing the max-
imum element from each column.
31. mod ():-

Modulus after division.


32. exp():-

Exponential.
exp(X) is the exponential of the elements of X, e to the
X.
33. input():-
.
.G

Prompt for user input.


.V
r.B

NUM = input(PROMPT) displays the PROMPT string on


D

the screen, waits for input from the keyboard, evaluates


any expressions in the input, and returns the value in
NUM.
To evaluate expressions, input accesses variables in the
current workspace.
If you press the return key without entering anything,
input returns an empty matrix.

13
Dr. Biju V.G. Digital Signal Processing Lab Manual

34. printsys():-

Print system in pretty format.


printsys is used to print state space systems with labels
to the right and above the system matrices or to print
transfer functions as a ratio of two polynomials.

Result:- Familiarized Matlab tool box basic function

Signature of the Staff in charge:- ——————————–


.
.G
.V

Output verification date:—————————————-


r.B
D

14
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.2 FAMILIARIZATION OF DSP TOOL BOX FUNCTION.

Cycle:-1
Experiment No:-2 Date:———————–
1. AIM : To familiarize DSP tool box basic funtion
2. OBJECTIVES:
(a) To study the DSP tool box function from the com-
mand promt.
Basic Instructions & functions in Matlab
• conv():-

Convolution and polynomial multiplication.


C = conv(A, B) convolves vectors A and B.
.
.G

• cconv():-
.V
r.B

Modulo-N circular convolution.


D

C = cconv(A, B, N) circularly convolves vectors A and B.


• fft():-

Discrete Fourier transform.


fft(X) is the discrete Fourier transform (DFT) of vector X.
fft(X,N) is the N-point fft, padded with zeros if X has less
than N points and truncated if it has more.
• ifft():-

Inverse discrete Fourier transform.


ifft(X) is the inverse discrete Fourier transform of X.
ifft(X,N) is the N-point inverse transform.

15
Dr. Biju V.G. Digital Signal Processing Lab Manual

• freqz():-

Frequency response of digital filter.


[H, W ] = freqz(B,A,N) returns the N-point complex fre-
quency response vector H and the N-point frequency
vector W in radians/sample of the filter. A & B numera-
tor and denominator coefficients.
• buttord():-

Butterworth filter order selection.


[N, W n] = buttord(Wp, Ws, Rp, Rs) returns the order N
of the lowest order digital Butterworth filter which has a
passband ripple of no more than Rp dB and a stopband
attenuation of at least Rs dB. Wp and Ws are the pass-
band and stopband edge frequencies, normalized from
0 to 1 (where 1 corresponds to pi radians/sample).
.
.G
.V
r.B

For example,
D

Lowpass: Wp = .1, Ws = .2
Highpass: Wp = .2, Ws = .1
Bandpass: Wp = [.2 .7], Ws = [.1 .8]
Bandstop: Wp = [.1 .8], Ws = [.2 .7]
buttord also returns Wn, the Butterworth natural fre-
quency (or, the ”3 dB frequency”) to use with BUTTER
to achieve the specifications.

16
Dr. Biju V.G. Digital Signal Processing Lab Manual

• butter():-

Butterworth digital and analog filter design.

[B, A]= butter(N,Wn) designs an N th order lowpass dig-


ital Butterworth filter and returns the filter coefficients
in length N+1 vectors B (numerator) and A (denomina-
tor). The coefficients are listed in descending powers of
z. The cutoff frequency Wn must be 0.0 < W n < 1.0,
with 1.0 corresponding to half the sample rate.

If Wn is a two-element vector,
Wn = [W1 W2], butter returns an order 2N bandpass filter
with passband W 1 < W < W 2.
[B, A] = butter(N,Wn,’high’) designs a highpass filter.
[B, A] = butter(N,Wn,’low’) designs a lowpass filter.
.
.G
.V

[B, A] = butter(N,Wn,’stop’) is a bandstop filter if


r.B

W n = [W 1 W 2].
D

• fir1():-

FIR filter design using the window method.

B = fir1(N,Wn) designs an N th order lowpass FIR digi-


tal filter and returns the filter coefficients in length N+1
vector B. The cut-off frequency Wn must be between
0 < W n < 1.0, with 1.0 corresponding to half the sam-
ple rate. The filter B is real and has linear phase. The
normalized gain of the filter at Wn is -6 dB.

17
Dr. Biju V.G. Digital Signal Processing Lab Manual

B = fir1(N,Wn,’high’) designs an N’th order highpass fil-


ter.
B = fir1(N,Wn,’low’) to design a lowpass filter.

If Wn is a two-element vector, Wn = [W1 W2], fir1 returns


an order N bandpass filter with passband W 1 < W <
W 2.
fir1(N,Wn,’bandpass’).
If Wn = [W1 W2],
B = fir1(N,Wn,’stop’) will design a bandstop filter.
• bilinear():-

Bilinear transformation with optional frequency prewarp-


ing.
[Zd, P d, Kd] = bilinear(Z,P,K,Fs) converts the s-domain
.

transfer function specified by Z, P, and K to a z-transform


.G
.V

discrete equivalent obtained from the bilinear transfor-


r.B

mation: where column vectors Z and P specify the ze-


D

ros and poles, scalar K specifies the gain, and Fs is the


sample frequency in Hz.
• impinvar():-

Impulse invariance method for analog to digital filter con-


version.
[BZ, AZ]= impinvar(B,A,Fs) creates a digital filter with
numerator and denominator coefficients BZ and AZ re-
spectively whose impulse response is equal to the im-
pulse response of the analog filter with coefficients B
and A sampled at a frequency of Fs Hertz. The B and A
coefficients will be scaled by 1/Fs.

18
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Studied DSP tool box functions

Signature of the Staff in charge:- ——————————–

Output verification date:—————————————-


.
.G
.V
r.B
D

19
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.3 MATLAB PROGRAM TO PERFOM ARITHMETIC OPER-


ATION

Cycle:-1
Experiment No:-3 Date:———————–
1. AIM : To perform Matrix Multiplication/Subtraction/Addition/Divis
2. OBJECTIVES:
(a) To perform Matrix Multiplication/Subtraction/Addition/Division
using user defined function.
Matlab program to perform Matrix
Multiplication/Subtraction/Addition/Division
• clc;
• close all;
• clear all;
.
.G
.V

• A=input (’Enter First Matrix =’);


r.B
D

• B=input (’Enter second Matrix =’);


• disp (’Inside main program’)
• [C D E F G H]=compute(A,B);
• disp(’Inside main program again’)
• disp(’The Matrix sum is’)
• disp(C)
• disp(’The Matrix difference is’)
• disp(D)
• disp(’The Matrix multiplication output is’)

20
Dr. Biju V.G. Digital Signal Processing Lab Manual

• disp(E)
• disp(’The Matrix element vice multiplication output is’)
• disp(F)
• disp(’The Matrix division output is’)
• disp(G)
• disp(’The Matrix element vice division output is’)
• disp(H)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Function to perform Arithmetic operations
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
• function [C D E F G H]=compute(A,B)
• disp(’Inside function’)
.
.G

• C=A+B;
.V
r.B

• D=A-B;
D

• E=A*B;
• A.*B;
• G=B/A;
• H=A./B;
• disp(’Leaving function’)
• end

21
Dr. Biju V.G. Digital Signal Processing Lab Manual

Input

Enter First Matrix =——————————-

Enter second Matrix =——————————–


Ouputs

The Matrix sum is————————

The Matrix difference is————————


.
.G
.V
r.B
D

The Matrix multiplication output is————————

The Matrix element vice multiplication output is—————–

The Matrix division output is————————

The Matrix element vice division output is————————

22
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to compute matrix addition,


subtraction, multiplication& division and their ouputs veri-
fied.

Signature of the Staff in charge:- ——————————–

Output verification date:—————————————-


.
.G
.V
r.B
D

23
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.4 GENERATION OF BASIC SIGNALS USING MATLAB

Cycle:-1
Experiment No:-4 Date:———————–
1. AIM : To generate basic signals like unit impulse, unit
step, unit ramp signal and Exponential signals.
2. OBJECTIVES:
(a) To generate basic signals like unit impulse, unit step,
unit ramp signal and Exponential signals using Mat-
lab.

Matlab program to generate basic signal waveforms

• clc;
.
.G

• close all;
.V
r.B

• clear all;
D

• a=[zeros(1, 5) 1 zeros(1, 5)]


• b= [zeros(1, 5) ones(1, 6)]
• c=-5:5
• subplot(3,4,1)
• plot(c,a)
• title(’Unit Impulse function’)
• xlabel(’Time axis’)
• ylabel(’Impluse Amplitude’)

24
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(3,4,2)
• stem(c,a)
• title(’ Discrete Unit Impulse function’)
• xlabel(’Time axis’)
• ylabel(’Impluse Amplitude’)
• subplot(3,4,3)
• plot(c,b)
• title(’Unit step function’)
• xlabel(’Time axis’)
• ylabel(’Step Amplitude’)
• subplot(3,4,4)
• stem(c,b)
.
.G

• title(’ Discrete Unit step function’)


.V
r.B

• xlabel(’Time axis’)
D

• ylabel(’Step Amplitude’)
• x=0:0.2:2*pi;
• y=sin(x)
• subplot(3,4,5)
• plot(x,y)
• title(’Sine wave’)
• xlabel(’Time axis’)
• ylabel(’Sine Amplitude’)

25
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(3,4,6)
• stem(x,y)
• title(’ Discrete Sine wave’)
• xlabel(’Time axis’)
• ylabel(’Sine Amplitude’)
• x=0:5;
• subplot(3,4,7)
• plot(x,x)
• title(’Triangular wave’)
• xlabel(’Time axis’)
• ylabel(’Triangular Amplitude’)
• subplot(3,4,8)
.
.G

• stem(x,x)
.V
r.B

• title(’ Discrete Triangular wave’)


D

• xlabel(’Time axis’)
• ylabel(’Triangular Amplitude’)
• x=0:5;
• y=0.5
• z = yx
• subplot(3,4,9)
• plot(x, z)
• title(’Exponential wave’)
• xlabel(’Time axis’)
• ylabel(’Exponential Amplitude’)

26
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(3,4,10)
• stem(x,z)
• title(’ Discrete Exponential wave’)
• xlabel(’Time axis’)
• ylabel(’Exponential Amplitude’)
• x=-10:10;
• y=[ones(1, 5) −1.∗ones(1, 5) ones(1, 6) −1.∗ones(1, 5)]
• subplot(3,4,11)
• plot(x,y)
• title(’Square wave’)
• xlabel(’Time axis’)
• ylabel(’Square wave Amplitude’)
.
.G

• subplot(3,4,12)
.V
r.B

• stem(x,y)
D

• title(’ Discrete Square wave’)


• xlabel(’Time axis’)
• ylabel(’Square Amplitude’)

27
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample Ouputs

.
.G
.V
r.B
D

28
Dr. Biju V.G. Digital Signal Processing Lab Manual

Ouput Diagram

.
.G
.V
r.B
D

29
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to plot the basic signals and


the outputs verified

Signature of the Staff in charge:- ——————————–

Output verification date:—————————————-


.
.G
.V
r.B
D

30
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.5 COMPUTATION OF LINEAR CONVOLUTION.

Cycle:-2
Experiment No:-5 Date:———————–
1. AIM : Matlab program to compute Linear Convolution of
two signals
2. OBJECTIVES:
(a) Matlab program to compute Linear Convolution of
two discrete time signals and verify the result using
DSP tool box function conv().

Matlab program to compute Linear Convolution

• clc;
.
.G

• close all;
.V
r.B

• clear all;
D

• x=input(’Enter the 1st sequence x:’);


• h=input(’Enter the 2nd sequence h:’);
• x1=length(x);
• h1=length(h);
• n1=length(x)+length(h)-1;

31
Dr. Biju V.G. Digital Signal Processing Lab Manual

• f or n = 1 : n1
• sum(n)=0;
• f or k = 1 : x1
• m = n + 1 − k;
• if m <= h1
• if k < n + 1
• sum(n) = sum(n) + (x(k) ∗ h(m));
• end
• end
• end
• y(n)=sum(n);
• end
.
.G

• disp (’ y(n)= x(n)*h(n)’);


.V
r.B

• disp(y)
D

• subplot(4,1,1);
• stem(x);
• title(’1st sequence x’);
• xlabel(’n’);
• ylabel(’x(n)’);

32
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(4,1,2);
• stem(h);
• title(’2nd sequence h’);
• xlabel(’n’);
• ylabel(’h(n)’);
• subplot(4,1,3);
• stem(y);
• title(’Convolved sequence y’);
• xlabel(’n’);
• ylabel(’y(n)’);
• z=conv(x,h)
• subplot(4,1,4);
.
.G

• stem(z);
.V
r.B

• title(’Tool box Convolved output’);


D

• xlabel(’n’);
• ylabel(’y(n)’);

33
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample Output Diagram

.
.G
.V
r.B
D

Input

Enter the 1st sequence x:————————-

Enter the 2nd sequence h:————————–

34
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output Diagram

.
.G
.V
r.B
D

35
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to compute Linear Convolu-


tion of two discrete time signals and verified the result us-
ing DSP tool box function conv().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

36
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.6 COMPUTATION OF CIRCULAR CONVOLUTION.

Cycle:-2
Experiment No:-6 Date:———————–
1. AIM : Matlab program to compute circular Convolution
of two signals
2. OBJECTIVES:
(a) Matlab program to compute Circular Convolution of
two discrete time signals and verify the result using
DSP tool box function cconv().

Matlab program to compute Circular Convolution

• clc;
.
.G

• close all;
.V
r.B

• clear all;
D

• x=input(’Enter the 1st sequence x:’);


• h=input(’Enter the 2nd sequence h:’);
• N1=length(x);
• N2=length(h);
• N=max(N1,N2);
• x = [x zeros(N − N 1)] ;
• h = [h zeros(N − N 2)];

37
Dr. Biju V.G. Digital Signal Processing Lab Manual

• for n=0 : N-1


• y(n+1)=0;
• f or i = 0 : N − 1
• j = mod(n − i, N );
• y(n + 1) = y(n + 1) + x(i + 1) ∗ h(j + 1);
• end
• end
• subplot(4,1,1);
• stem(x);
• title(’1st sequence x’);
• xlabel(’n’);
• ylabel(’x(n)’);
.
.G

• subplot(4,1,2);
.V
r.B

• stem(h);
D

• title(’2nd sequence h’);


• xlabel(’n’);
• ylabel(’h(n)’);
• subplot(4,1,3);
• stem(y);
• title(’ Circular Convolved sequence y’);
• xlabel(’n’);
• ylabel(’y(n)’);

38
Dr. Biju V.G. Digital Signal Processing Lab Manual

• z=cconv(x,h,N)
• subplot(4,1,4);
• stem(z);
• title(’Tool box Circular Convolved output’);
• xlabel(’n’);
• ylabel(’y(n)’);
Sample Output Diagram

.
.G
.V
r.B
D

39
Dr. Biju V.G. Digital Signal Processing Lab Manual

Input

Enter the 1st sequence x:————————-

Enter the 2nd sequence h:————————–


Output Diagram

.
.G
.V
r.B
D

40
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to compute Circular Convo-


lution of two discrete time signals and verified the result
using DSP tool box function cconv().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

41
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.7 COMPUTATION OF LINEAR CONVOLUTION USING CIR-


CULAR CONVOLUTION.

Cycle:-2
Experiment No:-7 Date:———————–
1. AIM : Matlab program to compute Linear Convolution
Using Circular Convolution.
2. OBJECTIVES:
(a) Matlab program to compute Linear Convolution of
two discrete time signals using Circular Convolution
and verify the result using DSP tool box function
conv().

Matlab program to compute Linear Convolution Using


Circular Convolution
.
.G
.V
r.B

• clc;
D

• close all;
• clear all;
• x=input(’Enter the 1st sequence x:’);
• h=input(’Enter the 2nd sequence h:’);
• N1=length(x);
• N2=length(h);
• N=N1+N2-1 To find linear convolution output length
• x = [x zeros(1, N 2 − 1)] ; append N-N1 zeros to x
• h = [h zeros(1, N 1 − 1)]; append N-N1 zeros to x

42
Dr. Biju V.G. Digital Signal Processing Lab Manual

• [y] =CConvolution(x,h,N);
• disp(y) % Program for plotting the output
• subplot(4,1,1);
• stem(x);
• title(’1st sequence x’);
• xlabel(’n’);
• ylabel(’x(n)’);
• subplot(4,1,2);
• stem(h);
• title(’2nd sequence h’);
• xlabel(’n’);
• ylabel(’h(n)’);
.
.G

• subplot(4,1,3);
.V
r.B

• stem(y);
D

• title(’ Linear Convolved sequence output y using circu-


lar
• convolution’);
• xlabel(’n’);
• ylabel(’y(n)’);
• z=cconv(x,h,N)

43
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(4,1,4);
• stem(z);
• title(’Tool box Circular Convolved output’);
• xlabel(’n’);
• ylabel(’y(n)’);
Function to perform Circular Convolution
• %%%%%%%%%%% Function %%%%%%%%%%%
• function [y]=CConvolution(x,h,N)
• f or n = 0 : N − 1
• y(n + 1) = 0;
• f or i = 0 : N − 1
• j = mod(n − i, N );
.
.G

• y(n + 1) = y(n + 1) + x(i + 1) ∗ h(j + 1);


.V
r.B

• end
D

• end
• end

44
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample Output Diagram

.
.G
.V
r.B
D

Input

Enter the 1st sequence x:————————-

Enter the 2nd sequence h:————————–

45
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output Diagram

.
.G
.V
r.B
D

46
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to compute Linear Convolu-


tion of two discrete time signals using circular convolution
and verified the result using DSP tool box function conv().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

47
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.8 COMPUTATION OF DFT

Cycle:-3
Experiment No:-8 Date:———————–
1. AIM : Matlab program to compute DFT.
2. OBJECTIVES:
(a) Matlab program to compute DFT of a discrete time
signals and verify the result using DSP tool box func-
tion fft().

Matlab program to compute DFT

• clc;
• close all;
.
.G

• clear all;
.V
r.B

• x=input(’Enter the sequence x:’);


D

• N=input(’Enter the value of N’);


• N1=length(x);
• x=[x zeros(1,(N-N1))];
• y=zeros(1,N);

48
Dr. Biju V.G. Digital Signal Processing Lab Manual

• if N < N 1
• disp(’Error’)
• disp(’Sequence length greater than N’)
• else
• for k=0:N-1
• f or n = 0 : N − 1
• y(k + 1) = y(k + 1) + (x(n + 1) ∗ exp(−(i) ∗ 2 ∗ pi ∗
k ∗ n/N ));
• end
• end
• disp(y)
• subplot(3,1,1);
.
.G

• stem(x);
.V
r.B

• title(’sequence x’);
D

• xlabel(’n’);
• ylabel(’x(n)’);
• subplot(3,1,2);
• stem(y);
• title(’ dft’);
• xlabel(’n’);
• ylabel(’X(K)’);

49
Dr. Biju V.G. Digital Signal Processing Lab Manual

• z=fft(x,N)
• subplot(3,1,3);
• stem(z);
• title(’Tool box FFT output’);
• xlabel(’n’);
• ylabel(’Z(K)’);
• end
Sample Output Diagram

.
.G
.V
r.B
D

50
Dr. Biju V.G. Digital Signal Processing Lab Manual

Input

Enter the sequence x:————————-

Enter the value of N:————————–


Output Diagram

.
.G
.V
r.B
D

51
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to compute DFT of a discrete


time signal and verified the result using DSP tool box func-
tion fft().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

52
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.9 COMPUTATION OF IDFT

Cycle:-3
Experiment No:-9 Date:———————–
1. AIM : Matlab program to compute IDFT.
2. OBJECTIVES:
(a) Matlab program to compute IDFT of a discrete time
signals and verify the result using DSP tool box func-
tion ifft().

Matlab program to compute IDFT

• clc;
.
.G

• close all;
.V
r.B

• clear all;
D

• x=input(’Enter the DFT sequence x:’);


• N=input(’Enter the value of N’);
• N1=length(x);
• x=[x zeros(1,(N-N1))];
• y=zeros(1,N);

53
Dr. Biju V.G. Digital Signal Processing Lab Manual

• if N < N 1
• disp(’Error’)
• disp(’Sequence length greater than N’)
• else
• for k=0:N-1
• f or n = 0 : N − 1
• y(k + 1) = y(k + 1) + (x(n + 1) ∗ exp((i) ∗ 2 ∗ pi ∗
k ∗ n/N ));
• end
• y(k+1)=y(k+1)./N;
• end
• disp(y)
.
.G

• subplot(3,1,1);
.V
r.B

• stem(x);
D

• title(’sequence x’);
• xlabel(’n’);
• ylabel(’x(n)’);
• subplot(3,1,2);
• stem(abs(y));
• title(’ idft’);
• xlabel(’n’);
• ylabel(’x(n)’);

54
Dr. Biju V.G. Digital Signal Processing Lab Manual

• z=ifft(x,N)
• subplot(3,1,3);
• stem(z);
• title(’Tool box IFFT output’);
• xlabel(’n’);
• ylabel(’z(n)’);
• end
Sample Output Diagram

.
.G
.V
r.B
D

55
Dr. Biju V.G. Digital Signal Processing Lab Manual

Input

Enter the DFT sequence x:————————-

Enter the value of N:————————–


Output Diagram

.
.G
.V
r.B
D

56
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to compute IDFT of a discrete


time signal and verified the result using DSP tool box func-
tion ifft().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

57
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.10 COMPUTATION OF CONVOLUTION USING DFT

Cycle:-3
Experiment No:-10 Date:———————–
1. AIM : Matlab program to compute convolution using DFT.
2. OBJECTIVES:
(a) Matlab program to compute Matlab program to com-
pute convolution using DFT and verify the result us-
ing DSP tool box function cconv().

Matlab program to compute convolution using DFT

• clc;
• close all;
.
.G

• clear all;
.V
r.B

• x=input(’Enter the 1st sequence x:’);


D

• h=input(’Enter the 2nd sequence h:’);


• N1=length(x);
• N2=length(h);
• N=length(x)+length(h)-1;
• x=[x zeros(1,N2-1)] ;
• h=[h zeros(1,N1-1)];
• x1=DFT(x,N);

58
Dr. Biju V.G. Digital Signal Processing Lab Manual

• x2=DFT(h,N);
• y1=x1.*x2;
• y=IDFT(y1,N);
• y=abs(y)
• y=y(1:N);
• z=conv(x,h)
• subplot(3,2,1);
• stem(x);
• title(’1st sequence x’);
• xlabel(’n’);
• ylabel(’x(n)’);
• subplot(3,2,2);
.
.G

• stem(x1);
.V
r.B

• title(’ X(K)’);
D

• xlabel(’n’);
• ylabel(’X(K)’);
• subplot(3,2,3);
• stem(h);
• title(’2nd sequence h’);
• xlabel(’n’);
• ylabel(’h(n)’);

59
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(3,2,4);
• stem(x2);
• title(’ H(K)’);
• xlabel(’n’);
• ylabel(’H(K)’);
• subplot(3,2,5);
• stem(y);
• title(’ Linear Convolution output’);
• xlabel(’n’);
• ylabel(’y(n)’);
• z=conv(x,h);
• z=z(1:N);
.
.G

• subplot(3,2,6);
.V
r.B

• stem(z);
D

• title(’Tool box Circular Convolved output’);


• xlabel(’n’);
• ylabel(’z(n)’);

60
Dr. Biju V.G. Digital Signal Processing Lab Manual

%%%%%%%%%%%%%%%%%%%%%%%%%%
Function to compute DFT
%%%%%%%%%%%%%%%%%%%%%%%%%%
• function [y]= DFT(x,N)
• y=zeros(1,N);
• f or k = 0 : N − 1
• f or n = 0 : N − 1
• y(k + 1) = y(k + 1) + (x(n + 1) ∗ exp(−(i) ∗ 2 ∗
pi ∗ k ∗ n/N ))
• end
• end
• end
.
.G

%%%%%%%%%%%%%%%%%%%%%%%%%%
.V
r.B

Function to compute IDFT


D

%%%%%%%%%%%%%%%%%%%%%%%%%%
• function [y]= IDFT(x,N)
• y=zeros(1,N);
• f or k = 0 : N − 1
• f or n = 0 : N − 1
• y(k + 1) = y(k + 1) + (x(n + 1) ∗ exp((i) ∗ 2 ∗ pi ∗
k ∗ n/N ));
• end
• y(k + 1) = y(k + 1)./N ;
• end
• end

61
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample Output Diagram

.
.G
.V
r.B
D

Input

Enter the 1st sequence x:————————-

Enter the 2nd sequence h:————————–

62
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output Diagram

.
.G
.V
r.B
D

63
Dr. Biju V.G. Digital Signal Processing Lab Manual

Result:-

Executed the matlab program to compute Linear convolu-


tion of two discrete time signal using DFT method and ver-
ified the result using DSP tool box function conv().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

64
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.11 IMPLEMENTATION OF IIR LOW PASS, HIGH PASS, BAND


PASS, BAND REJECT FILTER

CYCLE:-4
Experiment No:-11 Date:———————–
1. AIM: AIM: Design and implementation of IIR filter to meet
given specifications.
2. OBJECTIVES:
(a) To design the BUTTERWORTH filter to meet the given
specification using the MATLAB functions BUTTORD
and BUTTER.
(b) Bilinear transformation for analog-to-digital filter con-
version using function BILINEAR.
(c) To verify the result by theoretical calculations.
.
.G

3. Algorithm
.V
r.B

(a) Get the order of the filter


D

(b) Find the filter coefficients


(c) Plot the magnitude response
4. Steps
(a) Input the pass band and stop band frequencies
(b) Input the pass band and stop band ripples
(c) Input the sampling frequency
(d) From the given specifications find the order of the
filter N.

65
Dr. Biju V.G. Digital Signal Processing Lab Manual

(e) Round off it to the next higher integer.


(f) Find the transfer function H(s) for Ωc = 1rad/sec for
the value of N.
(g) Calculate the value of cutoff frequency Ωc.
(h) Find the transfer function Ha(s) for the above value
of Ωc by substituting s( Ωsc ) in H(s)
(i) Find H(Z) using Bilinear Transformation.

Matlab Program Low Pass Butterworth Filter

• clc;
• clear all;
• close all;
.
.G

• fp = input(’Enter the Pass band frequency in Hz = ’ );


.V
r.B

• fs = input(’Enter the Stop band frequency in Hz = ’);


D

• Fs = input(’Enter the Sampling frequency in Hz = ’);


• Ap = input(’ Enter the Pass band ripple in db:’);
• As = input(’Enter theStop band ripple in db:’);
• wp=2*fp/Fs;
• ws=2*fs/Fs;
• Up = 2*tan(wp/2);
• Us = 2*tan(ws/2);

66
Dr. Biju V.G. Digital Signal Processing Lab Manual

• disp(’Prewrapped Pass band frequency’)


• disp(Up)
• disp(’Prewrapped Stop band frequency’)
• disp(Us)
• [n, wn]= buttord (Up,Us,Ap,As);
• disp(’order of the filter N =’);
• disp(n);
• disp(’Normalized cut off frequency = ’);
• disp(wn);
• [num, den] = butter(n,wn,’low’);
• [h, w]=freqz(num, den);
• m=20*log10(abs(h));
.
.G

• ang=angle(h);
.V
r.B

• subplot(2,1,1);
D

• plot(w/pi,m)
• title(’Magnitude response of Analog Low Pass Filter’)
• xlabel(’Normalized frequency’);
• ylabel(’Magnitude’);
• grid;

67
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(2,1,2);
• plot(w/pi, ang);
• title(’Phase response of Analog Low Pass Filter’)
• xlabel(’Normalized frequency’);
• ylabel(’Phase’);
• grid;
• [b, a] = bilinear(num, den,1);
• printsys(b,a,’z’);
Inputs
Enter the Pass band frequency in Hz = ————————–
Enter the Stop band frequency in Hz = ————————–
Enter the Sampling frequency in Hz = ————————–
Enter the Pass band ripple in db:—————————
.
.G

Enter the Stop band ripple in db:—————————


.V
r.B
D

68
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample output diagram Low Pass filter

.
.G
.V
r.B
D

output
Prewrapped Pass band frequency:—————————-

Prewrapped Stop band frequency:—————————-

69
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output diagram Low Pass filter

.
.G
.V
r.B
D

70
Dr. Biju V.G. Digital Signal Processing Lab Manual

Matlab Program High Pass Butterworth Filter


• clc;
• clear all;
• close all;
• fp = input(’Enter the Pass band frequency in Hz = ’ );
• fs = input(’Enter the Stop band frequency in Hz = ’);
• Fs = input(’Enter the Sampling frequency in Hz = ’);
• Ap = input(’ Enter the Pass band ripple in db:’);
• As = input(’Enter theStop band ripple in db:’);
• wp=2*fp/Fs;
• ws=2*fs/Fs;
• Up = 2*tan(wp/2);
.
.G

• Us = 2*tan(ws/2);
.V
r.B

• disp(’Prewrapped Pass band frequency’)


D

• disp(Up)
• disp(’Prewrapped Stop band frequency’)
• disp(Us)
• [n, wn]= buttord (Up,Us,Ap,As);
• disp(’order of the filter N =’);
• disp(n);
• disp(’Normalized cut off frequency = ’);
• disp(wn);

71
Dr. Biju V.G. Digital Signal Processing Lab Manual

• [num, den] = butter(n,wn,’high’);


• [h, w]=freqz(num, den);
• m=20*log10(abs(h));
• ang=angle(h);
• subplot(2,1,1);
• plot(w/pi,m)
• title(’Magnitude response of Analog High Pass Filter’)
• xlabel(’Normalized frequency’);
• ylabel(’Magnitude’);
• grid;
• subplot(2,1,2);
• plot(w/pi, ang);
.
.G

• title(’Phase response of Analog High Pass Filter’)


.V
r.B

• xlabel(’Normalized frequency’);
D

• ylabel(’Phase’);
• grid;
• [b, a] = bilinear(num, den,1);
• printsys(b,a,’z’);

72
Dr. Biju V.G. Digital Signal Processing Lab Manual

Inputs
Enter the Pass band frequency in Hz = ————————–
Enter the Stop band frequency in Hz = ————————–
Enter the Sampling frequency in Hz = ————————–
Enter the Pass band ripple in db:—————————
Enter the Stop band ripple in db:—————————

Sample output diagram High Pass filter

.
.G
.V
r.B
D

73
Dr. Biju V.G. Digital Signal Processing Lab Manual

output
Prewrapped Pass band frequency:—————————-

Prewrapped Stop band frequency:—————————-

Output diagram High Pass filter

.
.G
.V
r.B
D

74
Dr. Biju V.G. Digital Signal Processing Lab Manual

Matlab Program Band Pass Butterworth Filter


• clc;
• clear all;
• close all;
• fp = input(’Enter the Pass band frequency in Hz = ’ );
• fs = input(’Enter the Stop band frequency in Hz = ’);
• Fs = input(’Enter the Sampling frequency in Hz = ’);
• Ap = input(’ Enter the Pass band ripple in db:’);
• As = input(’Enter theStop band ripple in db:’);
• wp=2*fp/Fs;
• ws=2*fs/Fs;
• Up = 2*tan(wp/2);
.
.G

• Us = 2*tan(ws/2);
.V
r.B

• disp(’Prewrapped Pass band frequency’)


D

• disp(Up)
• disp(’Prewrapped Stop band frequency’)
• disp(Us)
• [n, wn]= buttord (Up,Us,Ap,As);
• disp(’order of the filter N =’);
• disp(n);
• disp(’Normalized cut off frequency = ’);
• disp(wn);

75
Dr. Biju V.G. Digital Signal Processing Lab Manual

• [num, den] = butter(n,wn);


• [h, w]=freqz(num, den);
• m=20*log10(abs(h));
• ang=angle(h);
• subplot(2,1,1);
• plot(w/pi,m)
• title(’Magnitude response of Analog Band Pass Filter’)
• xlabel(’Normalized frequency’);
• ylabel(’Magnitude’);
• grid;
• subplot(2,1,2);
• plot(w/pi, ang);
.
.G

• title(’Phase response of Analog Band Pass Filter’)


.V
r.B

• xlabel(’Normalized frequency’);
D

• ylabel(’Phase’);
• grid;
• [b, a] = bilinear(num, den,1);
• printsys(b,a,’z’);

76
Dr. Biju V.G. Digital Signal Processing Lab Manual

Inputs
Enter the Pass band frequency in Hz = ————————–
Enter the Stop band frequency in Hz = ————————–
Enter the Sampling frequency in Hz = ————————–
Enter the Pass band ripple in db:—————————
Enter the Stop band ripple in db:—————————

Sample output diagram Band Pass filter

.
.G
.V
r.B
D

77
Dr. Biju V.G. Digital Signal Processing Lab Manual

output
Prewrapped Pass band frequency:—————————-

Prewrapped Stop band frequency:—————————-

Output diagram Band Pass filter

.
.G
.V
r.B
D

78
Dr. Biju V.G. Digital Signal Processing Lab Manual

Matlab Program Band Reject Butterworth Filter


• clc;
• clear all;
• close all;
• fp = input(’Enter the Pass band frequency in Hz = ’ );
• fs = input(’Enter the Stop band frequency in Hz = ’);
• Fs = input(’Enter the Sampling frequency in Hz = ’);
• Ap = input(’ Enter the Pass band ripple in db:’);
• As = input(’Enter theStop band ripple in db:’);
• wp=2*fp/Fs;
• ws=2*fs/Fs;
• Up = 2*tan(wp/2);
.
.G

• Us = 2*tan(ws/2);
.V
r.B

• disp(’Prewrapped Pass band frequency’)


D

• disp(Up)
• disp(’Prewrapped Stop band frequency’)
• disp(Us)
• [n, wn]= buttord (Up,Us,Ap,As);
• disp(’order of the filter N =’);
• disp(n);
• disp(’Normalized cut off frequency = ’);
• disp(wn);

79
Dr. Biju V.G. Digital Signal Processing Lab Manual

• [num, den] = butter(n,wn,’stop’);


• [h, w]=freqz(num, den);
• m=20*log10(abs(h));
• ang=angle(h);
• subplot(2,1,1);
• plot(w/pi,m)
• title(’Magnitude response of Analog Band Reject Filter’)
• xlabel(’Normalized frequency’);
• ylabel(’Magnitude’);
• grid;
• subplot(2,1,2);
• plot(w/pi, ang);
.
.G

• title(’Phase response of Analog Band Reject Filter’)


.V
r.B

• xlabel(’Normalized frequency’);
D

• ylabel(’Phase’);
• grid;
• [b, a] = bilinear(num, den,1);
• printsys(b,a,’z’);

80
Dr. Biju V.G. Digital Signal Processing Lab Manual

Inputs
Enter the Pass band frequency in Hz = ————————–
Enter the Stop band frequency in Hz = ————————–
Enter the Sampling frequency in Hz = ————————–
Enter the Pass band ripple in db:—————————
Enter the Stop band ripple in db:—————————

Sample output diagram Band Reject filter

.
.G
.V
r.B
D

81
Dr. Biju V.G. Digital Signal Processing Lab Manual

output
Prewrapped Pass band frequency:—————————-

Prewrapped Stop band frequency:—————————-

Output diagram Band Reject filter

.
.G
.V
r.B
D

82
Dr. Biju V.G. Digital Signal Processing Lab Manual

RESULT:-
Implementation of IIR Low, High, Band Pass & Band Reject
filter for the given specifications are done, the desired fre-
quency responses are plotted and computed the transfer
functions H(Z) using Bilinear Transfer function.

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

83
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.12 IMPLEMENTATION OF FIR LOW AND HIGH PASS FIL-


TER WITH AND WITHOUT USING WINDOW

CYCLE:-4
Experiment No:-12 Date:———————–
1. AIM: Design and implementation of FIR filter to meet
given specifications (low pass filter using hamming win-
dow).

2. OBJECTIVES:
(a) To design the FIR filter by Hamming window using
the inbuilt MATLAB function FIR1 and HAMMING.
(b) To verify the result by theoretical calculations
3. Algorithm
.
.G

(a) Get the sampling frequency


.V
r.B

(b) Get the pass band frequency


D

(c) Get the stop band frequency


(d) Get the pass band ripple and stop band attenuation
(e) Select the window suitable for stop band attenuation
(f) Calculate the order N based on transition width
(g) Find the N window coefficients
(h) Find the impulse response of h[n]
(i) Verify the frequency response of h[n]

84
Dr. Biju V.G. Digital Signal Processing Lab Manual

FIR Low pass Filter


• clc;
• close all;
• clear all;
• wp = input( ’Enter the Pass band edge in radians = ’);
• ws = input(’Enter the Stop band edge in radians = ’);
• wt =abs( ws-wp);
• n1 = ceil (8*pi/wt);
• N = n1 + rem(n1-1, 2);
• disp(’order of the FIR filter N = ’);
• disp(N);
• Wc1 = wp + wt/2 ;
.
.G

• Wc = Wc1/pi;
.V
r.B

• disp(’cut off frequency = ’);


D

• disp(Wc);
• h = fir1(N-1,Wc, ’low’);
• disp(’Impulse Response of FIR filter=’);
• disp(h);
• figure,freqz(h);
• xlabel(’n’);
• ylabel(’h(n)’);
• title(’FIR Low Pass Filter response without using Win-
dow ’);

85
Dr. Biju V.G. Digital Signal Processing Lab Manual

• wn = (hamming(N));
• h1=h.*wn’;
• figure,freqz(h1);
• xlabel(’n’);
• ylabel(’h(n)’);
• title(’FIR Low Pass Filter response using hamming Win-
dow’);
Inputs
enter the Pass band edge in radians =————–

enter the stop band edge in radians =—————


Note:-The inputs should be with in the range 0 to 1*pi
.
.G
.V
r.B
D

86
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample output Low Pass filter without and with window

.
.G
.V
r.B
D

87
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output diagram Low Pass filter

.
.G
.V
r.B
D

88
Dr. Biju V.G. Digital Signal Processing Lab Manual

FIR High Pass Filter


• clc;
• close all;
• clear all;
• wp = input( ’Enter the Pass band edge in radians = ’);
• ws = input(’Enter the Stop band edge in radians = ’);
• wt =abs( ws-wp);
• n1 = ceil (8*pi/wt);
• N = n1 + rem(n1-1, 2);
• disp(’order of the FIR filter N = ’);
• disp(N);
• Wc1 = wp + wt/2 ;
.
.G

• Wc = Wc1/pi;
.V
r.B

• disp(’cut off frequency = ’);


D

• disp(Wc);
• h = fir1(N-1,Wc, ’high’);
• disp(’Impulse Response of FIR filter=’);
• disp(h);
• figure,freqz(h);
• xlabel(’n’);
• ylabel(’h(n)’);
• title(’FIR Low Pass Filter response without using Win-
dow ’);

89
Dr. Biju V.G. Digital Signal Processing Lab Manual

• wn = (hamming(N));
• h1=h.*wn’;
• figure,freqz(h1);
• xlabel(’n’);
• ylabel(’h(n)’);
• title(’FIR Low Pass Filter response using hamming Win-
dow’);
Inputs
enter the Pass band edge in radians =————————–

enter the stop band edge in radians =————————–

Note:-The inputs should be with in the range 0 to 1*pi


.
.G
.V
r.B
D

90
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample output High Pass filter without and with window

.
.G
.V
r.B
D

91
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output diagram High Pass filter

.
.G
.V
r.B
D

92
Dr. Biju V.G. Digital Signal Processing Lab Manual

RESULT:-
Implementation of FIR filter for the given specifications is
done and the desired frequency response is obtained for
low and high pass FIR filter, with and without using window.

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

93
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.13 COMPUTATION OF BLOCK CONVOLUTION USING


OVERLAP SAVE METHOD

Cycle:-4
Experiment No:-13 Date:———————–
1. AIM : Matlab program to compute block convolution us-
ing overlap save method .
2. OBJECTIVES:
(a) Matlab program to compute block convolution using
overlap save method and verify the result using DSP
tool box function conv().
Matlab program to compute block convolution using
overlap save method
• clc;
.
.G

• close all;
.V
r.B

• clear all;
D

• x=input(’Enter the 1st sequence x:’);


• h=input(’Enter the 2nd sequence h:’);
• X=x;
• H=h;
• N= input(’enter the size of block’);
• Ls=length(x);
• M=length(h);

94
Dr. Biju V.G. Digital Signal Processing Lab Manual

• if (N < M )
• disp(’ Block size L must greater than the length of im-
pulse response ’)
• break
• end
• M1=M-1;
• DL=N-M+1;
• x = [zeros(1, M-1), x , zeros(1,N-1)];
• h = [h, zeros(1,N-M)];
• L=floor((Ls+M1-1)/DL);
• Y=zeros(L+1,N);
• for k=0:L
.
.G

• xk=x(k*DL+1:k*DL+N);
.V
r.B

• Y (k + 1, :) = CConvolution(xk, h, N );
D

• end
• Y=Y(:,M:N);
• Y=transpose(Y);
• f=Y(:)’;
• p=conv(X,H);
• disp(’using over lap save method’)
• disp(f)

95
Dr. Biju V.G. Digital Signal Processing Lab Manual

• disp(’using inbuilt function’)


• disp(p)
• subplot(4,1,1);
• stem(X);
• title(’ Input sequence(x(n)’);
• xlabel(’n’);
• ylabel(’x(n)’);
• subplot(4,1,2);
• stem(H);
• title(’ Impulse Response(h(n)’);
• xlabel(’n’);
• ylabel(’h(n)’);
.
.G

• subplot(4,1,3);
.V
r.B

• stem(f);
D

• title(’ Overlap Save method output’);


• xlabel(’n’); ylabel(’y(n)’);
• subplot(4,1,4);
• stem(p);
• title(’DSP Tool box function conv output’);
• xlabel(’n’);
• ylabel(’y(n)’);

96
Dr. Biju V.G. Digital Signal Processing Lab Manual

%%%%%%%%%%% %%%%%%%%%%%
Function to perform Circular Convolution
%%%%%%%%%%% %%%%%%%%%%%
• function [y]=CConvolution(x,h,N)
• f or n = 0 : N − 1
• y(n + 1) = 0;
• f or i = 0 : N − 1
• j = mod(n − i, N );
• y(n + 1) = y(n + 1) + x(i + 1) ∗ h(j + 1);
• end
• end
• end
.
.G
.V
r.B
D

97
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample Output Diagram

.
.G
.V
r.B
D

Input

Enter the 1st sequence x:————————-

Enter the 2nd sequence h:————————–

98
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output Diagram

.
.G
.V
r.B
D

99
Dr. Biju V.G. Digital Signal Processing Lab Manual

RESULT:-

Executed matlab program to compute block convolution us-


ing overlap save method and verified the result using DSP
tool box function conv().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

100
Dr. Biju V.G. Digital Signal Processing Lab Manual

0.14 COMPUTATION OF BLOCK CONVOLUTION USING


OVERLAP ADD METHOD

Cycle:-4
Experiment No:-14 Date:———————–
1. AIM : Matlab program to compute block convolution us-
ing overlap add method.
2. OBJECTIVES:
(a) Matlab program to compute block convolution using
overlap add method and verify the result using DSP
tool box function conv().
Matlab program to compute block convolution using
overlap add method
• clc;
.
.G

• close all;
.V
r.B

• clear all;
D

• x=input(’Enter the 1st sequence x:’);


• h=input(’Enter the 2nd sequence h:’);
• X=x;
• H=h;
• N= input(’enter the size of block’);
• Ls=length(x);
• M=length(h);

101
Dr. Biju V.G. Digital Signal Processing Lab Manual

• if (N < M )
• disp(’ Block size L must greater than the length of im-
pulse response ’)
• break
• end
• DL=N-M+1;
• h=[h zeros(1,(N-M))];
• L=floor((Ls+M-2)/DL);
• Xnew= zeros(L,N);
• Ynew= zeros(L,N);
• x=[x zeros(1,N-1)];
• for i=0:L
.
.G

• xx = [zeros(1, M − 1)];
.V
r.B

• a = [DL ∗ i + 1 : DL ∗ i + DL];
D

• xy = x(a);
• Xnew(i + 1, :) = [xy xx];
• xd = [xy xx];
• Y new(i + 1, :) = CConvolution(xd, h, N );
• end

102
Dr. Biju V.G. Digital Signal Processing Lab Manual

• OAM=[zeros(L+1,Ls+M-1)];
• for i=0:L
• a = i ∗ DL + 1;
• OAM ((i + 1), a : a + N − 1) = Y new(i + 1, :);
• end
• disp(’user defined function’)
• OAM=sum(OAM);
• OAM=OAM(1:Ls+M-1)
• disp(’built in function’)
• P=conv(X,H)
• subplot(4,1,1);
• stem(X);
.
.G

• title(’ Input sequence(x(n)’);


.V
r.B

• xlabel(’n’);
D

• ylabel(’x(n)’);
• subplot(4,1,2);
• stem(H);
• title(’ Inpulse Response(h(n)’);
• xlabel(’n’);
• ylabel(’h(n)’);

103
Dr. Biju V.G. Digital Signal Processing Lab Manual

• subplot(4,1,3);
• stem(OAM);
• title(’ Overlap add method output’);
• xlabel(’n’);
• ylabel(’y(n)’);
• subplot(4,1,4);
• stem(P);
• title(’DSP Tool box function conv output’);
• xlabel(’n’);
• ylabel(’y(n)’);

%%%%%%%%%%% %%%%%%%%%%%
.

Function to perform Circular Convolution


.G
.V

%%%%%%%%%%% %%%%%%%%%%%
r.B
D

• function [y]=CConvolution(x,h,N)
• f or n = 0 : N − 1
• y(n + 1) = 0;
• f or i = 0 : N − 1
• j = mod(n − i, N );
• y(n + 1) = y(n + 1) + x(i + 1) ∗ h(j + 1);
• end
• end
• end

104
Dr. Biju V.G. Digital Signal Processing Lab Manual

Sample Output Diagram

.
.G
.V
r.B
D

Input

Enter the 1st sequence x:————————-

Enter the 2nd sequence h:————————–

105
Dr. Biju V.G. Digital Signal Processing Lab Manual

Output Diagram

.
.G
.V
r.B
D

106
Dr. Biju V.G. Digital Signal Processing Lab Manual

RESULT:-

Executed matlab program to compute block convolution us-


ing overlap add method and verified the result using DSP
tool box function conv().

Signature of the Staff in charge:- ————————————-

Output verification date:—————————————-


.
.G
.V
r.B
D

107

You might also like