Lab no 7.doc

download Lab no 7.doc

of 13

Transcript of Lab no 7.doc

  • 8/14/2019 Lab no 7.doc

    1/13

    Lab # 7

    FATIMA JINNAH WOMEN UNIVERSITY RAWALPINDI

    Digital Signal Processing

    Sa!ling an" #lti$rate signal !rocessing% "eciation an"

    inter!olation

    Objectives:

    The purpose of this lab is to acquaint students with the following concepts:

    Sampling

    Rates of sampling

    Up sampling/Interpolation

    own sampling/ecimation !iltering within Sampling " #ore commonl$ %nown as the process of

    anti&aliasing

    Introduction:

    In signal processing' sampling is the reduction of a continuous signal to a

    discrete signal( ) common e*ample is the conversion of a sound wave +a

    continuous signal, to a sequence of samples +a discrete&time signal,( )

    sample refers to a value or set of values at a point in time and/or space( )sampler is a subs$stem or operation that e*tracts samples from a continuous

    signal( ) theoretical ideal sampler produces samples equivalent to the

    instantaneous value of the continuous signal at the desired points(

    -$quist .riterion:

    The -$quist criterion states that for the digital signal to be correctl$

    reconstructed it must be sampled at twice the frequenc$ of the ma*imum

    frequenc$ signal in the original analog signal( It is named after the Swedish&)merican engineer arr$ -$quist( Therefore -$quist frequenc$ is half the

    sampling frequenc$ of a discrete signal processing s$stem( It is sometimes

    %nown as the folding frequenc$ of a sampling s$stem(

    0hen the continuous function being sampled contains no frequencies equal

    or higher than the -$quist frequenc$' all the aliases caused b$ sampling

    occur above the -$quist frequenc$( The term aliasing usuall$ refers to the

  • 8/14/2019 Lab no 7.doc

    2/13

    Lab # 7

    case where some original frequenc$ components have aliases below

    -$quist( That often causes distortion when a continuous function is

    subsequentl$ reconstructed from samples(

    The -$quist frequenc$ should not be confused with the -$quist rate' whichis the lower bound of the sampling frequenc$ that satisfies the -$quist

    sampling criterion for a given signal or famil$ of signals( This lower bound

    is twice the bandwidth or ma*imum component frequenc$ of the signal(

    -$quist rate' as commonl$ used with respect to sampling' is a propert$ of a

    continuous&time signal' not of a s$stem' whereas -$quist frequenc$ is a

    propert$ of a discrete&time s$stem' not of a signal( In theor$' a -$quist

    frequenc$ just larger than the signal bandwidth is sufficient to allow perfect

    reconstruction of the signal from the samples( owever' this reconstruction

    requires an ideal filter that passes some frequencies unchanged while

    suppressing all others completel$ +commonl$ called a bric%&wall filter,( Inpractice' perfect reconstruction is unattainable( Some amount of aliasing is

    unavoidable( Signal frequencies higher than the -$quist frequenc$ will

    encounter a 1folding1 about the -$quist frequenc$' bac% into lower

    frequencies( !or e*ample' if the sample rate is 23 %4' the -$quist

    frequenc$ is 53 %4' and an 55 %4 signal will fold' or alias' to 6 %4(

    In signal processing' oversampling is the process of sampling a signal with a

    sampling frequenc$ significantl$ higher than twice the bandwidth or highest

    frequenc$ of the signal being sampled( Oversampling helps avoid aliasing'improves resolution and reduces noise( Oversampling can ma%e it easier to

    reali4e analog anti&aliasing filters( 0ithout oversampling' is ver$ difficult to

    implement filters with the sharp cutoff necessar$ to ma*imi4e use of the

    available bandwidth without e*ceeding the -$quist limit( 7$ increasing the

    bandwidth of the sampled signal' design constraints for the anti&aliasing

    filter ma$ be rela*ed( Once sampled' the signal can be digitall$ filtered and

    downsampled to the desired sampling frequenc$( In modern integrated

    circuit technolog$' digital filters are easier to implement than comparable

    analog filters(

  • 8/14/2019 Lab no 7.doc

    3/13

    Lab # 7

    In signal processing' downsampling +or 1subsampling1, is the process of

    reducing the sampling rate of a signal( This is usuall$ done to reduce the

    data rate or the si4e of the data( The downsampling factor +commonl$

    denoted b$ #, is usuall$ an integer or a rational fraction greater than unit$(

    This factor multiplies the sampling time or' equivalentl$' divides the

    sampling rate( !or e*ample' if compact disc audio at 88'533 4 is

    downsampled to 22'393 4 before broadcasting over !# radio' the bit rate

    is reduced in half' from 5'855'233 bit/s to 39';33 bit/s' assuming that eachsample retains its bit depth of 5; bits( The audio was therefore downsampled

    b$ a factor of 2(

  • 8/14/2019 Lab no 7.doc

    4/13

    Lab # 7

    Since downsampling reduces the sampling rate' we must be careful to ma%e

    sure the Shannon&-$quist sampling theorem criterion is maintained( If thesampling theorem is not satisfied then the resulting digital signal will have

    aliasing( To ensure that the sampling theorem is satisfied' a low&pass filter is

    used as an anti&aliasing filter to reduce the bandwidth of the signal before the

    signal is downsampled< the overall process +low&pass filter' then

    downsample, is called ecimation( -ote that if the original signal had been

    bandwidth limited' and then first sampled at a rate higher than the -$quist

  • 8/14/2019 Lab no 7.doc

    5/13

    Lab # 7

    minimum' then the downsampled signal ma$ alread$ be -$quist compliant'

    so the downsampling can be done directl$ without an$ additional filtering(

    ownsampling onl$ changes the sample rate not the bandwidth of the signal(

    The onl$ reason to filter the bandwidth is to avoid the case where the new

    sample rate would become lower than the -$quist requirement and thencause the aliasing b$ being below the -$quist minimum(

  • 8/14/2019 Lab no 7.doc

    6/13

    Lab # 7

    Some Useful #)T=)7 .ommands

    $ > decimate+*'R, " To downsample a signal( ere ?*@ is the arra$

    containing the signal to be downsampled and ?R@ is the downsampling

    factor/ratio

    $ > interp+*'R, " To upsample a signal( ere ?*@ is the arra$ containing

    the signal to be upsampled and ?R@ is the upsampling factor/ratio

    In =ab Tas%s

    5( Use $our ?sinegen@ function to generate a sine wave with f > A%4 and fs

    > B%4( .alculate its fft with 4ero frequenc$ component in the middle(

    Clot it on a properl$ scaled w&a*is(

    function D$E>sinegen+f'fs,

    t>&9333:5:9333

    *>sin+2FpiFf/fsFt,

    r>fft+*,

    $>fftshift+r,

    plot+t'$,

  • 8/14/2019 Lab no 7.doc

    7/13

    Lab # 7

    2( ecimate the signal in tas% 5 with ?# > 2@ and plot the resultant signal(

    Give $our observations about the plots in $our reports

    function D$E>sinegen+f'fs,

    t>&9333:5:9333*>sin+2FpiFf/fsFt,

    r>fft+*,

    $>fftshift+r,

    plot+t'$,

    t5>&9333:2:9333

    r5>decimate+*'2,fft+r5,fftshift+r2,&9333:2:9333

    r5>decimate+*'2,fft+r5,fftshift+r2,&9333:5:9333

    *>cos+2FpiFf3/fsFn,Hcos+2FpiFf5/fsFn,H cos+2FpiFf2/fsFn,

    r>fft+*,

    $>fftshift+r,

    plot+n'$,

    *label+n,

    $label+$,

    title+Signal Cloting using Sinegen+,,

    n5>&9333:2:9333

    r5>decimate+*'2,fft+r5,fftshift+r2,sinegen+f3'f5'f2'fA'f8'fs,

    n>&9333:5:9333

    *>sin+2FpiFf3/fsFn,Hsin+2FpiFf5/fsFn,H sin+2FpiFf2/fsFn,H

    sin+2FpiFfA/fsFn,H sin+2FpiFf8/fsFn,

    r>fft+*,

    $>fftshift+r,

    plot+n'$,

    *label+n,$label+$,

    title+Signal Cloting using Sinegen+,,

    n5>&9333:A:9333

    r5>decimate+*'A,fft+r5,fftshift+r2,&9333:5:9333

    *>sin+2FpiFf3/fsFn,Hsin+2FpiFf5/fsFn,H sin+2FpiFf2/fsFn,H

    sin+2FpiFfA/fsFn,H sin+2FpiFf8/fsFn,

    r>fft+*,

    $>fftshift+r,

    plot+n'$,*label+n,

    $label+$,

    title+Signal Cloting using Sinegen+,,

    fin>DE35:53333

    if counterM>53333

    p>4eros+5'A,< if counter>>3

    fin>Dfin n+i, pEDfin n+i, pEcounterH5

  • 8/14/2019 Lab no 7.doc

    13/13

    Lab # 7

    end

    end

    r5>interp+*'8,fft+r5,fftshift+r2,