0% found this document useful (0 votes)
236 views40 pages

DSP Lab Manual GEC Dahod 1

Here are the steps to write a MATLAB program to generate some elementary continuous time signals: 1. Clear the workspace: clear all; close all; clc 2. Define time vector: t = 0:0.01:10; % Time vector from 0 to 10 with step size of 0.01 3. Generate signals: % Sinusoidal signal x1 = sin(2*pi*t); % Complex signal x2 = sin(2*pi*t) + cos(4*pi*t); % Unit impulse x3 = (t==5); % Unit step x4 = heaviside(t-5

Uploaded by

Tushar Mhuskey
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)
236 views40 pages

DSP Lab Manual GEC Dahod 1

Here are the steps to write a MATLAB program to generate some elementary continuous time signals: 1. Clear the workspace: clear all; close all; clc 2. Define time vector: t = 0:0.01:10; % Time vector from 0 to 10 with step size of 0.01 3. Generate signals: % Sinusoidal signal x1 = sin(2*pi*t); % Complex signal x2 = sin(2*pi*t) + cos(4*pi*t); % Unit impulse x3 = (t==5); % Unit step x4 = heaviside(t-5

Uploaded by

Tushar Mhuskey
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/ 40

Department

of
Electronics & Communication Engineering

Laboratory Manual
Digital Signal Processing
B. E. SEMESTER: VII
(Subject Code: 171003)

(GUJARAT TECHNOLOGICAL UNIVERSITY)


Term Date: 1-7-2013 to 30-10-2013
Prepared by: Prof. S. B. Prajapati

Government Engineering College, Dahod

Certificate
This is to certify that Mr./Ms........
of Electronics and Communication department, semester. Enrollment
No. has satisfactorily completed his/her laboratory work in the
course .......................... course code ... for the term
ending in ..2013.

Date of Submission

Sign of the subject In-charge

Dept. of Electronics and Comm. GEC, Dahod |

Head of the Department

Digital Signal Processing Lab Manual

INDEX
Sr.
No.
1

7
8
9

Title of the Experiment

Date

Page

Sign

Marks

Familiarization with MATLAB software and general


functions.
Write a MATLAB program to develop some
elementary continues time (CT) signals
a. Sinusoidal
b. Complex waveform
c. Unit Impulse
d. Unit Step
e. Unit Ramp
f. Exponential
g. Noise
Write a MATLAB program to find the sum of
sinusoidal signals and understanding of the
concept of harmonics.
Write a MATLAB program to develop some
elementary sequences or discrete time (DT) signals
a. Sinusoidal
b. Complex waveform
c. Unit Impulse
d. Unit Step
e. Unit Ramp
f. Exponential
g. Noise
Write a MATLAB program to verify the Sampling
theorem.
Write a MATLAB program to find the impulse
response of a LTI system defined by a difference
equation:
y(n) + 0.7y(n-1) 0.45y(n-2) 0.6y(n-3) =
0.8x(n) 0.44x(n-1) + 0.36x(n-2) + 0.2x(n-3)
Write a MATLAB program to plot the Frequency
response of a given LTI sequence:
y(n) 5 y(n1) = x(n) + 4 x(n1)
Write a MATLAB program to compute linear
convolution of two given sequences.
Write a MATLAB program to find the Discrete Time
Fourier Transform DTFT of the given sequence.

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

10

write a MATLAB program to plot magnitude


response and phase response of digital FIR filter
using Rectangular window
a. Low pass filter
b. High pass filter
c. Bandpass filter
d. Bandstop filter
Hanning Window and Hamming Window Design

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

Experiment No: 1

FAMILIARISATION WITH MATLAB

Aim: To familiarise with MATLAB software and general functions.


MATLAB: MATLAB is a software package for high performance numerical computation and
visualization provides an interactive environment with hundreds of built in functions for
technical computation, graphics and animation. The MATLAB name stands for MATrix
Laboratory produced by Mathworks Inc., USA.
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).
It also allows you to put a list of your processing requests together in a file and save
that combined list with a name so that you can run all of those commands in the same order at
some later time. Furthermore, it allows you to run such lists of commands such that you pass in
data and/or get data back out (i.e. the list of commands is like a function in most programming
languages). Once you save a function, it becomes part of your toolbox (i.e. it now looks to you
as if it were part of the basic toolbox that you started with). For those with computer
programming backgrounds: Note that MATLAB runs as an interpretive language (like the old
BASIC). That is, it does not need to be compiled. It simply reads through each line of the
function, executes it, and then goes on to the next line. (In practice, a form of compilation
occurs when you first run a function, so that it can run faster the next time you run it.)
MATLAB Windows:
MATLAB works with through three 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 user-written programs ,are typed in this window at the MATLAB prompt.
Graphics window: the output of all graphics commands typed in the command window are
flushed to the graphics or figure window, a separate gray window with white background
colour 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 computation 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, character strings, structures and cells. There is
no need to declare variables as real or complex, MATLAB automatically sets the variable to be
real.
Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

