ADSP-ASSNMNT 2

Embed Size (px)

Citation preview

  • 8/6/2019 ADSP-ASSNMNT 2

    1/18

    I. TIME DOMAIN CHARACTERIZATION

    UP-SAMPLING OPERATION

    The program shown below can be used to study up-sampling of a sinusoidal input sequences, the

    up-sampling factor, and the frequency of the sinusoid in Hz. It then plots the input sequence and

    its up sampled version.

    PROGRAM

    % Illustration of Up-Sampling by an Integer Factor

    clf;

    N = input('Input length = ');

    L = input('Up-sampling Factor = ');

    fo = input('Input signal frequency = ');

    % Generate the input sinusoidal sequence

    n = 0:N-1;

    x = sin(2*pi*fo*n);

    % Generate the up-sampled sequence

    y = zeros(1, L*length(x));

    y([1: L: length(y)]) = x;

    % Plot the input and the output sequences

    subplot(2,1,1)

    stem(n,x);

    title('Input Sequence');

    xlabel('Time index n');ylabel('Amplitude');

    subplot(2,1,2)

    stem(n,y(1:length(x)));

    title(['Output sequence up-sampled by', num2str(L)]);

    xlabel('Time index n');ylabel('Amplitude');

    INPUT DATA

    Length of the Sequence-50

    Frequency:0.12

    Up-sampling factor:3

  • 8/6/2019 ADSP-ASSNMNT 2

    2/18

    INPUT /OUTPUT WAVEFORM

    DOWN

    SAMPLING OPERATION

    The program shown below can be used to study down sampling of a sinusoidal

    input sequences, the down sampling factor, and the frequency of the sinusoid in

    Hz. It then plots the input sequence and its down sampled sampled version.

    PROGRAM

    % Illustration of Down-Sampling by an Integer Factor

    %

    clf;

    N = input('Output length = ');

    M = input('Down-sampling Factor = ');

    fo = input('Input signal frequency = ');

    % Generate the input sinusoidal sequence

    n = 0 : N-1;

    m = 0 : N*M-1;

    0 5 10 15 20 25 30 35 40 45 50-1

    -0.5

    0

    0.5

    1Input Sequence

    Time index n

    Amplitude

    0 5 10 15 20 25 30 35 40 45 50-1

    -0.5

    0

    0.5

    1Output sequence up-sampled by3

    Time index n

    Amplitude

  • 8/6/2019 ADSP-ASSNMNT 2

    3/18

    x = sin(2*pi*fo*m);

    % Generate the down-sampled sequence

    y = x([1 : M : length(x)]);

    % Plot the input and the output sequences

    subplot(2,1,1)

    stem(n, x(1:N));

    title('Input Sequence');

    xlabel('Time index n');ylabel('Amplitude');

    subplot(2,1,2)

    stem(n, y);

    title(['Output sequence down-sampled by ',num2str(M)]);

    ylabel('Amplitude');xlabel('Time index n');

    INPUT DATA

    Length of the Sequence-50

    Frequency: 0.042 Hz

    Down sampling factor: 3

  • 8/6/2019 ADSP-ASSNMNT 2

    4/18

    INPUT/OUTPUT WAVEFORM

    0 5 10 15 20 25 30 35 40 45 50-1

    -0.5

    0

    0.5

    1Input Sequence

    Timeindex n

    Amplitude

    0 5 10 15 20 25 30 35 40 45 50-1

    -0.5

    0

    0.5

    1Output sequencedown-sampledby 3

    Amplitude

    Timeindex n

    II. FREQUENCY DOMAIN CHARACTERIZATION

    FREQUENCY-DOMAIN PROPERTIES OF THE UP-SAMPLER USING MATLAB

    The program determines the output of the up-sampler and then plots the input and

    output spectrums for L=5. The output spectrum consist of a factor of 5 compressed

    version of the input spectrum followed by L-1=4 images.

    PROGRAM

    % Effect of Up-Sampling in the Frequency Domain

    % Use fir2 to create a bandlimited input sequence

    freq = [0 0.45 0.5 1];

    mag = [0 1 0 0];

    x = fir2(99, freq, mag);

    % Evaluate and plot the input spectrum

    [Xz, w] = freqz(x, 1, 512);

  • 8/6/2019 ADSP-ASSNMNT 2

    5/18

    plot(w/pi, abs(Xz)); grid

    xlabel('\omega/\pi'); ylabel('Magnitude');

    title('Input spectrum');

    pause

    % Generate the up-sampled sequence

    L = input('Type in the up-sampling factor = ');

    y = zeros(1, L*length(x));

    y([1: L: length(y)]) = x;

    % Evaluate and plot the output spectrum

    [Yz, w] = freqz(y, 1, 512);

    plot(w/pi, abs(Yz)); grid

    xlabel('\omega/\pi'); ylabel('Magnitude');

    title('Output spectrum');

    INPUT/OUTPUT WAVEFORM

    0 0 . 1 0 . 2 0 . 3 0 . 4 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 1

    0

    0 . 1

    0 . 2

    0 . 3

    0 . 4

    0 . 5

    0 . 6

    0 . 7

    0 . 8

    0 . 9

    1

    /

    M

    agnitude

    In p u t s p e c tru m

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    /

    Magnitude

    Output spectrum

    Fig:MATLAB input and output spectrum of a factor of 5-up-sampler

    FREQUENCY-DOMAIN PROPERTIES OF THE DOWN SAMPLER USING MATLAB

    1. Down sampling factor of M=3,

    2. Down sampling factor of M=2

    PROGRAM

    % Effect of Down-Sampling in the Frequency Domain

    % Use fir2 to create a bandlimited input sequence

  • 8/6/2019 ADSP-ASSNMNT 2

    6/18

    freq = [0 0.42 0.48 1];

    mag = [0 1 0 0];

    x = fir2(101, freq, mag);

    % Evaluate and plot the input spectrum

    [Xz, w] = freqz(x, 1, 512);

    plot(w/pi, abs(Xz)); grid

    xlabel('\omega/\pi'); ylabel('Magnitude');

    title('Input spectrum');

    pause

    % Generate the down-sampled sequence

    M = input('Type in the down-sampling factor = ');

    y = x([1: M: length(x)]);

    % Evaluate and plot the output spectrum

    [Yz, w] = freqz(y, 1, 512);

    plot(w/pi, abs(Yz)); grid

    xlabel('\omega/\pi'); ylabel('Magnitude');

    title('Output spectrum');

    INPUT/OUTPUT WAVEFORM

    0 0 . 1 0 . 2 0 . 3 0 . 4 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 10

    0 . 1

    0 . 2

    0 . 3

    0 . 4

    0 . 5

    0 . 6

    0 . 7

    0 . 8

    0 . 9

    1

    /

    M

    agnitude

    In p u t s p e c t ru m

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

    0.05

    0.1

    0.15

    0.2

    0.25

    0.3

    0.35

    0.4

    0.45

    0.5

    /

    Magnitude

    Output spectrum

  • 8/6/2019 ADSP-ASSNMNT 2

    7/18

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

    0.05

    0.1

    0.15

    0.2

    0.25

    0.3

    0.35

    0.4

    0.45

    0.5

    /

    M

    agnitude

    Output spectrum

    Fig: input spectrum,output spectrum for down sampling factor of M=3,output spectrum for a

    down sampling factor of M=2

    III. DECIMATIONDECIMATION OPERATION USING MATLAB

    We consider the decimation of a sum of two sinusoidal sequences of normalized

    frequencies f1 and f2 by an arbitrary down sampling factor M using program

    shown below. The input data to the program are the length N of the input sequence

    x[n],the down sampling factor M ,and two normalized frequencies in Hz.The

    program uses a 30-tap FIR low pass decimation filter designed to have a stop band

    edge at /M power5 .It then plots the input and the output sequences,for

    N=100,M=2,f1=0.043,f2=0.031.

    PROGRAM:

    % Illustration of Decimation Process%

    clf;

    N = input('Length of input signal = ');

    M = input('Down-sampling factor = ');

    f1 = input('Frequency of first sinusoid = ');

    f2 = input('Frequency of second sinusoid = ');

    n = 0:N-1;

    % Generate the input sequence

    x = sin(2*pi*f1*n) + sin(2*pi*f2*n);

  • 8/6/2019 ADSP-ASSNMNT 2

    8/18

    % Generate the decimated output sequence

    y = decimate(x,M,'fir');

    % Plot the input and the output sequences

    subplot(2,1,1)

    stem(n,x(1:N));

    title('Input sequence');

    xlabel('Time index n');ylabel('Amplitude');

    subplot(2,1,2)

    m=0:N/M-1;

    stem(m,y(1:N/M));

    title('Output sequence');

    xlabel('Time index n'); ylabel('Amplitude');

    INPUT/OUTPUT WAVEFORM

    0 10 20 30 40 50 60 70 80 90 100-2

    -1

    0

    1

    2Input sequence

    Time index n

    Am

    plitude

    0 5 10 15 20 25 30 35 40 45 50-2

    -1

    0

    1

    2Output sequence

    Time index n

    Am

    plitude

  • 8/6/2019 ADSP-ASSNMNT 2

    9/18

    IV. INTERPOLATION

    INTERPOLATION OPERATION USING MATLAB

    To illustrate interpolation process,we consider an input x that is given by a sum of two sinusoidal

    sequences. Program is used to find its interpolated output y for an upsampling factor of L. The

    input data to th program are the length N of the input vector x,the upsamler factor L,anKd two

    normalized frequencies in hz.The frequencies of the sinusoids considered here are the f1=0.043

    and f2=0.031,while the interpolation factor is 2.The input length is 50.

    PROGRAM:

    % Illustration of Interpolation Process

    %

    clf;

    N = input('Length of input signal = ');

    L = input('Up-sampling factor = ');

    f1 = input('Frequency of first sinusoid = ');

    f2 = input('Frequency of second sinusoid = ');

    % Generate the input sequence

    n = 0:N-1;

    x = sin(2*pi*f1*n) + sin(2*pi*f2*n);

    % Generate the interpolated output sequence

    y = interp(x,L);

    % Plot the input and the output sequences

    subplot(2,1,1)

    stem(n,x(1:N));

    title('Input sequence');

    xlabel('Time index n'); ylabel('Amplitude');

    subplot(2,1,2)

    m=0:N*L-1;

    stem(m,y(1:N*L));

    title('Output sequence');

    xlabel('Time index n'); ylabel('Amplitude');

  • 8/6/2019 ADSP-ASSNMNT 2

    10/18

    INPUT/OUTPUT WAVEFORM:

    0 5 10 15 20 25 30 35 40 45 50-2

    -1

    0

    1

    2Input sequence

    Timeindexn

    Amplitude

    0 10 20 30 40 50 60 70 80 90 100-2

    -1

    0

    1

    2Output sequence

    Timeindexn

    Amplitude

    V. SAMPLE RATE ALTERATION

    SAMPLE RATE ALTERATION BY A RATIO OF TWO INTEGERS

    In this program, we consider the sampling rate increase by a ratio of two positive integers of a

    signal composed of two sinusoids. The input data to the program are the length N of the input

    vector x, the upsampling factor L, the down sampling factor M, and the two frequencies.

    PROGRAM

    % Program

    % Illustration of Sampling Rate Alteration by

    % a Ratio of Two Integers

    %

    clf;

    N = input('Length of input signal = ');

    L = input('Up-sampling factor = ');

    M = input('Down-sampling factor = ');

    f1 = input('Frequency of first sinusoid = ');

    f2 = input('Frequency of second sinusoid = ');

    % Generate the input sequence

  • 8/6/2019 ADSP-ASSNMNT 2

    11/18

    n = 0:N-1;

    x = sin(2*pi*f1*n) + sin(2*pi*f2*n);

    % Generate the resampled output sequence

    y = resample(x,L,M);

    % Plot the input and the output sequences

    subplot(2,1,1)

    stem(n,x(1:N));

    title('Input sequence');

    xlabel('Time index n'); ylabel('Amplitude');

    subplot(2,1,2)

    m=0:N*L/M-1;

    stem(m,y(1:N*L/M));

    title('Output sequence');

    xlabel('Time index n'); ylabel('Amplitude');

    INPUT

    Length of input signal = 25

    Up-sampling factor = 5

    Down-sampling factor = 3

    Frequency of first sinusoid = 0.043

    Frequency of second sinusoid = 0.031

    INPUT/OUTPUT WAVEFORM

  • 8/6/2019 ADSP-ASSNMNT 2

    12/18

    0 5 10 15 20 25-2

    -1

    0

    1

    2Input sequence

    Time index n

    Amplitude

    0 5 10 15 20 25 30 35 40-2

    -1

    0

    1

    2Output sequence

    Time index n

    Amp

    litude

    Fig: Illustration Of Sample Rate Increases By A Rational Number 5/3

    VI. NYQUIST FILTERS

    DESIGN OF Lth BAND FIR FILTER USING THE WINDOWED FORIER SERIES APPROACH

    Design a length-23 half-band (L=2) linear phase low pass filter using the

    windowed forier series approach with a Hamming window.

    PROGRAM

    % Program

    % Design of Lth Band FIR Filter Using the

    % Windowed Fourier Series Approach

    %

  • 8/6/2019 ADSP-ASSNMNT 2

    13/18

    N = input('Type in the filter length = ');

    L = input('Type in the value of L = ');

    K = (N-1)/2;

    n = -K:K;

    % Generate the truncated impulse response of the ideal

    % lowpass filter

    b = sinc(n/L)/L;

    % Generate the window sequence

    win = hamming(N);

    % Generate the coefficients of the windowed filter

    c = b.*win';

    % Plot the gain response of the windowed filter

    [h,w] = freqz(c,1,256);

    g = 20*log10(abs(h));

    plot(w/pi,g);grid

    xlabel('\omega/\pi');ylabel('Gain, dB');

    INPUT

    Type in the filter length = 23

    Type in the value of L = 2

    INPUT/OUTPUT WAVEFORM

  • 8/6/2019 ADSP-ASSNMNT 2

    14/18

    VII. QMF FILTER BANK

    FREQUENCY RESPONSES OF JOHNSTON'S QMF FILTERS

    The impulse response coefficients of the length -12 linear phase low pass filter 12B

    of Johnston are given by

    Filter coefficients = -0.006443977 -0.00758164 +0.09808522 +0.02745539 -0.0913825

    +0.4807962

    Matlab program is used to verify the performance of the above filter H0(z).

    PROGRAM

    % Program

    % Frequency Responses of Johnston's QMF Filters

    % Type in prototype lowpass filter coefficients

    clf;

    B1 = input('Filter coefficients = ');

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

    -80

    -60

    -40

    -20

    0

    20

    /

    Gain,

    dB

  • 8/6/2019 ADSP-ASSNMNT 2

    15/18

    B1 = [B1 fliplr(B1)];

    % Generate the complementary highpass filter

    L = length(B1);

    for k = 1:L

    B2(k) = ((-1)^k)*B1(k);

    end

    % Compute the gain responses of the two filters

    [H1z, w] = freqz(B1, 1, 256);

    h1 = abs(H1z); g1 = 20*log10(h1);

    [H2z, w] = freqz(B2, 1, 256);

    h2 = abs(H2z); g2 = 20*log10(h2);

    % Plot the gain responses of the two filters

    plot(w/pi, g1,'-',w/pi, g2,'--');axis([0 1 -80 5]);grid

    xlabel('Normalized frequency');ylabel('Gain in dB')

    pause

    % Compute the sum of the square magnitude responses

    for i = 1:256,

    sum(i) = (h1(i)*h2(i)) + (h2(i)*h1(i));

    end

    d =10*log10(sum);

    % Plot the sum of the square magnitude responses

    plot(w/pi,sum);grid;

    xlabel('Normalized frequency')

    ylabel('Amplitude distortion in dB')

    INPUT

    Filter coefficients = -0.006443977 -0.00758164 +0.09808522 +0.02745539 -0.0913825

    +0.4807962

  • 8/6/2019 ADSP-ASSNMNT 2

    16/18

    INPUTOUTPUT WAVEFORM

    Fig: Johnstons 12 B filter: Gain respons

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 10

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    1.4

    Normalizedfrequency

    AmplitudedistortionindB

    Fig: Johnstons 12 B filter: Amplitude distortion

    FREQUENCY RESPONSES OF TREE-STRUCTURED QMF FILTERS

    Design of a four channel QMF bank by iterating the two-channel QMF bank based on the filter

    12B of Johnston

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-80

    -70

    -60

    -50

    -40

    -30

    -20

    -10

    0

    Normalizedfrequency

    GainindB

  • 8/6/2019 ADSP-ASSNMNT 2

    17/18

    PROGRAM

    % Program

    % Frequency Responses of Tree-Structured QMF Filters

    %

    clf;

    % Type in prototype lowpass filter coefficients

    B = input('Filter coefficients = ');

    B1 = [B fliplr(B)];

    % Generate the complementary highpass filter

    L = length(B1);

    for k = 1:LB2(k) = ((-1)^k)*B1(k);

    end

    % Determine the coefficients of the four filters

    B10 = zeros(1, 2*length(B1));

    B10([1: 2: length(B10)]) = B1;

    B11 = zeros(1, 2*length(B2));

    B11([1: 2: length(B11)]) = B2;

    C0 = conv(B1, B10);C1 = conv(B1, B11);

    C2 = conv(B2, B10);C3 = conv(B2, B11);

    % Determine the frequency responses

    [H0z, w] = freqz(C0, 1, 256);

    h0 = abs(H0z);

    M0 = 20*log10(h0);

    [H1z, w] = freqz(C1, 1, 256);

    h1 = abs(H1z);

    M1 = 20*log10(h1);

    [H2z, w] = freqz(C2, 1, 256);

    h2 = abs(H2z);

    M2 = 20*log10(h2);

  • 8/6/2019 ADSP-ASSNMNT 2

    18/18

    [H3z, w] = freqz(C3, 1, 256);

    h3 = abs(H3z);

    M3 = 20*log10(h3);

    plot(w/pi, M0,'r-',w/pi, M1,'b--',w/pi, M3,'g-.',w/pi, M2,'m:');grid

    axis([0 1 -100 20]);

    xlabel('\omega /\pi');ylabel('Gain, dB')

    legend('H_{O}(z)','H_{1}(z)', 'H_{2}(z)', 'H_{3}(z)')

    INPUT

    Filter coefficients = -0.006443977 -0.00758164 +0.09808522 +0.02745539 -0.0913825

    +0.4807962

    INPUTOUTPUT WAVEFORM

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-100

    -80

    -60

    -40

    -20

    0

    20

    /

    Gain

    ,dB

    HO(z)

    H1(z)

    H2(z)

    H3(z)