You are on page 1of 31

S.U.S.

WOMEN ENGINEERING COLLEGE TANGORI (MOHALI)

LAB FILE
Digital Signal Processing Using Mat Lab 7.1 Submitted to: Er.Aarti Submitted by: Hina Pradip Sangai 81003108013 6th Semester Branch-ECE

Hina Pradip Sangai

81003108013

List of Experiments
1. Introduction about Mat lab. 2. To develop sine and cosine function waveforms. 3. To develop elementary signals: Unit step signal, unit ramp signal,
unit impulse signal, exponential signal.

4. Develop program modules based on operation on sequences like:


Signal addition, Signal multiplication, Signal folding, Signal Shifting.

5. To develop program to perform linear convolution of two input


Sequence x(n) and h(n). Plot x(n) and h(n) and result of linear convolution as y(n)on single plot and verify the result mathematically. 6. To obtain the impulse response of the system described by difference equation: y(n)-0.5y(n-1)=x(n) 7. Write a program to determine and plot poles and zeroes of rational Z-transform given as:- H(z)=(5+z )(3+z )
-1 -1

- -----------------(2+z-1)(4+z-1)

8.

To develop program for computing DFT and IDFT. system described by difference equation : y(n)=0.8y(n-2)+x(n)-x(n-2)

9. To develop program for finding magnitude and phase response of LTI

10.

To design an IIR filter with following specifications using filter design and analysis toolbox
Response type: Low pass filter Design method: IIR Butterworth filter Filter order: Minimum Match exactly: Stop band Frequency specifications: Units=KHz Fs=500 Fpass=100 Fstop=150 Magnitude specifications: Units=dB

Hina Pradip Sangai


Apass=3 Astop=1

81003108013

Hina Pradip Sangai

81003108013

EXPERIMENT-1

INTRODUCTION ABOUT MATLAB


MATLAB is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include: Math and computation Algorithm development Data acquisition Modeling, simulation and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building

MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar noninteractive language such as C or Fortran. The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation.

Desktop Overview
Use desktop tools to manage your work in MATLAB. You can also use MATLAB functions to perform the equivalent of most of the features found in the desktop tools. The following illustration shows the default configuration of the MATLAB desktop. You can modify the setup to meet your needs.

Hina Pradip Sangai

81003108013

The MATLAB System


The MATLAB system consists of five main parts: Desktop Tools and Dvelopment Environment. This is the set of tools and facilities that help you use MATLAB functions and files. Many of these tools are graphical user interfaces. It includes the MATLAB desktop and Command Window, a command history, an editor and debugger, and browsers for viewing help, the workspace, files, and the search path. The MATLAB Mathematical Function Library. This is a vast collection of computational algorithms ranging from elementary functions, like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms. The MATLAB Language. This is a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. It allows both "programming in the small" to rapidly create quick and dirty throw-away programs, and "programming in the large" to create large and complex application programs. Graphics. MATLAB has extensive facilities for displaying vectors and matrices as graphs, as well as annotating and printing these graphs. It includes high-level functions

Hina Pradip Sangai

81003108013

for two-dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. It also includes low-level functions that allow you to fully customize the appearance of graphics as well as to build complete graphical user interfaces on your MATLAB applications. The MATLAB External Interfaces/API. This is a library that allows you to write C and Fortran programs that interact with MATLAB. It includes facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files.

Programming:
Flow Control: MATLAB has several flow control constructs: if, else, and elseif switch and case for while continue break try - catch return Several special functions provide values of useful constants:

Hina Pradip Sangai

81003108013

Operators
Expressions use familiar arithmetic operators and precedence rules.

Hina Pradip Sangai

81003108013

EXPERIMENT-2 % Develop sine and cosine function waveforms


t=linspace(0,10,100); y=sin(pi*t); plot(t,y); y2=cos(pi*t); hold on plot(t,y2,'red'); xlabel('time'); ylabel('amplitude'); title('sine and cosine waveforms');

Hina Pradip Sangai