Dimensioning: Dimensioning is automatic in MATLAB. No dimension statements are required


for vectors or arrays. We can find the dimensions of an existing matrix or a vector with the size
and length commands.
Where to work in MATLAB?
All programs and commands can be entered either in the
a) Command window.
b) As an M file using Matlab editor.
Note: Save all M files in the folder 'work' in the current directory. Otherwise you have to locate
the file during compiling. Typing quit in the command prompt >> quit, will close MATLAB
Development Environment.

Basic commands 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. F= 20:1:100
Therefore F = [20 21 22 23 24 100]
3. T= 0: 1/pi: 1
Therefore T= [0, 0.3183, 0.6366, 0.9549]
4. zeros (1, 3)
The above instruction creates a vector of one row and three columns whose values are zero
Output= [0 0 0]
5. zeros (2,4)
Output = 0 0 0 0 0 0 0 0
6. ones (5,2)
The above instruction creates a vector of five rows and two columns
Output = 1 1 1 1 1 1 1 1 1 1
7. a = [ 1 2 3] b = [4 5 6]
a.*b = [4 10 18]
8. If C= [2 2 2]
b.*C results in [8 10 12]

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

9. plot (t, x)
If x = [6 7 8 9]
t = [1 2 3 4]
This instruction will display a figure window which indicates the plot of x versus t.

10. stem (t,x) :This instruction will display a figure window as shown

11. Subplot: This function divides the figure window into rows and columns.
Subplot (2 2 1) divides the figure window into 2 rows and 2 columns 1 represent number
of the figure

(2,2,1)

(2,2,3)

Dept. of Electronics and Comm. GEC, Dahod |

(2,2,2)

(2,2,4)

Digital Signal Processing Lab Manual

12. Conv
Syntax: w = conv(u,v)
Description: w = conv(u,v) convolves vectors u and v. Algebraically, convolution is the same
operation as multiplying the polynomials whose coefficients are the elements of u and v.
13. Disp
Syntax: disp(X)
Description: disp(X) displays an array, without printing the array name. If X contains a text
string, the string is displayed. Another way to display an array on the screen is to type its name,
but this prints a leading "X=," which is not always desirable. Note that disp does not display
empty arrays.
14. xlabel
Syntax: xlabel('string')
Description: xlabel('string') labels the x-axis of the current axes.
15. ylabel
Syntax : ylabel('string')
Description: ylabel('string') labels the y-axis of the current axes.
16. Title
Syntax : title('string')
Description: title('string') outputs the string at the top and in the centre of the current axes.
17. grid on
Syntax : grid on
Description: grid on adds major grid lines to the current axes.
18. FFT
FFT(X) is the discrete Fast Fourier transform (FFT) of vector X. For matrices, the FFT
operation is applied to each column. For N-D arrays, the FFT operation operates on the first
non-singleton dimension. FFT(X,N) is the N-point FFT, padded with zeros if X has less than N
points and truncated if it has more.
19. ABS
Absolute value.
ABS(X) is the absolute value of the elements of X. When X is complex, ABS(X) is the complex
modulus (magnitude) of the elements of X.
20. ANGLE

Phase angle.

ANGLE(H) returns the phase angles, in radians, of a matrix with complex elements.
Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

21. INTERP
Resample data at a higher rate using low-pass interpolation.
Y = INTERP(X,L) re-samples the sequence in vector X at L times the original sample rate. The
resulting re-sampled vector Y is L times longer, LENGTH(Y) = L*LENGTH(X).
22. DECIMATE
Resample data at a lower rate after low-pass filtering.
Y = DECIMATE(X,M) re-samples the sequence in vector X at 1/M times the original
sample rate. The resulting re-sampled vector Y is M times shorter,
i.e., LENGTH(Y) = CEIL(LENGTH(X)/M). By default, DECIMATE filters the data with an 8th
order Chebyshev Type I low-pass filter with cut-off frequency .8*(Fs/2)/R, before re-sampling.
Some important commands in MATLAB
Help
List topics on which help is available
Help command name
Provides help on the topic selected
Demo
Runs the demo program
Who
Lists variables currently in the workspace
Whos
Lists variables currently in the workspace with their size
Clear
Clears the workspace, all the variables are removed
Clear x,y,z
Clears only variables x,y,z
Quit
Quits MATLAB

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

