+ All Categories
Home > Documents > DSP Lab Manual2

DSP Lab Manual2

Date post: 04-Apr-2018
Category:
Upload: xp2009
View: 279 times
Download: 0 times
Share this document with a friend

of 21

Transcript
  • 7/31/2019 DSP Lab Manual2

    1/21

    L a b m a n u a l o n

    D i g i t a l S i g n a l P r o c e s s i n g

    Submitted to:

    E n g r . M . A b b a s A b b a s i

    Su b m i t t e d b y :

    0 8 E L - 6 0

    Sh a f q a t H u s s a in Sa b a a q

    Se m e s t e r :

    6 t h , 2 0 0 8 - 2 0 1 2

    University College Of Engineering And Technology

    Islamia University Of Bahawalpur, Pakistan.

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    2/21

    2

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    S.No Lab Experiments Page No

    1To become familiar with the different types of discrete signaland plot them in the matlab. 3

    2 Generating Tunes with Music Notes in MATLAB 11

    3Working with Audio Signals in MATLAB

    13

    4 Introduction to SimPowerSystem 16

    5To See the Frequency Response of a Signal in MATLAB

    18

    6To Implement a Discrete System in Simulink.

    20

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    3/21

    3

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Lab No 1

    Objective:

    To become familiar with the different types of discrete signal and plot them in the matlab.

    Apparatus:

    MATLAB software.Theoretical background:

    Discrete signals are those signals which have discrete values at particular

    interval of time. We study some of the basic discrete time signals.

    (1) Unit sample signal:The unit step signal can be expressed as

    x(n) = (n)

    And(n) = 1 for n = 0

    (n) = 0 for all n 0

    -3 -2 -1 0 1 2 30

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    (n)

    (xn

    )

    (FIG: UNIT IMPULSE SIGNAL)

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    4/21

    4

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    (2) Unit step signal:The unit step signal can be expressed as

    x(n) = u(n)

    And u(n) = 1 for n 0

    u(n) =0 for n < 0

    (3) Ramp signal:Ramp signal can be expressed as

    r(n) = n for n 0

    r(n) = 0 for n < 0

    -10 -8 -6 -4 -2 0 2 4 6 8 100

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    (n)

    (xn

    )

    (FIG: UNIT STEP SIGNAL)

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    5/21

    5

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    (4) Sinusoidal signal:The sinusoidal signal can be expressed as

    x(n) = A cos (2fn)

    -10 -8 -6 -4 -2 0 2 4 6 8 100

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    (n)

    (xn

    )

    (FIG: RAMP SIGNAL)

    -10 -8 -6 -4 -2 0 2 4 6 8 10-10

    -8

    -6

    -4

    -2

    0

    2

    4

    6

    8

    10

    (n)

    (xn

    )

    (FIG: SINUSOIDAL SIGNAL)

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    6/21

    6

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    (5)Exponential signal:The exponential signal can be expressed as

    x(n) = A ean

    (6) Complex exponential signal:The complex exponential signal can be expressed as

    x(n) = A ej2fn

    -10 -8 -6 -4 -2 0 2 4 6 8 100

    10

    20

    30

    40

    50

    60

    70

    80

    (n)

    (xn)

    (FIG: EXPONENTIAL SIGNAL)

    -10 -8 -6 -4 -2 0 2 4 6 8 10-10

    -5

    0

    5

    10

    (n)

    xr

    FIG: COMPLEX EXPONENTIAL SIGNAL(REAL PART)

    -10 -8 -6 -4 -2 0 2 4 6 8 10-10

    -5

    0

    5

    10

    (n)

    (xi)

    FIG: COMPLEX EXPONENTIAL SIGNAL(IMAGINARY PART)

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    7/21

    7

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    (7) Square wave signal:This signal obtained on the graph which shows that it has the wave like a square

    It can be expressed as

    x(n) = square (2fn)

    (8) Sawtooth wave signal:On the graph its behavior like a sawtooth. It is very common type of wave signal.

    It can be expressed as

    x(n) = sawtooth (2fn)

    -10 -8 -6 -4 -2 0 2 4 6 8 10

    -8

    -6

    -4

    -2

    0

    2

    4

    6

    8

    (n)

    (xn

    )

    (FIG: SQUARE WAVE SIGNAL)

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    8/21

    8

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    (9) Sinc signal:It is the signal which can be expressed mathematically as

    x(n) = sinc (2fn)

    -20 -15 -10 -5 0 5 10 15 20-20

    -15

    -10

    -5

    0

    5

    10

    15

    20

    (n)

    (xn

    )

    (FIG: SAWTOOTH WAVE SIGNAL)

    -10 -8 -6 -4 -2 0 2 4 6 8 10-2

    -1

    0

    1

    2

    3

    4

    5

    6

    7

    8

    (n)

    (xn

    )

    (FIG: SINC WAVE SIGNAL)

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    9/21

    9

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Cell structure matlab code for all signals listed above:

    %%

    %(1)unit impulse signal

    n=-3:3;

    x_n=[0 0 0 1 0 0 0];

    stem(n,x_n);xlabel('(n)');ylabel('(x_n)');grid ontitle('(FIG: UNIT IMPULSE SIGNAL)');

    %%

    %(2)unit step signal

    n=-10:10;

    x_n=zeros(1,length(n));

    x_n(find(n>=0))=1;

    stem(n,x_n);xlabel('(n)');ylabel('(x_n)');

    title('(FIG: UNIT STEP SIGNAL)');grid on

    %%

    %(3)ramp signal

    n=-10:10;

    x_n=n; x_n(find(n

  • 7/31/2019 DSP Lab Manual2

    10/21

    10

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    %%

    %(7) square wave signal

    n=-10:10;

    A=8; f=0.1;

    x_n=A*square(2*pi*f*n);

    stem(n,x_n);xlabel('(n)');ylabel('(x_n)');

    title('(FIG: SQUARE WAVE SIGNAL)');grid on%%

    %(8) sawtooth wave signal

    n=-20:20;

    A=20; f=0.1;

    x_n=A*sawtooth(2*pi*f*n);

    stem(n,x_n);xlabel('(n)');ylabel('(x_n)');

    title('(FIG: SAWTOOTH WAVE SIGNAL)');grid on

    %%

    %(9) sinc wave signal

    n=-10:10;

    A=8; f=0.1;

    x_n=A*sinc(2*pi*f*n);

    stem(n,x_n);xlabel('(n)');ylabel('(x_n)');

    title('(FIG: SINC WAVE SIGNAL)');grid on

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    11/21

    11

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Lab No 2

    Objective:

    Generating Tunes with Music Notes in MATLAB

    Apparatus:

    MATLAB software.Theoretical background:

    Introduction:The music tunes are composed of several sinusoidal and exponential signals. Each music

    note is defined as a function of time. So by the combination of different music notes, a tune can be

    generated. This lab session is to generate the music tune and to work with several discrete signals by

    getting familiarity with several parameters.

    Upsampling and Downsampling:The process of increasing the sampling frequency of the sampler is called upsampling while the process

    of decreasing the sampling frequency is called downsampling.

    Downsampling is done in MATLAB by the following code:

    tdown=downsample(t,N)

    here t is the sampling time that is reciprocal of sampling frequency and N is the number by which the

    downsampling is required. This command reduces the sampling frequency by a factor of N. tdown is the

    new sampling time.

    Similarly the command for upsampling is:

    tup=upsampling(t,N)

    Matlab code for sampling:

    %sampling

    A=5;

    F=300;

    F_s=8000;

    T_s=1/F_s;

    t=0:T_s:0.01;

    x_t=A*sin(2*pi*F.*t);

    tup=upsample(t,4);

    x_tup=upsample(x_t,4);

    stem(tup,x_tup)

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    12/21

    12

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Output results:

    F ig : S a m p l i n g

    0 0.001 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01-5

    -4

    -3

    -2

    -1

    0

    1

    2

    3

    4

    5

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    13/21

    13

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Lab No 3

    Objective:

    Working with Audio Signals in MATLAB

    Apparatus:

    MATLAB software.Theoretical background:

    Section AThere are four ways to transmit or receive data.

    1) Text Keypad2) Audio Microphone3) Image Camera4) Video Web Cam/VID Cam

    Sound command is used to listen a defined function in MATLAB. This function will be played at the

    frequency of 8 kHz, which is the default frequency of sound card. In addition, the transmission system is

    also transmitting signals on this frequency.

    The Maximum frequency that can be achieved from sound card is 48 kHz. To hear the maximum sound

    of sound card, the command soundsc is used.

    Lab Work:

    Consider the following program

    t=0:0.01:1;y1=5*sin(40*pi.*t);

    y2=10*square(40*pi.*t);

    y3=15*sawtooth(40*pi.*t);

    Q1. Listen the following signals at specified frequency

    i) y1ii) y2iii) y3iv) y1+y2+y3v) y1y2y3vi) y1y2+y3vii) y1-y2-y3viii) y1-y2y3

    sound(signal name) command is used to listen these signals.

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    14/21

    14

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Q2. Listen y2 at 8 kHz, 4 kHz, 2 kHz and 5 Hz

    sound(y2, 8000) is used to listen y2 at 8 kHz. Similarly by changing the frequency, y2 can be heard at any

    frequency.

    Q3. Listen y3 at 9 kHz

    sound(y3, 9000) is used here.

    All signals given in above questions have been successfully listened during the lab session.

    Matlab code:

    t=0:0.01:1;

    y1=5*sin(40*pi.*t);

    y2=10*square(40*pi.*t);

    y3=15*sawtooth(40*pi.*t);

    play(y1,8000)

    play(y2,8000)

    play(y2,4000)

    play(y2,3000)play(y2,2000)

    play(y3,9000)

    play(y1+y2+y3)

    play(y1y2y3)

    play(y1y2+y3)

    play(y1+y2y3)

    play(y1-y2-y3)

    Section B

    Recording:

    Recording in MATLAB can be static or dynamic.

    The difference in two types is that the static recording cant be plotted and also it is difficult to save it in

    memory. To view the recording graphically and to save it, we have to convert the recording into Dynamic

    Type.

    How to record a static file?

    Static recording can be accomplished using audiorecorder and record command. In order to record a

    signal y for 10 seconds, following MATLAB code is written:

    y=audiorecorder;

    record(y,10)

    To play this signal, use play command as shown below:play(y)

    To pause the playing signal, use pause command as shown below:

    pause(y)

    To stop the signal, use stop command as shown below:

    stop(y)

    How to covert Static Recording into Dynamic Recording?

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    15/21

    15

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Static recording can be converted into dynamic recording by using the getaudiodata command as shown

    below:

    x= getaudiodata(y);

    Now it is a dynamic file and cant be played with a play command. To listen this, use wavplay

    command as shown below:

    wavplay(x)How to save a wav file?

    wav file x can be saved by using the command wavwrite as shown below:

    wavwrite(x, desired frequency, Name of the file)

    This file will be saved in work folder of MATLAB.

    How to play a wav file from local disk?

    If a wav file is located in the local disk of computer, then it can be listened in MATLAB using the

    command wavread. Suppose a wav file format of 3idiots ringtone is located in tones folder in local disk

    D, then following code will be used to play this file in MATLAB:

    wavread(d:\tones\3idiots.wav)

    Matlab code for recording:y=audiorecorder;

    record(y)

    play(y,70)

    pause(y)

    stop(y)

    yd=getaudiodata(y);

    wavplay(yd)

    wavplay(yd,8000)

    wavwrite(yd,8000,'Sabaaq.wav')

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    16/21

    16

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Lab No 4

    Objective:

    Introduction to SimPowerSystem

    Apparatus:

    MATLAB software.Theoretical background:

    Introduction:

    SimPowerSystem is a library in simulink and is the core tool for Power Engineers for

    implementing and simulating the Power Devices and Projects. This library covers almost all of the

    practical modeling in simulation. This lab session is to learn techniques of simulink modeling of physical

    and power devices.

    Lab Work:

    Implement the following model in simpower and observe the output

    Fig: Simpower model

    powergui

    Continuous

    Voltage Measurement

    v+-

    Universal Bridge

    A

    B

    C

    +

    -Scope

    Sada source

    N

    A

    B

    C

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    17/21

    17

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Output Results:

    Fig: Output Results for simpower model

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    18/21

    18

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Lab No 5

    Objective:

    To See the Frequency Response of a Signal in MATLAB

    Apparatus:

    MATLAB software.Theoretical background:

    Introduction:Discrete-Time Fourier Transform (DTFT) is used to see the behavior of a signal with

    respect to Frequency that is often called as Frequency Response of a Signal.

    Discrete-Time Fourier Transform is denoted as X(j).

    Mathematically it is written as

    () = ()

    Lab Work:

    () = () Then

    |()|^2 = 1/ (1 2 + ^2 )

    Sketch X(j) for

    i) a=1/4ii) a=-1/4iii) a=1/2iv) a=-1/2

    a1=1/4;

    a2=-1/4;

    a3=1/2;

    a4=-1/2;

    w=-pi:0.001:pi;

    E1=1./(1-2*a1*cos(w)+a1^2);

    E2=1./(1-2*a2*cos(w)+a2^2);

    E3=1./(1-2*a3*cos(w)+a3^2);

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    19/21

    19

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    E4=1./(1-2*a4*cos(w)+a4^2);

    plot(w,E1,w,E2,w,E3,w,E4);

    grid on

    legend('a=1/4','a=-1/4','a=1/2','a=-1/2')

    Output Results:

    Fig: Frequency Response of a signal

    -4 -3 -2 -1 0 1 2 3 40

    0.5

    1

    1.5

    2

    2.5

    3

    3.5

    4

    a=1/4

    a=-1/4

    a=1/2

    a=-1/2

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    20/21

    20

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Lab No 6

    Objective:

    To Implement a Discrete System in Simulink.

    Apparatus:

    MATLAB software.Theoretical background:

    Introduction:This lab session is to implement a discrete system in Simulink and to be familiar with

    different simulink tools.

    The general equation of a system is given by

    () = ( 1) + () Lab Work:Let = 1 / = /And let

    = 10 = 1 = 0.5Now we will implement this model in simulink as shown below

    Fig: Model A

    Unit Delay

    z

    1

    Sine Wave

    Scope

    Gain 1

    a

    Gain

    b

    First-Order

    Hold 1

    First-Order

    Hold

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now
  • 7/31/2019 DSP Lab Manual2

    21/21

    21

    08EL-60 Shafqat Hussain Sabaaq Digital Signal Processing

    Output Results:

    Fig: Results for model A

    http://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-nowhttp://www.tracker-software.com/buy-now

Recommended