81003108013

WAVEFORMS:-

sine and cosine waveforms 1 0.8 0.6 0.4 0.2 amplitude 0 -0.2 -0.4 -0.6 -0.8 -1

5 time

10

Hina Pradip Sangai

81003108013

EXPERIMENT-3
% Develop elementary signals: 1) Unit step signal 2) unit ramp signal 3) unit impulse signal 4) exponential signal.
t=-3:1:3; y=[zeros(1,3),ones(1,4)]; subplot(2,2,1); stem(t,y); xlabel('time'); ylabel('amplitude'); title('unit step function'); t1=-4:1:4; y1=t1; subplot(2,2,2); stem(t1,y1); xlabel('time'); ylabel('amplitude'); title('unit ramp function'); t2=-3:1:3; y2=[zeros(1,3),1,zeros(1,3)]; subplot(2,2,3); stem(t2,y2); xlabel('time'); ylabel('amplitude'); title('unit impulse function'); t3=-5:1:5; y3=exp(t3); subplot(2,2,4); stem(t3,y3); xlabel('time'); ylabel('amplitude'); title('exponential function');

10

Hina Pradip Sangai

81003108013

WAVEFORMS:-

unit step function 1 4 2 amplitude 0.5 amplitude 0 -2 -4 -4

unit ramp function

0 -4

0 2 time unit impulse function

-2

0 2 time exponential function

-2

150

amplitude

0.5

amplitude -2 0 time 2 4

100

50

0 -4

0 -5

0 time

11

Hina Pradip Sangai

81003108013

EXPERIMENT-4
%Develop program modules based on operation on sequences like: 1) Signal addition 2) Signal multiplication 3) Signal folding 4) Signal shifting
t=0:1:5; x=[1,2,3,4,5,6]; subplot(4,3,1); stem(t,x); xlabel('time'); ylabel('amplitude'); title('x sequence'); t1=0:1:5; y=[0,-1,1,2,3,2]; subplot(4,3,2); stem(t1,y); xlabel('time'); ylabel('amplitude'); title('y sequence'); z=x+y; subplot(4,3,3); stem(z); xlabel('time'); ylabel('amplitude'); title('addition of x and y sequence'); t2=0:1:5; x1=[1,2,3,4,5,6]; subplot(4,3,4); stem(t2,x1); xlabel('time'); ylabel('amplitude'); title('x sequence'); t3=0:1:5; y1=[0,1,1,2,3,2]; subplot(4,3,5); stem(t3,y1); xlabel('time'); ylabel('amplitude'); title('y sequence'); z1=x.*y; subplot(4,3,6); stem(z1); xlabel('time'); ylabel('amplitude'); title('multiplication of x and y sequence'); t4=0:1:5; x2=[1,2,3,4,5,6]; subplot(4,3,7);

12

Hina Pradip Sangai


stem(t4,x2); xlabel('time'); ylabel('amplitude'); title('x sequence'); z2=-x2; subplot(4,3,8); stem(t4,z2); xlabel('time'); ylabel('amplitude'); title('folding of x sequence'); t5=0:1:5; t5=-t4; subplot(4,3,9); stem(t5,x2); xlabel('time'); ylabel('amplitude'); title('folding of x sequence'); t6=0:1:5; x3=[1,2,3,4,5,6]; subplot(4,3,10); stem(t6,x3); xlabel('time'); ylabel('amplitude'); title('x sequence'); t7=0:1:6; t7=t6-1; subplot(4,3,11); stem(t7,x3); xlabel('time'); ylabel('amplitude'); title('shifting of x sequence'); t8=0:1:6; t8=t6+1; subplot(4,3,12); stem(t8,x3); xlabel('time'); ylabel('amplitude'); title('shifting of x sequence');

81003108013

13

Hina Pradip Sangai

81003108013

WAVEFORMS:-

x sequence 10 am plitude 5 0 0 5 am plitude 5 0 -5 0

y s e q u e n c e a d d it io n o f x a n d y s e q u e n c e 10 am plitude am plitude 5 0 0