Experiment No: 2
GENERATION OF ELEMENTARY CONTINUES TIME SIGNALS
Aim : Write a MATLAB program to develop some elementary continues time (CT) signals

a.
b.
c.
d.
e.
f.
g.

Sinusoidal
Square
Complex waveform
Unit Step
Unit Ramp
Exponential
Noise

MATLAB Code :

a. Sinusoidal Waveform
clc;
clear all;
close all;
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
subplot (2,1,1);
y =a*sin(2*pi*f*t);
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('sine wave')
grid on;

Output:
Enter the value of frequency 2
Enter the value of amplitude 1

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

10

b. Square Waveform
clc;
clear all;
close all;
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
subplot (2,1,1);
y =a*square(2*pi*f*t);
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Square wave')
grid on;
Output :
Enter the value of frequency 1
Enter the value of amplitude 1

c.

Complex Waveform

clc;
clear all;
close all;
t = 0 : 0.001 : 5;
f = input ('Enter the value of frequency');
a = input ('Enter the value of amplitude');
subplot (2,1,1);
y = [exp((-0.2+2*i)*t)];
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Complex wave')
grid on;
Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

11

Output :
Enter the value of frequency 2
Enter the value of amplitude 1

d. Unit Step Waveform


clc;
clear all;
close all;
t = 0 : 0.001 : 5;
a = input ('Enter the value of amplitude');
subplot(2,1,1)
plot (t,a,'r');
xlabel ('time');
ylabel ('amplitude');
title ( 'Complex Wave')
grid on;
Output:
Enter the value of amplitude 1

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

12

e.

Unit Ramp Waveform

