Professional Documents
Culture Documents
LAB FILE
Digital Signal Processing Using Mat Lab 7.1 Submitted to: Er.Aarti Submitted by: Hina Pradip Sangai 81003108013 6th Semester Branch-ECE
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.
- -----------------(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)
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
81003108013
81003108013
EXPERIMENT-1
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.
81003108013
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:
81003108013
Operators
Expressions use familiar arithmetic operators and precedence rules.
81003108013
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
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
81003108013
WAVEFORMS:-
0 -4
-2
-2
150
amplitude
0.5
amplitude -2 0 time 2 4
100
50
0 -4
0 -5
0 time
11
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
81003108013
13
81003108013
WAVEFORMS:-
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
-1 0 0
14
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');
15
81003108013
16
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
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)')
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
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
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)
20
81003108013
21
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
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
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
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');
25
81003108013
1 abs H
0.5
0.5
2.5
3.5
2 1 angle H 0 -1 -2
0.5
1.5 W
2.5
3.5
26
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
81003108013
Magnitude Resoponse:
28
81003108013
Phase Response:
Impulse Response:
29
81003108013
Step Response:
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