t im e x sequence 10 am plitude 5 0 0 5 t im e x sequence 10 am plitude 5 0 0 5 am plitude am plitude 4 2 0 0

5 10 tim e tim e y s e q u e n c m u lt ip lic a t io n o f x a n d y s e q u e n c e e 20 am plitude 0 -2 0 0

5 10 tim e tim e f o l d i n g o f x s e q u e f n c dei n g o f x s e q u e n c e ol 0 10 -5 5 0 -4

-1 0 0

t im e x sequence 10 am plitude am plitude 5 0 0 t im e 5

-2 0 tim e tim e s h i f t i n g o f x s e q u e n c f tei n g o f x s e q u e n c e shi 10 10 5 0 -5 0 tim e 5 am plitude 5 0 0 5 tim e 10

14

Hina Pradip Sangai

81003108013

EXPERIMENT-5
%To develop program to perform linear convolution of two input sequence x(n) and h(n). Plot x(n) and h(n) and result of linear convolution as y(n)on single plot and verify the result mathematically.
t=0:1:4; x=input('enter x(n) sequence'); subplot(3,1,1); stem(t,x); xlabel('time'); ylabel('amplitude'); title('x sequence'); t1=0:1:2; h=input('enter h(n) sequence'); subplot(3,1,2); stem(t1,h); xlabel('time'); ylabel('amplitude'); title('h sequence'); t2=0:1:6; y=conv(x,h); subplot(3,1,3); stem(t2,y); xlabel('time'); ylabel('amplitude'); title('convolution of x and h sequence');

Result on command window:


enter x(n) sequence[1 2 3 4 5] enter h(n) sequence[ 1 2 3]

15

Hina Pradip Sangai

81003108013

16

Hina Pradip Sangai

81003108013

WAVEFORMS:-

x s equenc e 5 am plitude

0 .5

1 .5

2 2 .5 t im e h s equenc e

3 .5

4 am plitude 2 0 0 0 .2 0 .4 0 .6 1 1 .2 1 .4 1 .6 1 .8 2 t im e c o n vo lu t io n o f x a n d h s e q u e n c e 0 .8

40 am plitude 20 0 0 1 2 3 t im e 4 5 6

17

Hina Pradip Sangai

81003108013

EXPERIMENT-6 %To obtain the impulse response of the system described by difference equation y(n)-0.5y(n-1)=x(n)
x=[ones(1,1),zeros(1,9)] a=input('enter the coeff. of y(n)') b=input('enter the coeff. of x(n)') h=filter(b,a,x) n=0:9 stem(n,h) title('impulse response of the system') xlabel('n') ylabel('h(n)')

Result on command window:enter the coeff. of y(n)[1 a = 1.0000 -0.5000 -0.5]

enter the coeff. of x(n)[1] b = 1 h = 1.0000 0.5000 0.2500 0.0078 0.0039 0.0020 n = 0 1 2 3 4 5 6 7 8 9 0.1250 0.0625 0.0313 0.0156

18

Hina Pradip Sangai

81003108013

WAVEFORMS:-

impulse response of the system 1 0.9 0.8 0.7 0.6 h(n) 0.5 0.4 0.3 0.2 0.1 0

4 n

19

Hina Pradip Sangai

81003108013

EXPERIMENT-7
%Write a program to determine and plot poles and zeroes of rational z-transform given as H(z)= 15 z2 + 8 z + 1 --------------8 z2 + 6 z + 1 or H(z)=(5+z-1)(3+z-1) ----------(2+z-1)(4+z-1)

a=input('enter the coefficients of num.') b=input('enter the coefficients of den.') c=tf(a,b,1) [z p]=tf2zp(a,b) zplane(z,p) [r,p,k]=residuez(a,b) [num,den]=residuez(r,p,k)

Result on command window:enter the coefficients of num.[15 8 1] a= 15 8 1

enter the coefficients of den.[8 6 1] b= 8 6 1 1