clc;
clear all;
close all;
t = 0 : 0.001 : 5;
m = input ('Enter the value of slope');
subplot (2,1,1);
y = m*t;
plot (t,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Ramp wave')
grid on;
Output:
Enter the value of slope 1

f.

Exponential Waveform

clc;
clear all;
close all;
a=0.5;
t=0:0.1:10;
disp('EXPONENTIAL DECAYING SIGNAL');
x=a.^t;
subplot(2,1,1);
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Decaying Signal Response');
grid on;

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

13

disp('EXPONENTIAL GROWING SIGNAL');


x=a.^-t;
subplot(2,1,2);
plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponential Growing Signal Response');
grid on;
Output:
EXPONENTIAL DECAYING SIGNAL

EXPONENTIAL GROWING SIGNAL

g.

Noise Signal

clc;
clear all;
close all;
t=0:0.001:50;
% generate the uncorrupted signal
s=2*t.*(0.9.^t);
subplot(2,1,1);
plot(t,s);
title('Uncorrupted sequence');
xlabel('Time index');
ylabel('Amplitude');

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

14

% generate the noise signal


subplot(2,1,2);
x=rand(50,1);
plot(x);
title('Noise');
xlabel('Time index');
ylabel('Amplitude');
Output:

Conclusion:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

15

Experiment No: 3
CONCEPT OF HARMONICS

Aim: Write a MATLAB program to find the sum of sinusoidal signals and understand the
concept of harmonics.
MATLAB Code :

clc;
clear all;
close all;
t=0:.01:2*pi;
%generation of sine signals%
y1=sin(t);
y2=sin(3*t)/3;
y3=sin(5*t)/5;
y4=sin(7*t)/7;
y5=sin(9*t)/9;
%y = sin(t) + sin(3*t)/3 + sin(5*t)/5 + sin(7*t)/7 + sin(9*t)/9; %
y = y1+y2+y3+y4+y5;
plot (t,y,t,y1,t,y2,t,y3,t,y4,t,y5);
legend ('y','y1','y2','y3','y4','y5');
title ('generation of sum of sinusoidal signals');
grid on;
ylabel ('---> Amplitude');
xlabel ('---> t');
Output:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

16

Exercise:
1. Plot the synthesized waveform using the summation of even component of the series.
2. Plot the synthesized triangular waveform.

Conclusion:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

17

Experiment No: 4
GENERATION OF ELEMENTARY DISCRETE TIME SIGNALS
Aim : Write a MATLAB program to develop some elementary discrete time (DT) signals

a.
b.
c.
d.
e.
f.
g.

Sinusoidal
Square
Complex waveform
Unit Impulse
Unit Step
Unit Ramp
Exponential

MATLAB Code :

a. Sinusoidal DT signal
clc;
clear all;
close all;
N = input('Enter Number of Samples : ');
n = 0:0.1:N;
x = sin(n);
stem (n,x);
xlabel ('Time');
ylabel ('Amplitude');
title ('Discrete Time Sine Signal');
grid on;
Output:
Enter Number of Samples : 15

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

18

b. Square DT signal
clc;
clear all;
close all;
N = input('Enter the number of Samples:);
n = 0:0.1:N;
s = square(2*n);
stem (n,s);
xlabel ('time');
ylabel ('amplitude');
title ('square wave')
grid on;
Output:
Enter the number of Samples : 10

c. Complex DT signal
clc;
clear all;
close all;
n = 0 : 0.1 : 15;
subplot (2,1,1);
y = [exp((-0.2+2*i)*n)];
stem (n,y,'r');
xlabel ('time');
ylabel ('amplitude');
title ('Discrete Time Complex wave')
grid on;

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

19

d. Unit Impulse DT signal


clc;
clear all;
close all;
N = input('Enter the Number of Samples: ');
n = -N:1:N;
x = [zeros(1,N) 1 zeros(1,N)];
subplot (2,1,1);
stem (n,x,'r');
xlabel ('Time');
ylabel ('Amplitude');
title ('Impulse Response');
grid on;
Output: Enter the number of Samples : 7

e. Unit Step DT signal


clc;
clear all;
close all;
N = input(' Enter the Number of Samples : ');
n = -N:1:N;
x = [zeros(1,N) 1 ones(1,N)];
subplot (2,1,1);
stem (n,x,'r');
xlabel ('Time');
ylabel ('Amplitude');
title ('Unit Step Response');
grid on;
Output: Enter the number of Samples : 10

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

20

f. Unit Ramp DT signal


clc;
clear all;
close all;
N = input('Enter Number of Samples : ');
a = input('Enter Amplitude : ');
n = 0:1:N;
x = a*n;
subplot (2,1,1);
stem (n,x,'r');
xlabel ('Time');
ylabel ('Amplitude');
title ('Unit Ramp Response');
grid on;
Output:

Enter Number of Samples : 50

Enter Amplitude : 1

g. Exponential DT signal
clc;
clear all;
close all;
N = input('Enter Number of Samples : ');
% EXPONENTIAL DECAYING SIGNAL
a = 0.5;
n = 0:.1:N;
x = a.^n;
subplot (2,1,1);
stem (n,x,'r');
xlabel ('Time');
ylabel ('Amplitude');
title ('Exponential Decaying Signal Response');
grid on;
%EXPONENTIAL GROWING SIGNAL
subplot (2,1,2);
x = a.^-n;
stem (n,x,'r');
xlabel ('Time');
ylabel ('Amplitude');
title ('Exponential Growing Signal Response');
grid on;
Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

21

Output: Enter Number of Samples : 5

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

22

Experiment No: 5
SAMPLING THEOREM

Aim: Write a MATLAB program to verify the Sampling theorem.


MATLAB Code:
clear all;
close all;
clc;

tf = 0.05;
t = 0 : 0.00005 : tf;
f = input ('Enter the analog frequency,f = : ');
xt = cos (2*pi*f*t);
% Under Sampling Sampling Frequency less than Nyquist rate => fs < 2f
fs1 = 1.3*f;
n1 = 0:1/fs1:tf;
xn = cos(2*pi*f*n1);
subplot (3,1,1);
plot (t,xt,'b',n1,xn,'r*-');
title ('Undersampling plot');
xlabel ('time');
ylabel ('Amplitude');
% Nyquist Sampling Sampling Frequency fs = 2f
fs2 = 2*f;
n2 = 0 : 1/fs2 : tf;
xn = cos(2*pi*f*n2);
subplot (3,1,2);
plot (t,xt,'b',n2,xn,'r*-');
title ('Nyquist plot');
xlabel ('time');
ylabel ('Amplitude');
% Over Sampling Sampling Frequency greater than Nyquist rate => fs > 2f
fs3 = 6*f;
n3 = 0 : 1/fs3 : tf;
xn = cos(2*pi*f*n3);
subplot (3,1,3);
plot (t,xt,'b',n3,xn,'r*-');
title ('Oversampling plot');
xlabel ('time');
ylabel ('Amplitude');

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

23

Output : Enter the analog frequency,f = : 200

Conclusion:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

24

Experiment No: 6
IMPULSE RESPONSE OF THE LTI SYSTEM

Aim: Write a MATLAB program to find the impulse response of a LTI system defined by a
difference equation:
y(n) + 0.7y(n-1) 0.45y(n-2) 0.6y(n-3) = 0.8x(n) 0.44x(n-1) + 0.36x(n-2) + 0.2x(n-3)
MATLAB Code:
clc;
clear all;
close all;
N = input ('Enter the required length of impulse response N = ');
n = 0 : N-1;
b = input ('Enter the co-efficients of x(n), b = ');
a = input ('Enter the co=efficients of y(n), a = ');
% Impulse response of the LTI system given by the difference equation
x = [1, zeros(1,N-1)];
y = impz (b,a,N);
subplot (2,1,1);
stem (n,y,r);
xlabel ('time');
ylabel ('amplitude');
title ('IMPULSE RESPONSE');
grid on;
% Pole Zero distribution of the LTI system given by the difference equation
subplot (2,1,2);
zplane (b,a);
xlabel ('Real part');
ylabel ('Imaginary part');
title ('Poles and Zeros of H[z] in Z-plane');
grid on;

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

25

Output :

Enter the required length of impulse response N = 40


Enter the co-efficients of x(n), b = [0.8 -0.44 0.36 0.02]
Enter the co=efficients of y(n), a = [1 0.7 -0.45 -0.6]

Exercise:
Find out the impulse response of the following difference equation and plot the pole-zero
response of the same.
1. 0.25y(n-3) + 0.7y(n-2)+y(n) = 3x(n) 0.9x(n-1) + 1.3x(n-2)
2. y(n) y(n-1) = x(n) x(n-1)

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

26

Conclusion:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

27

Experiment No: 7
FREQUENCY RESPONSE OF THE LTI SYSTEM

Aim: Write a MATLAB program to plot the Frequency response of a given LTI sequence:
y(n) 5 y(n1) = x(n) + 4 x(n1)
MATLAB Code:
b = [1, 4]; %Numerator coefficients
a = [1, -5]; %Denominator coefficients
w = -2*pi: pi/256: 2*pi;
% Frequency Response of the LTI system
[h] = freqz(b, a, w);
subplot(2, 1, 1),
plot(w, abs(h));
xlabel ('Frequency \omega'),
ylabel ('Magnitude');
grid on;
% Phase Response of the LTI system
subplot(2, 1, 2),
plot(w, angle(h));
xlabel('Frequency \omega'),
ylabel('Phase - Radians');
grid on;
Output:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

28

Exercise:
Find out the frequency response of the following difference equations.
1. 0.25y(n-3) + 0.7y(n-2)+y(n) = 3x(n) 0.9x(n-1) + 1.3x(n-2)
2. y(n) y(n-1) = x(n) x(n-1)

Conclusion:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

29

Experiment No: 8
LINEAR CONVOLUTION

Aim: Write a MATLAB program to compute linear convolution of two given sequences.
MATLAB Code:
a. Linear convolution computation (Program 1)
clear all;
close all;
clc;
x1 = input ('enter the first sequence ');
subplot (2,2,1);
stem (x1,'r');
ylabel ('amplitude');
title ('plot of the first sequence');
grid on;
x2 = input ('enter 2nd sequence ');
subplot (2,2,2);
stem (x2, 'r');
ylabel ('amplitude');
title ('plot of 2nd sequence');
grid on;
f = conv (x1,x2);
disp ('output of linear conv is');
disp (f);
subplot (2,2,3);
stem (f,'r');
xlabel ('time index n');
ylabel ('amplitude f');
title('linear conv of sequence');
grid on;

Output:
enter the first sequence [1 2 3 4]
enter 2nd sequence [2 -1 2 3]
output of linear conv is
2

6 12

Dept. of Electronics and Comm. GEC, Dahod |

8 17 12

Digital Signal Processing Lab Manual

30

b. Linear convolution computation (Program 2)


clc;
clear all;
close all;
a=input('Enter the starting point of x[n]=');
b=input('Enter the starting point of h[n]=');
x=input('Enter the co-efficients of x[n]=');
h=input('Enter the co-efficients of h[n]=');
y=conv(x,h);
subplot(3,1,1);
p=a:(a+length(x)-1);
stem(p,x,'r');
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=b:(b+length(h)-1);
stem(q,h,'r');
grid on;
Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

31

xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=a+b:length(y)+a+b-1;
stem(n,y,'r');
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('Convolution x(n)* h(n)');
Output:
Enter the starting point of x[n]=-2
Enter the starting point of h[n]=1
Enter the co-efficients of x[n]=[1 2 3 4 5]
Enter the co-efficients of h[n]=[-1 -2 1 1 2]
-1 -4 -6 -7 -6

1 15 13 10

Exercise: Find out the Convolution of other two series and find the starting point of the result.

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

32

Conclusion:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

33

Experiment No: 9
DISCRETE TIME FOURIER TRANSFORM - DTFT

Aim: Write a MATLAB program to find the Discrete Time Fourier Transform (DTFT) of the
given sequence.
MATLAB Program:

% Evaluation of the DTFT


clf;
% Compute the frequency samples of the DTFT
w = -4*pi : 8*pi/511 : 4*pi;
num = [2 1];
den = [1 -0.6];
h = freqz(num, den, w);
% Plot the DTFT
subplot(4,1,1)
plot(w,real(h));
grid on;
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(4,1,2)
plot(w,imag(h));grid
title('Imaginary part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(4,1,3)
plot(w,abs(h));grid
title('Magnitude Spectrum |H(e^{j\omega})|')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(4,1,4)
plot(w,angle(h));grid
title('Phase Spectrum arg[H(e^{j\omega})]')
xlabel('\omega /\pi');
ylabel('Phase, radians');

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

34

Output:

Exercise: Find the Fourier transform of the ( )

Dept. of Electronics and Comm. GEC, Dahod |

( )

( )

Digital Signal Processing Lab Manual

35

Conclusion:

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

36

Experiment No: 10
FIR FILTER DESIGN

Aim: Write a MATLAB program to plot magnitude response and phase response of digital FIR
Filter using Rectangular window
a. Low pass Filter
b. High pass Filter
c. Bandpass Filter
d. Bandstop Filter
MATLAB Program:

a. LOW PASS FIR Filter Designing


clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,rectwin(N+1));
freqz(h);
Output:

Enter the value of N: 5


Enter cutoff frequency: 0.5*pi

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

37

b. HIGH PASS FIR Filter Designing


clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi, high,rectwin(N+1));
freqz(h);
Output:

Enter the value of N: 28


Enter cutoff frequency: 0.5*pi

c. BAND PASS FIR Filter Designing


clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi,rectwin(N+1));
freqz(h);
Output:

