frequency domain signal processing using matlab

Upload: kiruthika-devi

Post on 06-Apr-2018

238 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    1/41

    Frequency Domain SignalFrequency Domain SignalProcessing Using MATLABProcessing Using MATLAB

    Mohammad Sadgh TalebiSharif University of Technology

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    2/41

    Fourier Transform inFourier Transform in MatlabMatlab

    Y = fft(X,n)

    Computes n-point Discrete FourierTransform (DFT) of each column of X

    with a FFT algorithm

    If length(x) < n => zero-padding

    If length(x) > n => truncate x

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    3/41

    Y = ifft(X,n)

    Similarly, IFFT computes n-point InverseDiscrete Fourier Transform (IDFT) of

    each column of X with a IFFT algorithm

    If length(x) < n => zero-padding

    If length(x) > n => truncate x

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    4/41

    Signal Analysis >Signal Analysis >

    ConvolutionConvolution

    fftshift(X) swaps the left and right halves

    of X. For matrices, fftshift(X) swaps thefirst quadrant with the third and the

    second quadrant with the fourth.

    Similarly, ifftshift(X) neutralizes the

    results of fftshift.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    5/41

    Signal Analysis >Signal Analysis >

    ConvolutionConvolutionx(1:20)=0;

    x(21:30)=1;

    x(31:50)=0;

    figure(1);

    plot(x);

    X=fft(x);

    figure(2);

    subplot(211);

    plot(abs(X));subplot(212);

    plot(angle(X));

    figure(3);

    subplot(211);

    plot(abs(fftshift(X)));

    subplot(212);

    plot(angle(fftshift(X)));

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    6/41

    Signal Analysis >Signal Analysis >

    Step ResponseStep Response

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    7/41

    Signal Analysis >Signal Analysis >

    Step ResponseStep Response

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    8/41

    Signal Analysis >Signal Analysis >

    Bode DiagramsBode Diagrams Filtering

    Frequency Domain Time Domain

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    9/41

    Frequency Domain Filtering

    Take FFT from input signal and just multiply itby frequency response of filter. Finally take

    inverse FFT from result.

    Alternatively, with the knowledge of Pole-Zeroplot or Transfer Function, you can filter any

    signal using filter command.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    10/41

    Y = FILTER(B,A,X)

    Filter data with an infinite impulseresponse (IIR) or finite impulse response

    (FIR) filter

    y(n) = b(1)*x(n) + b(2)*x(n-1) + ... +

    b(nb+1)*x(n-nb)- a(2)*y(n-1) - ... -

    a(na+1)*y(n-na)

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    11/41

    Time Domain Filtering

    Frequency response of desired filter yields theimpulse response of filter, thus filtering can be

    carried out using:

    Conv Fftfilt

    However, the main problem, i.e. computing the

    impulse response is still left.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    12/41

    Filter DesignFilter Design

    Several approaches for computing

    impulse response of filters, with a desiredcharacteristics

    Parks-McClellan , (firpm and remez

    commands)

    Traditional approximations for filters, such

    as Butterworth, Chebychev, Elliptic, etc.

    Filter Design & Analysis Tool

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    13/41

    Analog filter frequency responseAnalog filter frequency response

    H = FREQS(B,A,W) returns the complex

    frequency response of the analog filterspecified by coefficient vectors b and a.

    [H,W] = FREQS(B,A,F) picks f number offrequencies on which to compute thefrequency response h.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    14/41

    Digital filter frequency responseDigital filter frequency response

    [H,W] = FREQZ(B,A,N) returns the N-point complexfrequency response vector H and the N-point frequency

    vector W in radians/sample of the filter.

    frequency response is evaluated at N points equally

    spaced around the upper half of the unit circle. If Nisn't specified, it defaults to 512.

    [H,W] = FREQZ(B,A,N,'whole') uses N points around

    the whole unit circle.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    15/41

    Example:Example:

    Frequency Response Using FREQZFrequency Response Using FREQZa=[1 3 2 1];

    b=1;[H,w]=freqz(b,a,128);

    semilogy(w,abs(H));

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    16/41

    Example:Example:

    Frequency Response Using FREQSFrequency Response Using FREQS Evaluate frequency response of

    a = [1 0.4 1]; b = [0.2 0.3 1];

    w = logspace(-1,1);

    h=freqs(b,a,w)

    mag = abs(h); phase = angle(h);

    subplot(2,1,1), loglog(w,mag)

    subplot(2,1,2), semilogx(w,phase)

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    17/41

    Example:Example:

    Frequency Response Using FREQSFrequency Response Using FREQS

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    18/41

    Butterworth FilterButterworth Filter

    The frequency response of the

    Butterworth filter is maximally flat (hasno ripples) in the passband, and rolls off

    towards zero in the stopband.

    A Butterworth LP prototype has the

    following characteristic function:

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    19/41

    Butterworth Filter (ContButterworth Filter (Contd)d)

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    20/41

    Chebyshev FilterChebyshev Filter

    having a steeper roll-off and morepassband/stopband ripple than Butterworthfilters

    Chebyshev filters have the property that theyminimize the error between the idealized filtercharacteristic and the actual over the range ofthe filter, but with ripples in the passband or

    stopband.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    21/41

    Chebyshev Filter (ContChebyshev Filter (Contd)d)

    Chebyshev Type I

    It has no ripple in the stopband, but hasripple in the passband. The transfer function

    is:

    where Tn() is a chebyshev polynomial.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    22/41

    Chebyshev Filter (ContChebyshev Filter (Contd)d)

    Chebyshev Type II

    It has no ripple in the passband, but hasripple in the stopband. The transfer function

    is:

    where Tn() is a chebyshev polynomial

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    23/41

    Chebyshev Filter (ContChebyshev Filter (Contd)d)

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    24/41

    Elliptic FilterElliptic Filter

    is a filter with equiripple behavior in

    both the passband and the stopband.

    It minimizes the maximum error in both

    bands, as opposed to a Chebyshev filterwhich exhibits equiripple behavior in thepassband, or the inverse Chebyshev filter

    which has ripples in the stopband.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    25/41

    Elliptic Filter (ContElliptic Filter (Contd)d)

    The magnitude of the frequency response of

    a lowpass elliptic filter is given by:

    where Rn() is a chebyshev rational function.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    26/41

    Elliptic Filter (ContElliptic Filter (Contd)d)

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    27/41

    Filters : ComparisonFilters : Comparison

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    28/41

    Butterworth FilterButterworth Filter

    butter designs lowpass, bandpass, highpass,

    and bandstop digital and analog Butterworthfilters.

    [B,A] = BUTTER(N,Wn) designs an Nth order

    lowpass digital Butterworth filter and returnsthe filter coefficients in length N+1 vectors B

    (numerator) and A (denominator). The cutoff

    frequency Wn must be 0

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    29/41

    Butterworth Filter (ContButterworth Filter (Contd)d)

    If Wn is a two-element vector, Wn = [W1 W2],BUTTER returns an order 2N bandpass filterwith passband W1 < W < W2.

    [B,A] = BUTTER(N,Wn,'high') designs ahighpass filter.

    [B,A] = BUTTER(N,Wn,'low') designs a lowpassfilter.

    [B,A] = BUTTER(N,Wn,'stop') is a bandstop

    filter if Wn = [W1 W2].

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    30/41

    Chebyshev FilterChebyshev Filter

    [b,a] = cheby1(n,R,Wp) designs an order nChebyshev lowpass digital Chebyshev filterwith normalized passband edge frequency Wpand R dB of peak-to-peak ripple in thepassband.

    Normalized passband edge frequency is thefrequency at which the magnitude response of

    the filter is equal to -R dB.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    31/41

    Butterworth ExampleButterworth Example

    [b,a]=butter(7,.32);

    [H,w]=freqz(b,a,128);

    plot(w,abs(H));

    Filt D i ithFilt D i ith

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    32/41

    Filter Design withFilter Design with

    ParksParks--McClellanMcClellan FRIPM command designs a linear-phase FIR

    filter using the Parks-McClellan algorithm.

    Chebyshev approximation is used to fit theoptimal fit between desired and actualresponse.

    b = firpm(n,f,a): returns n+1 coefficients ofthe order n FIR filter whose frequency-amplitude characteristics match those given

    by vectors f and a.

    Filt D i ithFilt D i ith

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    33/41

    Filter Design withFilter Design with

    ParksParks--McClellan (ContMcClellan (Contd)d) f is a vector of pairs of normalized frequency

    points, specified in the range between 0 and1 in increasing order.

    a is a vector containing the desiredamplitudes at the points specified in f.

    f and a must be the same length. The lengthmust be an even number.

    Filt D i ithFilter Design ith

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    34/41

    Filter Design withFilter Design with

    ParksParks--McClellan (ContMcClellan (Contd)d) The desired amplitude at frequencies

    between pairs of points (f(k), f(k+1)) for k oddis the line segment connecting the points(f(k), a(k)) and (f(k+1), a(k+1)).

    The desired amplitude at frequenciesbetween pairs of points (f(k), f(k+1)) for keven is unspecified. The areas between such

    points are transition or "don't care" regions.

    E ample ofExample of

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    35/41

    Example ofExample of

    FIRPM Filter DesignFIRPM Filter Designf = [0 0.3 0.4 0.6 0.7 1];

    a = [0 0 1 1 0 0];

    b = firpm(17,f,a);

    [h,w] = freqz(b,1,512);

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    36/41

    How to read a soundHow to read a sound

    [y,Fs,bits] = wavread('filename',[N1 N2])

    Read Microsoft WAVE (.wav) sound file

    specified in the filename and load its data to

    vector y ( samples N1 through N2).

    Fs returns the sampling frequency and bits

    returns the number of bits used for encoding.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    37/41

    How to write a signal as a soundHow to write a signal as a sound

    wavwrite(y,Fs,N,'filename')

    writes the data stored in the variable y to a

    WAVE file called filename. Fs is sample

    rate and N is the number of bits used forencoding. Amplitude values outside the

    range [-1,+1] are clipped prior to writing.

    N = 8, 16, 24, or 32

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    38/41

    How to make a sound noisy!How to make a sound noisy!

    By using wavread command, first we

    convert a sound into a vector, then weadd noise term to it.

    Common forms of noises are Gaussian

    and Uniform.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    39/41

    Gaussian NoiseGaussian Noise

    Gaussian Noise

    Y = randn(m,n) generates normallydistributed random numbers (noises)

    In order to generate a Gaussian noisesequence with arbitrary statistics, multiply

    the output of randn by the standard

    deviation and then add the desired mean

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    40/41

    UniformUniform NoiseNoise

    Uniform Noise

    Y = rand (m,n) generates unifromlydistributed random numbers (noises) over[0,1] interval.

    In order to generate a uniform distribution ofrandom numbers on a specified interval[a,b], multiply the output of rand by (b-a),

    then add a.

  • 8/3/2019 Frequency Domain Signal Processing Using MATLAB

    41/41

    QuestionsQuestions

    surely, in the creation of the heavensand the earth, there are signs for theowners of wisdom

    The Holy Quran

    Thanks for your attendance.