Transfer function: 15 z^2 + 8 z + 1 ---------------8 z^2 + 6 z + 1 Sampling time: 1 z= -0.3333 -0.2000 p=

20

Hina Pradip Sangai


-0.5000 -0.2500 r= 0.7500 0.1250 p= -0.5000 -0.2500 k= 1 num = 1.8750 den = 1.0000 0.7500 0.1250 1.0000 0.1250

81003108013

21

Hina Pradip Sangai

81003108013

POLE-ZERO PLOT:-

1 0.8 0.6 0.4 Imaginary Part 0.2 0 -0.2 -0.4 -0.6 -0.8 -1 -1 -0.5 0 Real Part 0.5 1

22

Hina Pradip Sangai

81003108013

EXPERIMENT-8
%To develop program for computing DFT and IDFT
clc; x=input('ENTER A SEQUENCE TO FIND DFT'); N=8; X=fft(x,N); a=ifft(X);

23

Hina Pradip Sangai

81003108013

Result on the command window:ENTER A SEQUENSE TO FIND DFT[1 2 3 4 5] N= 8 X= Columns 1 through 6 15.0000 -5.4142 - 7.2426i 3.0000 + 2.0000i -2.5858 - 1.2426i 3.0000 -2.5858 + 1.2426i Columns 7 through 8 3.0000 - 2.0000i -5.4142 + 7.2426i a= 1.0000 2.0000 3.0000 4.0000 5.0000 -0.0000 0 -0.0000

24

Hina Pradip Sangai

81003108013

EXPERIMENT-9
% To develop program for finding magnitude and phase response of LTI system described by difference equation y(n)=0.8y(n-2)+x(n)-x(n-2)
clc; b=input('enter the coeff. of x(n)'); a=input('enter the coeff. of y(n)'); N=200; [H,W]=freqz(b,a,N); subplot(2,1,1); absH=abs(H); angH=angle(H); plot(W,absH); xlabel('W'); ylabel('abs H'); title('LTI magnitude'); subplot(2,1,2); plot(W,angH); xlabel('W'); ylabel('angle H'); title('LTI angle');

Result on command window:


enter the coeff. of x(n)[1 0 -1] enter the coeff. of y(n)[1 0 -0.81]

25

Hina Pradip Sangai

81003108013

WAVEFORMS:LTI magnitude 1.5

1 abs H

0.5

0.5

1.5 W LTI angle

2.5

3.5

2 1 angle H 0 -1 -2

0.5

1.5 W

2.5

3.5

26

Hina Pradip Sangai

81003108013

EXPERIMENT-10
% To design an IIR filter with following specifications using filter design and analysis toolbox Response type: Low pass filter Design method: IIR Butterworth filter Filter order: Minimum Match exactly: Stop band Frequency specifications: Units=KHz Fs=500 Fpass=100 Fstop=150 Magnitude specifications: Units=dB Apass=3 Astop=16

27

Hina Pradip Sangai

81003108013

Current Filter Information:

Magnitude Resoponse:

28

Hina Pradip Sangai

81003108013

Phase Response:

Impulse Response:

29

Hina Pradip Sangai

81003108013

Step Response:

Generated MATLAB Code:30

Hina Pradip Sangai

81003108013

%EXP10 Returns a discrete-time filter object. % % M-File generated by MATLAB(R) 7.1 and the Signal Processing Toolbox 6.4. % % Generated on: 23-Apr-2009 13:55:23 % % Butterworth Lowpass filter designed using FDESIGN.LOWPASS. % All frequency values are in kHz. Fs = 500; % Sampling Frequency Fpass Fstop Apass Astop match = = = = = 100; 150; 3; 16; 'stopband'; % % % % % Passband Frequency Stopband Frequency Passband Ripple (dB) Stopband Attenuation (dB) Band to match exactly

% Construct an FDESIGN object and call its BUTTER method. h = fdesign.lowpass(Fpass, Fstop, Apass, Astop); Hd = butter(h, 'MatchExactly', match); % [EOF]

31

You might also like