Dsp 2 - Signals in Matlab

download Dsp 2 - Signals in Matlab

of 27

Transcript of Dsp 2 - Signals in Matlab

  • 8/2/2019 Dsp 2 - Signals in Matlab

    1/27

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-1

    Fundamentals of Signals

    Practical Signal Processing Conceptsand Algorithms using MATLAB

  • 8/2/2019 Dsp 2 - Signals in Matlab

    2/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-2

    What is signal Processing?

    The scope of signal processing has grown so broad as toobviate a perfect and precise definition of what is entailed in it

    Traditionally, signal processing includes the materials thought inDSP courses but now signal processing has greater reach

    because of its influence on related disciplines such as controls,communications theory and also digital communication.

    Thus, signal processing can be defined as that area of appliedmathematics that deals with operations on or analysis of signals,in either discrete or continuous time, to perform usefuloperations on those signals.

  • 8/2/2019 Dsp 2 - Signals in Matlab

    3/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-3

    Digital signal processing is the process of extracting usefulinformation from an incoming set of signal (sampled at regularinterval, Ts)

    When you speak,your voice ispicked up by ananalog sensor inthe cell phonesmicrophone

    An analog-to-

    digital converterchip convertsyour voice(analog) intodigital signals,representing 1sand 0s

    The Digital SignalProcessor (DSP)compresses thedigital signals andremove anynoise.

    In the receivers

    cell phone, adigital-to-analogconverter chipchanges thedigital signalback to ananalog voice

    signal

    Your voice exitsthe phonethrough thespeaker

  • 8/2/2019 Dsp 2 - Signals in Matlab

    4/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-4

    What is Signal Processing Toolbox?

    The Signal Processing Toolbox is a collection oftools built on the MATLABnumeric computingenvironment.

    The toolbox supports a wide range of signalprocessing operations, from waveformgeneration to filter design and implementation,parametric modeling, and spectral analysis.

    The toolbox provides two categories of tools.

  • 8/2/2019 Dsp 2 - Signals in Matlab

    5/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-5

    Section Outline

    Creating and importing signals

    Sampling and re-sampling

    Signal visualization

    Modeling noise

    Modulation

  • 8/2/2019 Dsp 2 - Signals in Matlab

    6/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-6

    Discrete Signals

    Time base: t = [0.0 0.1 0.2 0.3];

    Signal data: x = [1.0 3.2 2.0 8.5];

    Creating vectors in MATLAB:

    >> t = [0.0 0.1 0.2 0.3];

    >> t = 0:0.1:0.3;

    >> t = linspace(0, 0.3, 4);

  • 8/2/2019 Dsp 2 - Signals in Matlab

    7/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-7

    Sampling Signals

    Analog signal sources

    Electromagnetic, audio, sonar, biomedical

    Sampling

    )()( sa nTxnx

    discretesignal

    analogsignal

    sampletime

  • 8/2/2019 Dsp 2 - Signals in Matlab

    8/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-8

    Aliasing

    Ms ff 2Shannon Sampling Theorem:

    Ms ff 2 Ms ff 2

    Original signal and sampled

    signal have same frequency

    Sampled signal is aliased to

    half the original frequency

  • 8/2/2019 Dsp 2 - Signals in Matlab

    9/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-9

    Signal Visualization

    View signal amplitude vs. time index

    Functions

    plot, stem, stairs, strips

    Listen to datasound

  • 8/2/2019 Dsp 2 - Signals in Matlab

    10/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-10

    Signal Processing Tool

    >> sptool

  • 8/2/2019 Dsp 2 - Signals in Matlab

    11/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-11

    Importing a Signal

    Choose Import under the File menu

  • 8/2/2019 Dsp 2 - Signals in Matlab

    12/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-12

    Since MATLAB is a programming language, an endless variety of differentsignals is possible. Here are some statements that generate severalcommonly used sequences, including the unit impulse, unit step, and unit

    ramp functions:

    >> t = (0:0.01:1);

    >> y = ones(101); % step

    >> y = [1; zeros(100,1)]; % impulse

    >> y = t ; % ramp>> y = t.^2; % exponential

    >> y = square(2*pi*4*t); % generates a square wave every 0.25secs.

    Signal Processing BasicsCommon Sequences

  • 8/2/2019 Dsp 2 - Signals in Matlab

    13/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-13

    Waveform generation

    >> y = sin(2*pi*50*t) + 2*sin(2*pi*120*t); %two sinusoids,%one at 50 Hz%and one at%120Hz with%twice the amplitude

    >> plot(t,y) %plot y versus time

    >> plot(t(1:50),y(1:50)) %display only the first%50 points(zoom!)

  • 8/2/2019 Dsp 2 - Signals in Matlab

    14/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-14

    Signal Browser

  • 8/2/2019 Dsp 2 - Signals in Matlab

    15/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-15

    Changing Sample Rates

    To change the sample rate ofa signal in SPTool,

    1. Click one signal in the

    signals column of SPTool.2. Select Sampling Frequencyin the Edit menu.

    3. Enter the desired samplingfrequency and click OK.

  • 8/2/2019 Dsp 2 - Signals in Matlab

    16/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-16

    Signal GenerationSignal Generation

    Signals

    Create a time base vector

    >> t = [0:0.1:2];

    Signal as function of time>> x = sin(pi*t/2);

    Useful MATLAB Functions

    Nonperiodic functions

    ones, zeros, step

    Periodic functions

    sin, cos, square, sawtooth

  • 8/2/2019 Dsp 2 - Signals in Matlab

    17/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-17

    Non-periodic Signals

    >> t = linspace(0,1,11)

    Step

    >> y = ones(11,1);

    Impulse

    >> y = [1;zeros(10,1)];

    Ramp

    >> y = 2*t;

  • 8/2/2019 Dsp 2 - Signals in Matlab

    18/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-18

    Sine Waves

    Parameters

    AmplitudeA

    Frequencyf

    Phase shift

    Vertical offsetB

    General form

    BtfABftAy ))(2sin()2sin(

  • 8/2/2019 Dsp 2 - Signals in Matlab

    19/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-19

    Square Waves

    >> sqw1 = square(2*pi*4*t);

    >> sqw2 = square(2*pi*4*t,75);

    Duty cycle is 50% (default)

    Frequency is 4 Hz

    Duty cycle is 75%

    Frequency is 4 Hz

  • 8/2/2019 Dsp 2 - Signals in Matlab

    20/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-20

    Sawtooth Waves

    >> saw1 = sawtooth(2*pi*3*t);

    >> saw2 = sawtooth(2*pi*3*t,1/2);

    Peak at end of cycle (default)

    Frequency is 3 Hz

    Peak halfway through cycle

    Frequency is 3 Hz

  • 8/2/2019 Dsp 2 - Signals in Matlab

    21/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-21

    Complex Signals

    x(t) = e j2ft= cos(2ft) +j sin(2ft) = cos(t) +j sin(t)

    >> x = exp(2*pi*j*f*t);

    Useful MATLAB Functions: real, imag, abs, angle

    z-plane: ej Time domain: sin(t)

    Fs/2 0,Fs

  • 8/2/2019 Dsp 2 - Signals in Matlab

    22/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-22

    textread

    xlsread

    imreadimportdata wavread

    uiimport

    input

    Importing Data

  • 8/2/2019 Dsp 2 - Signals in Matlab

    23/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-23

    Modeling Noise with Random Data

    >> un = -5+10*rand(1,1e6);

    >> hist(un,100)

    >> gn = 10+5*randn(1,1e6);

    >> hist(gn,100)

    Uniform Gaussian

  • 8/2/2019 Dsp 2 - Signals in Matlab

    24/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-24

    Adding Noise to a Signal

    noisy signal = signal + noise

    >> y1 = x + rand(size(x)) uniform noise

    >> y2 = x + randn(size(x)) Gaussian noise

  • 8/2/2019 Dsp 2 - Signals in Matlab

    25/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-25

    Pseudorandomness

    0.95012928514718

    This is the first number produced by the MATLAB uniform randomnumber generator with its default settings. Is it random?

    A random sequence is a vague notion ... in which each term isunpredictable to the uninitiated and whose digits pass a certain numberof tests traditional with statisticians ...

    - D.H. Lehmer

    >> rand('state',s) Sets the state to s.

    >> rand('state',0) Resets the generator to its initial state.

    >> rand('state',sum(100*clock)) New state each time.

  • 8/2/2019 Dsp 2 - Signals in Matlab

    26/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-26

    Resampling

    Useful MATLAB functions

    downsample, upsample, resample, interp, decimate

  • 8/2/2019 Dsp 2 - Signals in Matlab

    27/27

    Fundamental of Signals

    2010 Trity Technologies Sdn Bhd. All Rights Reserved 2-27

    Modulation and Demodulation

    y = modulate(x,fc,fs,'fm')

    x = demod(y,fc,fs,'fm')