DSP MATLAB Assignments

download DSP MATLAB Assignments

of 134

Transcript of DSP MATLAB Assignments

  • 7/27/2019 DSP MATLAB Assignments

    1/134

  • 7/27/2019 DSP MATLAB Assignments

    2/134

    DISCLAIMER: While the document has attempted to make the information as accurate as possible, the information on this document is for personal and/or

    educational use only and is provided in good faith without any express or implied warranty. There is no guarantee given as to the accuracy or currency of any

    individual items. The document does not accept responsibility for any loss or damage occasioned by use of the information contained and acknowledgescredit of author(s) where ever due. While the document makes every effort to ensure the availability and integrity of its resources, it cannot guarantee that

    these will always be available, and/or free of any defects, including viruses. Users should take this into account when accessing the resources. All access and

    use is at the risk of the user and owner reserves that right to control or deny access.

    Digital Signal Processing MATLAB Notes, First Edition

    Copyright 2013 Akshansh

    ALL RIGHTS RESERVED.

    Presented by: Akshansh Chaudhary

    Graduate of BITS Pilani, Dubai Campus

    Batch of 2011

    Course content by: Dr. R. Mary Lourde

    Then Faculty, BITS Pilani, Dubai Campus

    Layout design by: AC Creations 2013

    The course content was prepared during Fall, 2013.

    More content available at:www.Akshansh.weebly.com

    http://www.akshansh.weebly.com/http://www.akshansh.weebly.com/http://www.akshansh.weebly.com/http://www.akshansh.weebly.com/
  • 7/27/2019 DSP MATLAB Assignments

    3/134

    MATLAB BASICS

    Digital Signal Processing

  • 7/27/2019 DSP MATLAB Assignments

    4/134

  • 7/27/2019 DSP MATLAB Assignments

    5/134

  • 7/27/2019 DSP MATLAB Assignments

    6/134

  • 7/27/2019 DSP MATLAB Assignments

    7/134

  • 7/27/2019 DSP MATLAB Assignments

    8/134

  • 7/27/2019 DSP MATLAB Assignments

    9/134

  • 7/27/2019 DSP MATLAB Assignments

    10/134

  • 7/27/2019 DSP MATLAB Assignments

    11/134

  • 7/27/2019 DSP MATLAB Assignments

    12/134

  • 7/27/2019 DSP MATLAB Assignments

    13/134

  • 7/27/2019 DSP MATLAB Assignments

    14/134

  • 7/27/2019 DSP MATLAB Assignments

    15/134

  • 7/27/2019 DSP MATLAB Assignments

    16/134

  • 7/27/2019 DSP MATLAB Assignments

    17/134

  • 7/27/2019 DSP MATLAB Assignments

    18/134

  • 7/27/2019 DSP MATLAB Assignments

    19/134

    MATLAB Assignment 1Digital Signal Processing

  • 7/27/2019 DSP MATLAB Assignments

    20/134

  • 7/27/2019 DSP MATLAB Assignments

    21/134

  • 7/27/2019 DSP MATLAB Assignments

    22/134

  • 7/27/2019 DSP MATLAB Assignments

    23/134

  • 7/27/2019 DSP MATLAB Assignments

    24/134

  • 7/27/2019 DSP MATLAB Assignments

    25/134

  • 7/27/2019 DSP MATLAB Assignments

    26/134

  • 7/27/2019 DSP MATLAB Assignments

    27/134

  • 7/27/2019 DSP MATLAB Assignments

    28/134

  • 7/27/2019 DSP MATLAB Assignments

    29/134

  • 7/27/2019 DSP MATLAB Assignments

    30/134

  • 7/27/2019 DSP MATLAB Assignments

    31/134

    !"#$%$ ($%)*$%+,

    -.//!!012..3

    45657%8 156&%8 0+9:;##5&6 ;&7 /

    Butterworth filter

    Instructions -[N1,Wn1]=buttord([1200 1800],[800 2200],0.5,30,'s')[B1,A1]=butter(N1,Wn1,'s')[h1,f1]=freqs(B1,A1)plot(f1,h1)plot(f1,20*log10(abs(h1)))

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    32/134

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    33/134Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    34/134

    Chebyshev's filter

    Instructions -

    [N2,Wn2]=cheb1ord([1200 1800],[800 2200],0.5,30,'s')

    [B2,A2]=cheby1(4,0.5,[1200 1800],'s')

    [h2,f2]=freqs(B2,A2)

    plot(f2,h2)

    plot(f2,20*log10(abs(h2)))

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    35/134

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    36/134

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    37/134

    Elliptical filter

    Instructions -

    [N3,Wn3]=ellipord([1200 1800],[800 2200],0.5,30,'s')

    [B3,A3]=ellip(N3,0.5,30,[1200 1800],'s')

    [h3,f3)=freqs(B3,A3)

    plot(f3,h3)

    plot(f3,20*log10(abs(h3)))

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    38/134

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    39/134Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    40/134

    Comparison

    As the order decreases, frequency decreases.For Butterworth filter, n=7.For Chebyshevs filter, n=4

    For Elliptical Filter, n=3.

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    41/134

    MATLAB Assignment 2Digital Signal Processing

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    42/134

  • 7/27/2019 DSP MATLAB Assignments

    43/134

  • 7/27/2019 DSP MATLAB Assignments

    44/134

  • 7/27/2019 DSP MATLAB Assignments

    45/134

  • 7/27/2019 DSP MATLAB Assignments

    46/134

    !"#"$%& ("#)%& *+,-.//")#

    012314 1//"#)5.)$ 6

    17/8%)/8 98%:;8%+ ? 6@AA11*(B@@C

    !"#$%&'()"#$ %&'()*$& *+(,%-.( .* ' /-),&$%$ %-0$ )1)%$0 -) 2-3$( 41

    5'6 7586958:;86?=@A8B=>C=?D6

    E$%$&0-($ %#$ F.,'%-.( .* G.F$) '(/ 8$&.$)>

    HF.% %#$ G.F$ 8$&. 0'G .* *+(,%-.(>

    546 I$G$'% %#$ )'0$ -* *+(,%-.( -) 2-3$( 41

    758695A;8;A6?=@A8;AB=>C=?D8;:6

    5,6 HF.% G.F$;8$&. /-'2&'0 .* 7586 -( 4.%# ,')$)5->6 J-%# (+0$&'%.& '(/ /$(.0-('%.& G.F1(.0-'F ,.$**-,-$(%) ') -(G+%)

    5-->6 J-%# G.F$) '(/ 8$&.$) ') -(G+%)

    5/6 HF.% %#$ *&$K+$(,1 &$)G.()$ .* %#$ E" )1)%$0 L-%# ' )'0GF-(2 *&$K+$(,1 .*

    5->6 A M78

    5-->6 A=M78

    5--->6 A==M78

    *'+"%&'()N$% %#$ %&'()*$& *+(,%-.() 4$ ('0$/ ')

    5'6 "OA 9 58:;86?=@A8B=>C=?D6

    546 "O: 9 5A;8;A6?=@A8;AB=>C=?D8;:6

    (:DE%+$ AF *,&?=@A =>C=?DUV

    G80'G5SPW6

    O&.0 %#-)P L$ 2$% %#$ *.FF.L-(2 2&'G# X

  • 7/27/2019 DSP MATLAB Assignments

    47/134

    "# $%& '$()

    *%++,-./0

    -1+234 5467 .8-234 59#:9;4 9#?+,>@-1+).8-A

    B8 C8D DE8 F%GG%HI-C C&,>E J

    !"#$%&' )* +,-./ %01 2.&,./ %/ 30$"'/*

    ,# $%& '$4)

    $I-.I-C DE8 >%G8/ ,-. ?8&%8/ %F DE8 '$#

    *%++,-./0

    KK L42&%%D/@LA

    L4 2

    9

    4

    KK M42&%%D/@MA

    M4 2

    9#

  • 7/27/2019 DSP MATLAB Assignments

    48/134

    !"#$ &"''()*+ ,"- '(./)0 123 4"53 63-" 45"1 ,"- 7894(-1 :;

    @

    AA 46'(4BC@$D@E

    9= >"- ?>:

    AA 46'(4B*3)@$)8'@E

  • 7/27/2019 DSP MATLAB Assignments

    49/134

    !"#$ &'() *+,'+,- .#/01/,23 #/456,4/ 6. 78 434$/9 :+$; " 4"95?@

    A699",'B .#/0@&,19C'/,C=DDD(

    ++) =D>?@

    A699",'B .#/0@&,19C'/,C=DDDD(

  • 7/27/2019 DSP MATLAB Assignments

    50/134

    !!!" #$$%&'

    )*++,-./

    0123'4-5+6.2-6#$$$$$7

    !"#$%&'()*+ '+- .+'/0#)# 189 :,; !?2- 91,-;,9!?2 A*:21; *< '"

    B*6 C0# 4A*;!9!?2 A*:21; *< '7 =,; *1.21 DE 4:"1"9 -5+21,9*17

    F-.6 C0E 4-2>,9!?2 A*:21; *< '7 =,; *1.21 D# 4:"1"9 -5+21,9*17

    FG;*6 !9 :,;

    ;22!-> 9=2 AG*9; *- .!

  • 7/27/2019 DSP MATLAB Assignments

    51/134

    MATLAB Assignment 3Digital Signal Processing

  • 7/27/2019 DSP MATLAB Assignments

    52/134

  • 7/27/2019 DSP MATLAB Assignments

    53/134

  • 7/27/2019 DSP MATLAB Assignments

    54/134

  • 7/27/2019 DSP MATLAB Assignments

    55/134

  • 7/27/2019 DSP MATLAB Assignments

    56/134

  • 7/27/2019 DSP MATLAB Assignments

    57/134

  • 7/27/2019 DSP MATLAB Assignments

    58/134

    Assignment 3

    Akshansh Chaudhary

    ID 2011AAPS300UDated - 7.10.2013

    Question-Given the specifications of a band stop filter, make it an analog filter and convert it to

    digital filter using impulse invariant method and Bilinear z transform method. Also, find

    the magnitude plot, phase plot, group delay and pole zero diagrams for both the methods.

    Solution -

    Part (1)

    Making analog elliptical

    filterInitializing the value of Wp,Ws,Rp, Rs for the elliptical

    filter

    Rp=0.2Rp =

    0.2000

    >> Rs=40

    Rs =

    40>> Fs=100000

    Fs =100000

    >> Wp=[15000/50000, 30000/50000]Wp =

    0.3000 0.6000

  • 7/27/2019 DSP MATLAB Assignments

    59/134

  • 7/27/2019 DSP MATLAB Assignments

    60/134

    Part (2)Converting to Digital

    (i.) Impulse Invariant Method

    [bz,az]=impinvar(B1,A1,Fs)bz =

    1.0e-003 *

    Columns 1 through 8

    0.0029 -0.0238 0.0859 -0.1772 0.2284 -0.1882 0.0968 -0.0284Column 9

    0.0037

    az =

    Columns 1 through 81.0000 -8.0000 28.0000 -56.0001 70.0002 -56.0002 28.0001 -8.0000

    Column 9

    1.0000

    (a.) Magnitude Plot

    >> [H,F]=freqs(bz,az)

    >> plot(F,20*log10(abs(H)))

    >> xlabel('freq. (in kHz)')

    >> ylabel('magnitude (in dB)')

    (Note: Graphs got in one version of MATLAB may differ in other versions)

  • 7/27/2019 DSP MATLAB Assignments

    61/134

    Observations from the graph:

    The stop band is between 0.2 and 0.25 kHz as required.

    Pass band is between 0-0.15 kHz and then 0.3-0.5 kHz as in problem.The pass band ripple is nearly 0.2 (after zooming the pass band area)

    The stop band ripple has a little deviation. Its coming as 30 db (instead of 40 dB given.)

    The problem becomes more ideal when the sampling frequency is increased.

  • 7/27/2019 DSP MATLAB Assignments

    62/134

    (b.) Phase delay>> phasedelay(bz,az,512)

    (c.) Group Delay>> grpdelay(bz,az,512)

    >>

  • 7/27/2019 DSP MATLAB Assignments

    63/134

  • 7/27/2019 DSP MATLAB Assignments

    64/134

  • 7/27/2019 DSP MATLAB Assignments

    65/134

    (ii.) BZT Method>> [b1,a1]=bilinear(B1,A1,Fs)

    b1 =

    Columns 1 through 8

    0.3652 -2.9218 10.2263 -20.4526 25.5658 -20.4527 10.2263 -2.9218Column 9

    0.3652a1 =Columns 1 through 8

    1.0000 -8.0000 28.0000 -56.0001 70.0002 -56.0002 28.0001 -8.0000Column 9

  • 7/27/2019 DSP MATLAB Assignments

    66/134

  • 7/27/2019 DSP MATLAB Assignments

    67/134

  • 7/27/2019 DSP MATLAB Assignments

    68/134

  • 7/27/2019 DSP MATLAB Assignments

    69/134

    (d.) Pole Zero Plot>> zplane(b1,a1)

  • 7/27/2019 DSP MATLAB Assignments

    70/134

  • 7/27/2019 DSP MATLAB Assignments

    71/134

    Showing that we have Band Stop Filter(Seeing in s domain)>> [N1,Wn1]=ellipord(Wp,Ws,Rp,Rs,'s')

    >> [B1,A1]=ellip(N1,Rp,Rs,Wn1,'stop')

    >> [H,F]=freqs(B1,A1)

    >>plot(F,abs(H))

    >> plot(F, 20*log10(abs(H)))

    >> ylabel('H(jw) (magnitude) in dB')>> xlabel('frequency (Hz)')

  • 7/27/2019 DSP MATLAB Assignments

    72/134

  • 7/27/2019 DSP MATLAB Assignments

    73/134

  • 7/27/2019 DSP MATLAB Assignments

    74/134

  • 7/27/2019 DSP MATLAB Assignments

    75/134

  • 7/27/2019 DSP MATLAB Assignments

    76/134

  • 7/27/2019 DSP MATLAB Assignments

    77/134

  • 7/27/2019 DSP MATLAB Assignments

    78/134

  • 7/27/2019 DSP MATLAB Assignments

    79/134

  • 7/27/2019 DSP MATLAB Assignments

    80/134

  • 7/27/2019 DSP MATLAB Assignments

    81/134

  • 7/27/2019 DSP MATLAB Assignments

    82/134

  • 7/27/2019 DSP MATLAB Assignments

    83/134

  • 7/27/2019 DSP MATLAB Assignments

    84/134

    Assignment 4

    In the given problem, it has been told that the pass band frequency is given as 200 Hz andstop band frequency is given as 500 Hz.Now, as its told to design a band pass filter, are left to assume it as:

    a. A low pass filter with pass band edge frequency of 200 Hz and stop band edge

    frequency of 500 Hzb. A band pass filter with lower stop band frequency of 0 Hz, lower pass band

    frequency of 200 Hz and upper stop band frequency of 500 Hz.

    Note: it is left to the designer to choose how to design the filter using the specs given.

    Now, assuming the case, b. we assume:

    Wsl= 0 Hz

    Wpl= 200 HzThat means, the transition width (Wpl-Wsl)= Delta f (denormalised)=200 Hz

    Wsu=500 Hz

    So, Wpu= Wsu-200 Hz = 300 Hz

  • 7/27/2019 DSP MATLAB Assignments

    85/134

    Commands:

    >> fs=2000;

    >> fn=fs/2; % fn= Nyquist freq.

    >> N=7;

    >> fc1=100/fn; % 100, as its Wpl - (delta f/2); and /fn, as normalising w.r.t nyquist>> fc2=400/fn; % 400, as its Wpu + (delta f/2)

    >> FC=[fc1 fc2];

    >> hn=fir1(N-1, FC, hamming(N));>> [H,f]=freqz(hn, 1,512,fs);

    >> mag=20*log10(abs(H));

    >> plot(f,mag,'red');grid on;

    xlabel('freq(Hz)')

    >> ylabel('Magnitude response (db)')>>

  • 7/27/2019 DSP MATLAB Assignments

    86/134

  • 7/27/2019 DSP MATLAB Assignments

    87/134

  • 7/27/2019 DSP MATLAB Assignments

    88/134

    Clearly, here fpl=2kHz and fpu=4kHz.For the given problem, assume the sampling frequency as 10kHz, as its not mentioned.

    (We know that for denormalizing using Nyquist theorem, we have to divide the

    frequencies by (fs/2), where fs is the sampling frequency.Also, the sampling frequency should be greater than 4kHz.)

    For hamming windowN=41;

    >> fp1=0.3196; % value got after normalizing it w.r.t Nyquist, and using smearing effect

    >> fp2=0.8804;>> fs=10000;

    >> fp=[fp1 fp2];

    >> hn=fir1(N-1,fp,hamming(N));>> hn=fir1(N-1,fp,hamming(N));

    >> [H,f]=freqz(hn,1,512,fs);

    >> mag=20*log10(abs(H));

    >> plot(f,mag,'magenta'); grid on;>>

  • 7/27/2019 DSP MATLAB Assignments

    89/134

  • 7/27/2019 DSP MATLAB Assignments

    90/134

    It is also having pass band in 2000 to 5000 Hz.

    Including both graphs

  • 7/27/2019 DSP MATLAB Assignments

    91/134

  • 7/27/2019 DSP MATLAB Assignments

    92/134

    Matlab Assignment 5Digital Signal Processing

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    93/134

  • 7/27/2019 DSP MATLAB Assignments

    94/134

  • 7/27/2019 DSP MATLAB Assignments

    95/134

  • 7/27/2019 DSP MATLAB Assignments

    96/134

    MATLAB Assignment 6Digital Signal Processing

  • 7/27/2019 DSP MATLAB Assignments

    97/134

  • 7/27/2019 DSP MATLAB Assignments

    98/134

  • 7/27/2019 DSP MATLAB Assignments

    99/134

  • 7/27/2019 DSP MATLAB Assignments

    100/134

  • 7/27/2019 DSP MATLAB Assignments

    101/134

  • 7/27/2019 DSP MATLAB Assignments

    102/134

  • 7/27/2019 DSP MATLAB Assignments

    103/134

  • 7/27/2019 DSP MATLAB Assignments

    104/134

  • 7/27/2019 DSP MATLAB Assignments

    105/134

  • 7/27/2019 DSP MATLAB Assignments

    106/134

  • 7/27/2019 DSP MATLAB Assignments

    107/134

  • 7/27/2019 DSP MATLAB Assignments

    108/134

  • 7/27/2019 DSP MATLAB Assignments

    109/134

  • 7/27/2019 DSP MATLAB Assignments

    110/134

  • 7/27/2019 DSP MATLAB Assignments

    111/134

  • 7/27/2019 DSP MATLAB Assignments

    112/134

  • 7/27/2019 DSP MATLAB Assignments

    113/134

  • 7/27/2019 DSP MATLAB Assignments

    114/134

  • 7/27/2019 DSP MATLAB Assignments

    115/134

  • 7/27/2019 DSP MATLAB Assignments

    116/134

    MATLAB Assignment 7Digital Signal Processing

    Akshansh Chaudhary

  • 7/27/2019 DSP MATLAB Assignments

    117/134

  • 7/27/2019 DSP MATLAB Assignments

    118/134

  • 7/27/2019 DSP MATLAB Assignments

    119/134

  • 7/27/2019 DSP MATLAB Assignments

    120/134

  • 7/27/2019 DSP MATLAB Assignments

    121/134

  • 7/27/2019 DSP MATLAB Assignments

    122/134

    Part c- Interpolation (250*10 i.e. 2500 samples)

  • 7/27/2019 DSP MATLAB Assignments

    123/134

  • 7/27/2019 DSP MATLAB Assignments

    124/134

  • 7/27/2019 DSP MATLAB Assignments

    125/134

  • 7/27/2019 DSP MATLAB Assignments

    126/134

    >>

    >> %Now, decimating for part b.>> y=decimate(x,10);

    >> subplot(3,1,2)

    >> stem(y(1:100))

    >> xlabel('Discrete time, nT/10')>> ylabel('Decimated output signal level')

    >>

    >> %Now, interpolating for part c.>> y1=interp(y,4);

    >> subplot(3,1,3)

    >> stem(y1(1:400))>> xlabel('Discrete time, 4*nT')

    >> ylabel('Decimated output signal level')

    >>

    Change 2

    Fs=5000;

    >> A=2;

  • 7/27/2019 DSP MATLAB Assignments

    127/134

  • 7/27/2019 DSP MATLAB Assignments

    128/134

  • 7/27/2019 DSP MATLAB Assignments

    129/134

  • 7/27/2019 DSP MATLAB Assignments

    130/134

  • 7/27/2019 DSP MATLAB Assignments

    131/134

  • 7/27/2019 DSP MATLAB Assignments

    132/134

  • 7/27/2019 DSP MATLAB Assignments

    133/134

  • 7/27/2019 DSP MATLAB Assignments

    134/134