digital signal processing file
-
Upload
vaibhavsharmaaa -
Category
Documents
-
view
226 -
download
0
Transcript of digital signal processing file
-
7/31/2019 digital signal processing file
1/39
matlabprogramming
-
7/31/2019 digital signal processing file
2/39
SUBMITTED TO:- SUBMITTED BY:-
MR. Y.P.S. MARAVIAISHWARY gaurav sharma
ROLL NO.-:ec041
-
7/31/2019 digital signal processing file
3/39
CONTENT
S.NO
.
PROGRAMME DATE OF
SUBMISSION
SIGNATURE
1. Write a program for y=exp^((1+3j)n) function
2. Write a program for the function y=1.5^n andfor different values of n.
3. Write a program for step function
4. Write a program for ramp function
5. Write a program to plot periodic function.
6. Write a program to perform convolution of twosequences
7. Write a program to find scaled signal fromgiven signal(to increase the magnitude of
following program by a factor of 2.)
8. Write a program to a causal LTI system by thediff equation y(n)=y(n-1)+y(n-2)+x(n-1) where
x(n)=input signal, y(n)=output signal, Then
find transfer function, plot the ROC, and poles
and Zeros for H(Z)=Y(Z)/X(Z).
9. W.A.P. to find inverse z transform of following2*z/(z-2)^2.
10. W.A.P. to perform folding property on givensequence.
11. W.A.P.to perform circular convolution of givensequence.
12. W.A.P to perform roots plotting
13. W.A.P to perform crosscorelation
14. W.A.P to perform FFT of given sequences
15. W.A.P to perform DFT of given sequences
-
7/31/2019 digital signal processing file
4/39
16. W.A.P to perform inverse DFT of givensequences
17. Theory of digital filters.
18. W.A.P.to find the order of low passbutterworth IIR digital filter having following
specification:fp= 1500hz
fs=1800hz
Fs=5000hz
Rp=2dB
Rs=40dB
19. W.A.P. Obtain the freq. response of low passiir butterworth filter with following
specifications:
fp= 1500Hz
fs=1800HzFs=5000Hz
Rp=2dB
Rs=40dB
20. design a type 2 cabycshev lowpass filter withfollowing specifications: fp=1200Hz
fs=1700 Hz
Fs=6000 Hz
Rp=0.5dB
Rs=50dB show magnitude and pole-zero
respose.
21. design elliptic IIR lowpass filter withfollowing specifications:show magnitude and
phase response .
fp=800Hz
fs=1000Hz
Fs=4000Hz
Rp=0.5db
Rs=40db
22. design a fir lowpass filter using hammingwindows for following specification.
Pass band edge=2rad/esc
Stop band edge=4rad/sec
Max. pass band ripplpe=0.1db
Min. stopband attenuation =4.0db
Sampling frequency =2rad/sec
-
7/31/2019 digital signal processing file
5/39
Show magnitude and phase response.23.
FUNCTIONS USED IN FILE
1. clc: clc clears all input and output from the command window display, giving you aclean screen.After using clc , you cannot use a scroll bar to see the history of
functions , but you still can use the up arrow to recall statements from the command
history.
2. disp( ): disp(text) displays text centered on the icon where text is any MATLAB
expression that evaluates to a string. Disp(text,textmode,on)allows you to use TeXformatting command in the text.The TeX formatting commands in turn allows you to
include symbols and greek letters in icon text.
3. length( ): The statement length(X) is equivalent to max(size(X)) for non-emptyarrays and zero for empty arrays.n=length(X) returns the size of the longest dimension
of X.If X is a vector , this is the same as its length.
4. stem( ): stem(X,Y) plots X v/s the columns of Y.X and Y must be vectors ormatrices of the same size. Additionally , X can be a row or a column vector and Y a
matrix with length(X) rows.
5. subplot( ): subplot divides the current figure into a rectangular planes that arenumbered rowwise . Each plane contains an axes object. Subsequent plots are output to
the current plane. h= subplot(m,n,p) or subplot(mnp) breaks the figure window into anm by-n matrix os small axes , selects the path axes object for the current plt, and
returns the axes handle. The axes are counted along the top row of the figure window ,
then the second row, etc.
6. conv( ): 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 uand v.
7. Zplane( ): This function displays the poles and zeroes of discrete time systems .Zplane(z,p) plots the zeroes specified in column vector z and the poles specified in
column vector p in the current figure window. The symbol O represents a zero and
the symbolx represents a pole. The plot includes the unit circle for reference. If z and
-
7/31/2019 digital signal processing file
6/39
p are arrays , Zplane plots the poles and zeroes in the columns of z and p in different
colours.
8. Title( ): Each axes graphics object can have one title . The title is located at the topand in the center of the axes . Title(string) outputs the string at the top and in thecenter of the current axes.
9. Fft( ): Y=fft(X) returns the discrete fourier transform (DFT) of vector X , computedwith the fast fourier transform algorithm.If X is a matrix , then FFT returns the fourier
transform of each column of the matrix. IF X is the multidimensional array , Fft
operates on the non singleton dimension . Y=fft(X,[],dim) and Y=fft(X,n,dim) applies
the FFT operation across the dimension dim.
10. Ifft( ): Y= ifft(X) returs they inverse discrete fourier transform( DFT) of vector X,computed with a fast fourier transform(FFT) algorithm. If X is a matrix, ifft returns the
inverse DFT of each column of the matrix.
-
7/31/2019 digital signal processing file
7/39
Q-1) Write a program for y=exp^((1+3j)n) function.
Editor window:
n=0:1:5;
y=exp((1+(j*.3))*n)
stem(n,y);
Command window:-
y =1.0e+002 *Columns 1 through 5
0.0100 0.0260 + 0.0080i 0.0610 + 0.0417i 0.1249 +0.1573i
0.1978 + 0.5089i
Column 6
0.1050 + 1.4804i
Output:-
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 50
2
4
6
8
10
12
14
16
18
20
-
7/31/2019 digital signal processing file
8/39
Q-2) Write a program for the function y=1.5^n and for different values of n.
Editor window:
n=[-8:8]
x=1.5.^n;
stem(n,x);
Command window:
n =
-8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8
Output:-
-8 -6 -4 -2 0 2 4 6 80
5
10
15
20
25
30
-
7/31/2019 digital signal processing file
9/39
Q-3) Write a program for step function.
Solution:
Editor window:
n=5;
t=0:1:n-1;
y=ones(1,n);
stem(t,y);
Output:-
-
7/31/2019 digital signal processing file
10/39
0 0.5 1 1.5 2 2.5 3 3.5 40
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
1
Q-4) Write a program for ramp function.
Solution:
Editor window :
n=5;t=0:1:n-1;
y=t;
stem(t,y);
Output:-
-
7/31/2019 digital signal processing file
11/39
0 0.5 1 1.5 2 2.5 3 3.5 40
0.5
1
1.5
2
2.5
3
3.5
4
Q-5) Write a program to plot periodic function.
Solution:
Editor window :
clc;
disp('to plot periodic func');n=0:1:40;
y1=sin(2*3.14*50*n);
subplot(2,1,1);
stem(n,y1)
y2=cos(2*3.14*50*n);
subplot(2,1,2);
-
7/31/2019 digital signal processing file
12/39
stem(n,y2)
output:
0 5 10 15 20 25 30 35 40-1
-0.5
0
0.5
1
0 5 10 15 20 25 30 35 40-1
-0.5
0
0.5
1
Q-6) Write a program for convolution.
Editor window :
b=[1 1 1]
a=[1 2 3]
C=conv(b,a)
stem(C);
Command window:-
b =1 1 1
a = 1 2 3
C =1 3 6 5 3
-
7/31/2019 digital signal processing file
13/39
Output:-
1 1.5 2 2.5 3 3.5 4 4.5 50
1
2
3
4
5
6
Q-7) Write a program to find scaled signal from given signal(to increase the
magnitude of following program by a factor of 2.)
Solution:
Editor window:
x=[2 -1 4 3 1];
z=2.*x;
subplot(2,1,1);
stem(x,'fill');
title('simple signal')
subplot(2,1,2);
stem(z,'fill')
title('scaled signal')
-
7/31/2019 digital signal processing file
14/39
Output:-
1 1.5 2 2.5 3 3.5 4 4.5 5-2
0
2
4simplesignal
1 1.5 2 2.5 3 3.5 4 4.5 5-5
0
5
10scaledsignal
Q.8) Write a program to a causal LTI system by the diff equation y(n)=y(n-
1)+y(n-2)+x(n-1) where x(n)=input signal, y(n)=output signal, Then find
transfer function, plot the ROC, and poles and Zeros for H(Z)=Y(Z)/X(Z).
Solution:
Editor window:
b=input('enter the coefficient of the numerator');
a=input('enter the coefficient of dnominator');
zplane(b,a);
command window:
enter the coefficient of the numerator[1]
enter the coefficient of dnominator[1 -1 -1]
Y(Z)=Z-1 Y(Z)+ Z-2Y(Z) + Z-1 X(Z)
Y(Z)[1-Z-1-Z-2]=Z-1X(Z)
As we know that : H(Z)=Y(Z)/X(Z)
Hence :
-
7/31/2019 digital signal processing file
15/39
H(Z)= Z-1 /(1-Z-1-Z-2 )
The funtion is causal,
Q-9) find inverse z transform of following 2*z/(z-2)^2
Editor window:
g = 2*z/(z-2)^2
d=iztrans(g)
command window:
d =2^n*n
-
7/31/2019 digital signal processing file
16/39
Q-10) write a programme to perform folding property on given sequence.
Editor window:
x=input ('enter the given sequence in sqaure brakets');
n1=input ('enter the lower limit of the sequence');
n2=input('enter the upper limit of the sequence');
n=[n1:n2];
m=-fliplr(n);
z=fliplr(x)
disp('the instants of the sequences are:');
disp(n);
disp('the given sequence as:');disp(x);
disp('the instants of the folded sequence are:');
disp(m);
disp('the folded sequence as:');
disp(z);
subplot(2,1,1);
-
7/31/2019 digital signal processing file
17/39
stem(n,x,'fill')
title('given signal');
subplot(2,1,2);
stem(m,z,'fill')
title('folded signal');
command window:
enter the given sequence in sqaure brakets[-3 -2 -1 1 2 3]
enter the lower limit of the sequence-3
enter the upper limit of the sequence2
z =3 2 1 -1 -2 -3
the instants of the sequences are:
-3 -2 -1 0 1 2
the given sequence as:
-3 -2 -1 1 2 3
the instants of the folded sequence are:
-2 -1 0 1 2 3
the folded sequence as:
3 2 1 -1 -2 -3
-
7/31/2019 digital signal processing file
18/39
-3 -2.5 -2 -1.5 -1 -0.5 0 0.5 1 1.5 2-4
-2
0
2
4givensignal
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3-4
-2
0
2
4foldedsignal
Q.11)write a programme to perform circular convolution of given sequence.
Editor window:
x=input('enter the first sequence');
h=input('enter the second sequence');
-
7/31/2019 digital signal processing file
19/39
y=cconv(x,h,4)
stem(y)
command window:
enter the first sequence[1 1 2 2]
enter the second sequence[1 2 3 4]
y =
15 17 15 13
1 1.5 2 2.5 3 3.5 40
2
4
6
8
10
12
14
16
18
Q.12)write a programme to perform roots plotting of given sequence .
Editor window:
P=[1 -6 -72 -27]
r=roots(P);
stem(r);
title('roots plotting')
-
7/31/2019 digital signal processing file
20/39
Output : -
Q. 13)wap to perform crosscorrelation of sequences.
Editor window:
a=[1 4 6 3];
y=[3 7 1 5];
z=xcorr(a,y)
stem(z);
-
7/31/2019 digital signal processing file
21/39
OUTPUT: -
Q. 14)wap to perform FFT of sequence.
Editor window:
x=[0 1 2 3 4 5 6 7];
a=fft(x,8)
stem(a);
Command window:
-
7/31/2019 digital signal processing file
22/39
a = Columns 1 through 4
28.0000 -4.0000 + 9.6569i -4.0000 + 4.0000i -4.0000 + 1.6569i
Columns 5 through 8
-4.0000 -4.0000 - 1.6569i -4.0000 - 4.0000i -4.0000 - 9.6569i
OUTPUT:
Q. 15)wap to perform DFT of sequence.
Editor window:
x=input('enter the given sequence in square brackets:');
disp(x);
A=x*dftmtx(4)
Stem(A);
-
7/31/2019 digital signal processing file
23/39
Command window:
enter the given sequence in square brackets:[1 2 3 4]1 2 3 4
A = Columns 1 through 3
10.0000 -2.0000 + 2.0000i -2.0000
Column 4
-2.0000 - 2.0000i
OUTPUT:
Q. 16) WAP to perform inverse DFT of given sequence.
Editor window:
X=input('enter the given seq in sqaure brackets');
disp(X);
N=length(X);
Ai=conj(dftmtx(N))/N;
-
7/31/2019 digital signal processing file
24/39
y=X*Ai
command window:
enter the given seq in sqaure brackets[1 0 1 0]
1 0 1 0
y =
0.5000 0 0.5000 0
Q.17) Theory of digital filters:
Digital filter can be classified as :
1. finite duration impulse response (FIR)
-
7/31/2019 digital signal processing file
25/39
2. infinite duration impulse response(IIR).
IIR filter further can classified as :
1. Butterworth
2. Chebyshev type 1
3. Chebyshev type 2
4. Elliptical filter
COMMENT LINE:
To calculate the order of the filter:
[N,Wn]= butterworth(Wp,Ws,Rp,Rs)edge
[N,Wp]=cheb1ord(Wp,Ws,Rp,Rs)
[N,Ws]=cheb2ord(Wp,Ws,Rp,Rs)[N,Wp]=ellipord(Wp,Ws,Rp,Rs)
where Wp and Ws are edge frequencies for pass band and
stop band resp. normalized from 0-1 ,
Rp is pass band ripple ,
N is the order of the filter,
Rs is stop band attenuation in dB, Wn is length 2 -vector
fp and fs are passband and stopband frequencies
Wp=(2*fp/Fs)
Ws=(2*fs/Fs)
Q.18) Find the order of low pass butterworth IIR digital filter having following
specification: fp= 1500hz
fs=1800hz
Fs=5000hz
Rp=2dB
Rs=40dB
-
7/31/2019 digital signal processing file
26/39
Editor window:
fp=1500;
fs=1800 ;
Fs=5000;
Rp=2;
Rs=40;
Wp=(2*fp/Fs);
Ws=(2*fs/Fs);
[N,Wn]= buttord(Wp,Ws,Rp,Rs)
fprintf('order of the filter:%f\n',N);
command window:
N =12
Wn = 0.6152
order of the filter:12.000000
NOTE:
In case of lowpass and high pass filter the frequency scaling factorWn is having only one value whereas for passband and stopband
filter Wn is length 2-vector and N is the half the order of the filter
to be designed .
[b,a]= filter coefficent of length N+1 ,
vector b gives numerator and
vector a gives denominator values in desending power of z.
-
7/31/2019 digital signal processing file
27/39
[b,a]=butter(N,Wn)
[b,a]=cheb1(N,Rp,Wp)
[b,a]=cheb2(N,Rs,Ws)
[b,a]=ellip(N,Rp,Rs,Wp)
Q.19)Obtain the freq. response of low pass iir butterworth filter with
following specifications:fp= 1500Hz
fs=1800Hz
Fs=5000Hz
Rp=2dB
Rs=40dB
-
7/31/2019 digital signal processing file
28/39
Editor window: fp=1500;
fs=1800 ;
Fs=5000;
Rp=2;
Rs=40;
Wp=(2*fp/Fs);
Ws=(2*fs/Fs);
[N,Wn]= buttord(Wp,Ws,Rp,Rs)
fprintf('order of the filter:%f\n',N);
[b,a]=butter(N,Wn)
freqz(b);
command window:
N =12
Wn =0.6152
order of the filter:12.000000
b =Columns 1 through 7
0.0064 0.0772 0.4248 1.4158 3.1856 5.0970 5.9465
Columns 8 through 13
5.0970 3.1856 1.4158 0.4248 0.0772 0.0064
a =Columns 1 through 7
1.0000 2.7575 4.9313 5.8618 5.2618 3.5782 1.8938
Columns 8 through 13
0.7714 0.2398 0.0550 0.0088 0.0009 0.0000
-
7/31/2019 digital signal processing file
29/39
OUTPUT:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-1500
-1000
-500
0
NormalizedFrequency (
rad/sample)
Phase(deg
rees)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-400
-200
0
200
NormalizedFrequency ( rad/sample)
Magnitude
(dB)
Q.20) design a type 2 cabycshev lowpass filter with following specifications:
fp=1200Hzfs=1700 Hz
Fs=6000 Hz
Rp=0.5dB
Rs=50dB show magnitude and pole-zero respose.
COMMAND WINDOW:
-
7/31/2019 digital signal processing file
30/39
-
7/31/2019 digital signal processing file
31/39
0 0.5 1 1.5 2 2.5
-60
-50
-40
-30
-20
-10
0
Frequency(kHz)
Magnitude(dB)
MagnitudeResponse(dB)
-1.5 -1 -0.5 0 0.5 1 1.5
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Real Part
ImaginaryPart
Pole/ZeroPlot
-
7/31/2019 digital signal processing file
32/39
0 0.5 1 1.5 2 2.5-8
-7
-6
-5
-4
-3
-2
-1
0
Frequency(kHz)
Phase(radians)
PhaseResponse
0 0.5 1 1.5 2 2.5
-60
-50
-40
-30
-20
-10
0
Frequency(kHz)
Magnitude(dB)
Magnitude(dB) andPhaseResponses
-7.0524
-5.8872
-4.7219
-3.5567
-2.3914
-1.2261
-0.0609
Phase(radians)
-
7/31/2019 digital signal processing file
33/39
0 0.5 1 1.5 2 2.5
2
3
4
5
6
7
8
9
10
Frequency(kHz)
Groupdelay(insamples)
GroupDelay
0 0.5 1 1.5 2 2.5
0
0.5
1
1.5
2
2.5
3
3.5
4
Frequency(kHz)
PhaseDelay(radians/Hz)
PhaseDelay
-
7/31/2019 digital signal processing file
34/39
0 1 2 3 4 5 6 7 8 9
-0.2
-0.1
0
0.1
0.2
0.3
0.4
Time(mseconds)
Amplitude
ImpulseResponse
0 1 2 3 4 5 6 7 8 90
0.2
0.4
0.6
0.8
1
1.2
Time(mseconds)
Amplitude
StepResponse
-
7/31/2019 digital signal processing file
35/39
0 0.5 1 1.5 2 2.5
-260
-250
-240
-230
-220
-210
-200
-190
Frequency(kHz)
Power/frequency(dB/Hz)
Round-off NoisePowerSpectrum
-
7/31/2019 digital signal processing file
36/39
Q.21) Design elliptic IIR lowpass filter with following specifications show
magnitude and phase response .
fp=800Hz
fs=1000Hz
Fs=4000Hz
Rp=0.5db
Rs=40db
Solution:
Editor window:
fp=800;
fs=1000;
Fs=4000;Rp=0.5;
Rs=40;
Wp=2*fp/Fs;
Ws=2*fs/Fs;
[N,Wn]= ellipord(Wp,Ws,Rp,Rs)fprintf('order of the filter:%f\n',N);
[b,a]=ellip(N,Rp,Rs,Wp)
freqz(b);
Command window: N =5
Wn= 0.4000
order of the filter:5.000000
b = 0.0528 0.0797 0.1295 0.1295 0.0797 0.0528
a = 1.0000 -1.8107 2.4947 -1.8801 0.9537 -0.2336
-
7/31/2019 digital signal processing file
37/39
Output:
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-300
-200
-100
0
100
NormalizedFrequency (
rad/sample)
Phase(degrees)
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-150
-100
-50
0
NormalizedFrequency (
rad/sample)
Magnitude(d
B)
-
7/31/2019 digital signal processing file
38/39
Q.22) Design a fir lowpass filter using hamming windows for following
specification.
Pass band edge=2rad/esc
Stop band edge=4rad/sec
Max. pass band ripplpe=0.1db
Min. stopband attenuation =4.0db
Sampling frequency =2rad/sec
Show magnitude and phase response.
Solution:
Editor window: fs=20;
f=[2 ,4];
a=[1,0];
Rp=0.1;Rs=40;
%calculate allowable deviation or ripple
dp=1-10^(-Rp/20);
ds=1-10^(-Rs/20);
dev=[dp ds];
%calculate order
[n,f0,a0,w]=firpmord(f,a ,dev,fs)
freqz(f0)
command window:
n = 7
f0 = 0
0.2000
0.4000
1.0000
a0 = 1
1
0
0w =86.4863
1.0
-
7/31/2019 digital signal processing file
39/39