Enter the value of N: 28


Enter cutoff frequency: [0.3*pi 0.7*pi]

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

38

d. BAND STOP FIR Filter Designing


clc;
clear all;
close all;
N=input('Enter the value of N:');
wc=input('Enter cutoff frequency:');
h=fir1(N,wc/pi, stop,rectwin(N+1));
freqz(h);
Output:

Enter the value of N: 28


Enter cutoff frequency: [0.2*pi 0.7*pi]

Dept. of Electronics and Comm. GEC, Dahod |

Digital Signal Processing Lab Manual

39

Hanning Window:
1.
2.
3.
4.

h=fir1(N,wc/pi,hanning(N+1));
h=fir1(N,wc/pi, high,hanning(N+1));
h=fir1(N,wc/pi,hanning(N+1));
h=fir1(N,wc/pi, stop, hanning(N+1));

Low Pass FIR Filter


High Pass FIR Filter
Band Pass FIR Filter
Band Stop FIR Filter

Hamming Window:
1.
2.
3.
4.

h=fir1(N,wc/pi,hamming(N+1));
h=fir1(N,wc/pi, high,hamming(N+1));
h=fir1(N,wc/pi,hamming(N+1));
h=fir1(N,wc/pi, stop, hamming(N+1));

Dept. of Electronics and Comm. GEC, Dahod |

Low Pass FIR Filter


High Pass FIR Filter
Band Pass FIR Filter
Band Stop FIR Filter

Digital Signal Processing Lab Manual

40

You might also like