Meril Final List to Be Given

download Meril Final List to Be Given

of 64

Transcript of Meril Final List to Be Given

  • 8/6/2019 Meril Final List to Be Given

    1/64

    Expt 1:Basic Matlab Programs

    Program 1

    Generate unit impulse and unit step signal

    clc;

    clearall;close all;

    n=-10:20;

    i=(n==0);subplot(2,2,1);stem(n,i);

    title('impulse response');

    xlabel('range');

    ylabel('Amplitude');s=(n>=0);

    subplot(2,2,2);

    stem(n,s);

    title('step response');xlabel('range');

    ylabel('amplitude');

  • 8/6/2019 Meril Final List to Be Given

    2/64

    Program 2

    Plot the magnitude and phase response of fourier transform of sequence

    x(n)= 0.5n u(n)

    clc;clearall;

    close all;

    w=-pi:0.1:pi;b=[1];

    a=[1 0.5];

    h=freqz(b,a,w);

    x=real(h);y=imag(h);

    subplot(2,2,3);

    stem(w/pi,x);

    title('real part');subplot(2,2,4);

    stem(w/pi,y);title('imaginary part');

    mag=abs(h);

    ph=angle(h);

    subplot(2,2,1);plot(w/pi,mag);

    title('mag response');

    subplot(2,2,2);plot(w/pi,ph);

    title('phase response');

  • 8/6/2019 Meril Final List to Be Given

    3/64

  • 8/6/2019 Meril Final List to Be Given

    4/64

    Program 3

    Find the Convolution of two sequences

    x(n)={1,0,1,2,-1,3,2}

    h(n)={1,1,2,2,1,1}

    clc;

    clearall;

    close all;x=input('enter the value x(n)');

    h=input('enter the value h(n)');

    y=conv(x,h);

    stem(y);xlabel('n');

    ylabel('amplitude');

    title('convolution');

    enter the value x(n)[1 0 1 2 -1 3 2]

    enter the value h(n)[1 1 2 2 1 1]

  • 8/6/2019 Meril Final List to Be Given

    5/64

    Program 4

    Generate a complex exponential sequence of the form exp(-1/12)+j*(pi/6)n

    clc;clearall;

    close all;

    m1=input('enter the value for m1');m2=input('enter the value for m2');

    n=-m1:m2;

    y=((-1/12)+j*(pi/6));p=y*n;

    x=exp(p);

    stem(n,x);

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

    enter the value for m110

    enter the value for m223

  • 8/6/2019 Meril Final List to Be Given

    6/64

    Program 5

    Consider 50 points of a 10 Hz sinusoid sampled at fs=50 Hz and scaled by T.

    Compute the 50 point FFT of the sequence and plot the spectrum.

    clc;clearal;

    close all;

    t=input('enter the value of t');n=0:49;

    x=t*sin(((2*pi*10)/50)*n);

    figure(1);

    stem(n,x);figure(2);

    y=fft(x,50);

    stem(n,abs(y));

    figure(3);stem(n,angle(y));

    enter the value of t.02

  • 8/6/2019 Meril Final List to Be Given

    7/64

  • 8/6/2019 Meril Final List to Be Given

    8/64

    Program 6

    Compute 32 point DFT X(K) of length 32 sinusoidal sequence x(n) of frequency 10

    Hz with a sampling rate of 64 Hz.

    clc;

    clearal;

    close all;n=0:31;

    x=sin(((2*pi*10)/64)*n);

    figure(1);

    stem(n,x);title('input sigmal');

    figure(2);

    y=fft(x,32);

    stem(n,abs(y));title('32-point dft');

  • 8/6/2019 Meril Final List to Be Given

    9/64

  • 8/6/2019 Meril Final List to Be Given

    10/64

    Program 7

    Verify that convolution in time domain is equal to multiplication in frequency

    domain.

    x1=input ('enter the seq1');

    x2=input('enter the seq2');l1=length(x1)

    l2=length(x2)

    y=conv(x1,x2);figure(1);

    stem(y);

    xlabel('n');

    ylabel('amplitude');title('covoluted sequence');

    y1=fft(x1,(l1+l2-1));

    y2=fft(x2,(l1+l2-1));

    x=y1.*y2;x1=ifft(x,(l1+l2-1));

    figure(2);stem(x1);xlabel('n');

    ylabel('amplitude');

    title('recovered sequence');

    enter the seq1[1 2 3 4]

    enter the seq2[1 1 1]

  • 8/6/2019 Meril Final List to Be Given

    11/64

  • 8/6/2019 Meril Final List to Be Given

    12/64

    Program 8

    Find the DFT and IDFT of a sequence without using the formula

    clc;

    clearall;

    close all;xn= input('enter the values of x');

    N=input ('enter the value of N');

    a=exp(-j*2*pi/N);fork=1:N

    X(k)=0;

    forn=1:N

    X(k)=X(k)+ xn(n)*a^((n-1)*(k-1));end

    end

    display(X)

    forn=1:Nx(n)=0;

    fork=1:Nx(n)=x(n)+ X(k)*a^(-(n-1)*(k-1));

    end

    end

    display(x/N)

    enter the values of x [1 2 3 4]

    enter the value of N 4

    X =

    10.0000 -2.0000 + 2.0000i -2.0000 - 0.0000i -2.0000 - 2.0000i

    ans =

    1.0000 - 0.0000i 2.0000 - 0.0000i 3.0000 - 0.0000i 4.0000 + 0.0000i

  • 8/6/2019 Meril Final List to Be Given

    13/64

    Program 9

    Determine the first 41 samples of the impulse response and step response of the

    causal LTI system described by

    y(n)+.7y(n-1)-.45y(n-2)-.6y(n-3) = .8x(n)-.44x(n-1)+.36x(n-2)+.02x(n-3)

    clc;clearall;

    close all;

    b=[0.8 -0.44 0.36 0.02];a=[1 0.7 -0.45 -0.6];

    n=0:41;

    x=(n==0);

    y=(n>=0);imp=filter(b,a,x);

    st=filter(b,a,y);

    subplot(2,2,1);

    stem(n,imp);title('impulse response');

    subplot(2,2,2);stem(n,st);

    title('step response');

    [h,n]=impz(b,a,41);

    subplot(2,2,3);stem(n,h);

    title('impulse response');

    [w,n]=stepz(b,a,41);subplot(2,2,4);

    stem(n,w);

    title('step response');

  • 8/6/2019 Meril Final List to Be Given

    14/64

  • 8/6/2019 Meril Final List to Be Given

    15/64

    ANALOG FILTER DESIGN

    Program 1

    Determine the transfer function of an analog 4th order maximally flat LPF with cut

    off frequency of 1rad/second.Plot the gain response also.

    clear all;

    close all;

    w=0:0.01:20;

    [z,p,k]=buttap(4);

    [b,a]=zp2tf(z,p,k)

    h=freqs(b,a,w);

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

    plot(w,mag);

    grid on;

    ylabel('magnitude in db');

    xlabel('angular frequency');

    OUTPUT

    b =

    0 0 0 0 1

    a =

    1.0000 2.6131 3.4142 2.6131 1.0000

  • 8/6/2019 Meril Final List to Be Given

    16/64

  • 8/6/2019 Meril Final List to Be Given

    17/64

    Program 2

    Determine the lowest order Low pass chebyshev filter with 0.25dB cutoff frequency

    at 1.5Khz and a minimum attenuation of 25dB at 6Khz without using inbuilt

    commands. Verify the results using cheb1ord.

    clear all;

    close all;

    wp=input('enter pass band edge');

    ws=input('enter stopband edge');

    rp=input('enter passband ripple in db');

    rs=input('enter stopband ripple in db');

    ds=10^(2*rs/20)

    dp=10^(2*rp/20)

    x=sqrt(ds-1);

    y=sqrt(dp-1);

    N=acosh(x/y)/acosh(ws/wp)

    [n,wn]=cheb1ord((2500*pi),(12000*pi),.25,25,'s')

    OUTPUT

    enter pass band edge3000*pienter stopband edge12000*pi

    enter passband ripple in db.25

    enter stopband ripple in db25

    ds =

    316.2278

    dp =

    1.0593

    N =

    2.4148

    n =

    3

    wn =

    7.8540e+003

  • 8/6/2019 Meril Final List to Be Given

    18/64

    Program 3

    Design a butterworth LPF with .25 db cut off frequency at 1.5KHz and

    minimum attenuation of 25db at 6khz.plot the gain response and verify that the

    filter design meets given specification.

    clc;

    clear all;

    close all;

    w=0:100:50000;

    [n,wn]=buttord(3000*pi,12000*pi,.25,25,'s');

    [b,a]=bu tter(n,wn,'s');

    h=freqs(b,a,w);

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

    plot(w/(2*pi),mag);

    grid on;

    xlabel(' frequency');

    ylabel('magnitude');

    title('Magnitude response of butterworth LPF');

    OUTPUT

  • 8/6/2019 Meril Final List to Be Given

    19/64

    Program 3

    Design a chebychev hpf with 1 db cut off frequency at 700hz and

    minimum attenuation of 32db at 500hz.plot the gain response and verify that the

    filter design meets given specification.The maximum input frequency is 1000hz.

    clc;

    clear all;

    fp=input('enter passband edge frequency');fs=input('enter stopband edge frequency');

    rp=input('enter passband ripple in db');

    rs=input('enter ripple in stopbandin db');

    wp=2*pi*fp;ws=2*pi*fs;

    w=0:50:40000;[n,wp] = cheb1ord(wp,ws,rp,rs,'s')

    [b,a] = cheby1(n,rp,wp,'high','s')

    h=freqs(b,a,w);m=20*log10(abs(h));

    plot(w/(2*pi),m);

    grid on

    title('gain response ');xlabel('frequency in hertz');

    ylabel('absolute magnitude in db');

    enter passband edge frequency700

    enter stopband edge frequency500

    enter passband ripple in db1enter ripple in stopbandin db32

    n =

    6

    wp =

    4.3982e+003

    b =

    0.8913 0 0 0 0 0 0

  • 8/6/2019 Meril Final List to Be Given

    20/64

    a =

    1.0e+023 *

    0.0000 0.0000 0.0000 0.0000 0.0000 0.0002 1.0505

  • 8/6/2019 Meril Final List to Be Given

    21/64

    Program 4

    Determine the transfer function of a Low pass type chebyshev1 analog filter with .

    25 db cutoff frequency at 1.5Khz and minimum attenuation of 25 db at 6Khz.Plot

    gain response.

    clc;clear all;

    close all;

    wp=input('enter pass band frequency');

    ws=input('enter stop band frequency');rp=input('pass band ripples');

    rs=input('stop band ripples');

    w=0:100:65000;

    [n,wp]=cheb1ord(wp,ws,rp,rs,'s')[b,a]=cheby1(n,rp,wp,'s')

    h=freqs(b,a,w);mag=20*log10(abs(h));

    plot(w/(2*pi),mag);

    xlabel('angular frequency');

    ylabel('magnitude');title('Magnitude response of chebyshev 1 LPF');

    grid on;

    OUTPUT

    enter pass band frequency 3000*pienter stop band frequency 12000*pi

    pass band ripples .25

    stop band ripples 25

    n =

    3

    wp =

    9.4248e+003

    b =

    1.0e+011 *

  • 8/6/2019 Meril Final List to Be Given

    22/64

    0 0 0 8.5980

    a =

    1.0e+011 *

    0.0000 0.0000 0.0017 8.5980

  • 8/6/2019 Meril Final List to Be Given

    23/64

  • 8/6/2019 Meril Final List to Be Given

    24/64

    n1 =

    4

    wn =

    121.7901

  • 8/6/2019 Meril Final List to Be Given

    25/64

    Program 6

    Design an analog chebychev type1 filter with following specifications. Pass band

    edges at 4KHz and 7KHz.Stop band edges at 3KHz and 8KHz.Passband ripple of

    2dB and stopband attenution of 50dB.

    clear all;

    close all;

    w=0:1000:20000*pi;

    wp1=input('enter pass band edge1');

    wp2=input('enter pass band edge2');

    ws1=input('enter stopband edge1');

    ws2=input('enter stopband edge2w0');

    rp=input('enter passband ripple in db');

    rs=input('enter stopband ripple in db');

    w0=sqrt(wp2*wp1);

    wp=1;

    a=ws1*ws2;

    b=wp1*wp2;

    if(a

  • 8/6/2019 Meril Final List to Be Given

    26/64

  • 8/6/2019 Meril Final List to Be Given

    27/64

    Program 7

    Design an analog chebychev type1 band stop filter with following specifications.Pass

    band edges at 100Hz and 600Hz.Stop band edges at 200Hz and 400Hz.Passband

    rippleof 3dB and stopband attenution of 20dB.

    clear all;

    close all;

    w=0:100:2000*pi;

    wp1=input('enter pass band edge1');

    wp2=input('enter pass band edge2');

    ws1=input('enter stopband edge1');

    ws2=input('enter stopband edge2w0');

    rp=input('enter passband ripple in db');

    rs=input('enter stopband ripple in db');

    w0=sqrt(ws2*ws1);

    ws=1;

    a=ws1*ws2;

    b=wp1*wp2;

    if(a>b)

    wp11=w0^2/wp2;

    wp=(ws2-ws1)/(wp2-wp11);

    else

    wp22=w0^2/wp1;

    wp=(ws2-ws1)/(wp22-wp1);

    end

    bw=ws2-ws1;

    [n,wp]=cheb1ord(wp,ws,rp,rs,'s');

    [b,a]=cheby1(n,rp,wp,'s');

    [bt,at]=lp2bs(b,a,w0,bw);

    h=freqs(bt,at,w);

    m1=abs(h);m=20*log10(m1);

    plot(w/(2*pi),m);

    xlabel('angular frequncy ');

    ylabel('magnitude in decibels');

    title('magnitude respinse');

    grid on;

    enter pass band edge1200*pi

    enter pass band edge21200*pienter stopband edge1400*pi

    enter stopband edge2w0800*pienter passband ripple in db3enter stopband ripple in db20

  • 8/6/2019 Meril Final List to Be Given

    28/64

  • 8/6/2019 Meril Final List to Be Given

    29/64

    Expt 2 IIRDIGITAL FILTER DESIGN

    Program 1

    Using bilinear transformation method design digital low pass butterworth filter

    with a maximum input frequency of 5KHz. at a sampling rate of with followingspecifications. Pass band edge at 2500Hz Stop band edges at 3000Hz .Pass band

    ripple of 1dB Minimum stop band attenuation of 10dB.Plot the gain response.

    clear all;

    close all;

    fp=input('enter pass band edge frequency in hz');

    fs=input('enter stopband edge frequency in hz');

    rp=input('enter passband ripple in db');

    rs=input('enter stopband ripple in db');

    fm=input('enter the maxinput frequency');

    fsa=2*fm;wp=2*pi*fp/fsa;

    ws=2*pi*fs/fsa;

    wp1=wp/pi;

    ws1=ws/pi;

    w=0:0.01:pi;

    [n,wp]=cheb1ord(wp/pi,ws/pi,rp,rs);

    [b,a]=cheby1(n,rp,wp);

    h=freqz(b,a,w);

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

    plot(w/pi,m);

    grid on;

    enter pass band edge frequency in hz2500enter stopband edge frequency in hz3000

    enter passband ripple in db1

    enter stopband ripple in db10enter the maxinput frequency5000

  • 8/6/2019 Meril Final List to Be Given

    30/64

  • 8/6/2019 Meril Final List to Be Given

    31/64

    Program 2

    Using bilinear transformation method design digital high pass butterworth filter at

    a sampling rate of 1.5MHz with following specifications. Pass band edge at 600 KHz

    Stop band edges at 210 KHz .Pass band ripple of 0.4dBMinimum stop bandattenuation of 45dB.What are the specifications of analog prototype LPF .Show all

    TFs. Plot the gain response of prototype analog LPF, analog HPF and desired

    digital HPF

    clc;

    clear all;

    close all;

    ft=input('entere sampling frequency');

    T=1/ft;

    fp=input('enter passband edge frequency');

    fs=input('enter stopband edge frequency');

    rp=input('enter passband ripple in db');

    rs=input('enter ripple in stopbandindb');w1=0:0.1:10;

    w=0:0.01:pi;

    w2=0:1000:10000000;

    wp=2*pi*fp/ft

    ws=2*pi*fs/ft

    omp=2/T*(tan(wp/2))

    oms=2/T*(tan(ws/2))

    oms1=omp/oms

    omp1=1

    [n,omp1] = cheb1ord(omp1,oms1,rp,rs,'s')

    [b,a] = cheby1(n,rp,omp1,'s');

    h1=freqs(b,a,w1);

    m1=20*log10(abs(h1));figure;

    plot(w1,m1);

    grid on;

    xlabel('angular frequency ');

    ylabel('magnitude in decibels');

    title('magnitude response of lpf');

    [bt,at]=lp2hp(b,a,omp);

    h2=freqs(bt,at,w2);

    m2=20*log10(abs(h2));

    figure;

    plot(w2,m2);

    grid on;

    xlabel('angular frequency ');

    ylabel('magnitude in decibels');title('magnitude response of analog hpf');

    [nr,dr]=bilinear(bt,at,ft);

    h=freqz(nr,dr,w);

    m=20*log10(abs(h))

    figure;

    plot((w*ft)/(2*pi),m);

    xlabel(' frequency ');

    ylabel('magnitude in decibels');

  • 8/6/2019 Meril Final List to Be Given

    32/64

    title('magnitude response of digital hpf');

    grid on;

    OUTPUTentere sampling frequency1500000

    enter passband edge frequency600000

    enter stopband edge frequency210000enter passband ripple in db.4

    enter ripple in stopbandindb45

    wp =

    2.5133

    ws =

    0.8796

    omp =

    9.2331e+006

    oms =

    1.4117e+006

    oms1 =

    6.5404

    omp1 =

    1

    n =

    3

    omp1 =

    1

  • 8/6/2019 Meril Final List to Be Given

    33/64

  • 8/6/2019 Meril Final List to Be Given

    34/64

    Program 3

    Design a digital band pass filter with following specifications

    Pass band edges at .45 pi and .65 pi

    Stopband edges at.3pi and .75pi

    Pass band ripple -1dBStopband attenuation-40dB

    clear all;

    close all;

    w=0:0.01:pi;

    fs=input('enter the sampling frequency');

    wp1=input('enter pass band edge1');

    wp2=input('enter pass band edge2');

    ws1=input('enter stopband edge1');

    ws2=input('enter stopband edge2w0');

    rp=input('enter passband ripple in db');rs=input('enter stopband ripple in db');

    T=1/fs;

    wp1new=(2/T)*tan(wp1*pi/2);

    wp2new=(2/T)*tan(wp2*pi/2);

    ws1new=(2/T)*tan(ws1*pi/2);

    ws2new=(2/T)*tan(ws2*pi/2);

    w0=sqrt(wp2new*wp1new);

    wp=1;

    a=ws1new*ws2new;

    b=wp1new*wp2new;

    if(a

  • 8/6/2019 Meril Final List to Be Given

    35/64

    enter stopband edge1.3

    enter stopband edge2w0.75

    enter passband ripple in db1enter stopband ripple in db40

    >>

  • 8/6/2019 Meril Final List to Be Given

    36/64

    Program 4

    Design a digital band stop filter with following specifications

    Pass band edges at .45 pi and .65 pi

    Stopband edges at.3pi and .75pi

    Pass band ripple -1dBStopband attenuation-40dB

    clear all;

    close all;

    w=0:0.1:pi;

    fs=input('enter the sampling frequency');

    wp1=input('enter pass band edge1');

    wp2=input('enter pass band edge2');

    ws1=input('enter stopband edge1');

    ws2=input('enter stopband edge2w0');

    rp=input('enter passband ripple in db');rs=input('enter stopband ripple in db');

    T=1/fs;

    wp1new=(2/T)*tan(wp1*pi/2);

    wp2new=(2/T)*tan(wp2*pi/2);

    ws1new=(2/T)*tan(ws1*pi/2);

    ws2new=(2/T)*tan(ws2*pi/2);

    w0=sqrt(ws2new*ws1new);

    ws=1;

    a=ws1new*ws2new;

    b=wp1new*wp2new;

    if(a>b)

    wp11=w0^2/wp2new;

    wp=(ws2new-ws1new)/(wp2new-wp11);else

    wp22=w0^2/wp1new;

    wp=(ws2new-ws1new)/(wp22-wp1new);

    end

    bw=ws2new-ws1new;

    [n,wp]=cheb1ord(wp,ws,rp,rs,'s');

    [b,a]=cheby1(n,rp,wp,'s');

    [bt,at]=lp2bs(b,a,w0,bw);

    [nr,dr]=bilinear(bt,at,fs);

    h=freqz(nr,dr,w);

    m1=abs(h);

    m=20*log10(m1);

    plot(w/pi,m);

    xlabel('angular frequncy ');ylabel('magnitude in decibels');

    title('magnitude respinse');

    grid on;

    OUTPUTenter the sampling frequency.5

  • 8/6/2019 Meril Final List to Be Given

    37/64

    enter pass band edge1.3

    enter pass band edge2.75

    enter stopband edge1.45enter stopband edge2w0.65

    enter passband ripple in db1

    enter stopband ripple in db40

  • 8/6/2019 Meril Final List to Be Given

    38/64

    Program 5

    Design digital low pass butterworth filter with following specifications. Pass band

    edge at .25pi. Stop band edges at .55pi.Pass band ripple of 0.5dBMinimum stop

    band attenuation of 15dB. Plot the gain response

    clear all;

    close all;wp=input('enter pass band edge');

    ws=input('enter stopband edge');

    rp=input('enter passband ripple in db');

    rs=input('enter stopband ripple in db');

    w=0:0.01:pi;

    [n,wn]=buttord(wp,ws,rp,rs);

    [b,a]=butter(n,wn);

    h=freqz(b,a,w);

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

    plot(w/pi,m);

    grid on;

    enter pass band edge .25enter stopband edge.55

    enter passband ripple in db.5enter stopband ripple in db15

  • 8/6/2019 Meril Final List to Be Given

    39/64

    Program 6

    Design digital high pass butterworth filter with following specifications. Pass band

    edge at 700Hz. Stop band edges at 500Hz.Pass band ripple of 1dB.Minimum stop

    band attenuation of 32dB.The maximum input frequency is 1KHz. Plot the gain

    responseclear all;

    close all;

    fp=input('enter pass band edge frequency in hz');

    fs=input('enter stopband edge frequency in hz');

    rp=input('enter passband ripple in db');

    rs=input('enter stopband ripple in db');

    fm=input('enter the maxinput frequency');

    fsa=2*fm;

    wp=2*pi*fp/fsa;

    ws=2*pi*fs/fsa;

    wp1=wp/pi;

    ws1=ws/pi;

    w=0:0.01:pi;

    [n,wn]=cheb1ord(wp1,ws1,rp,rs);

    [b,a]=cheby1(n,rp,wn,'high');h=freqz(b,a,w);

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

    plot(w/pi,m);

    grid on;

    enter pass band edge frequency in hz 700

    enter stopband edge frequency in hz500

    enter passband ripple in db1enter stopband ripple in db32

    enter the maxinput frequency1000

  • 8/6/2019 Meril Final List to Be Given

    40/64

    I

  • 8/6/2019 Meril Final List to Be Given

    41/64

    Program 7

    Using impulse invariant transformation method design digital high pass

    butterworth filter at a sampling rate 0.5 with following specifications. Pass band

    edge at .25*pi.Stop band edges at .55*pi .Pass band ripple of 0.5dB.Minimum stop

    band attenuation of 15dB. Plot the gain response

    clc;

    clear all;

    close all;

    w=0:0.01:pi;

    fs=input('enter sampling frequency');

    T=1/fs;

    omp=input('enter passband edge frequency');

    oms=input('enter stopband edge frequency');

    rp=input('enter ripple in passband in db');

    rs=input('enter ripple in stopbandin db');

    wp=omp/pi;

    ws=oms/pi;

    [n,wn] = buttord(wp,ws,rp,rs,'s')

    [b,a] =butter(n,wn,'s');[nr,dr]=impinvar(b,a,fs);

    h=freqz(nr,dr,w);

    m=20*log10(abs(h))

    plot(w/pi,m);

    grid on

    title('magnitude response');

    xlabel('normalised frequency in radians');

    ylabel('absolute magnitude in db');

    enter sampling frequency0.5enter passband edge frequency0.25*pi

    enter stopband edge frequency0.55*pi

    enter ripple in passband in db0.5enter ripple in stopbandin db15

  • 8/6/2019 Meril Final List to Be Given

    42/64

  • 8/6/2019 Meril Final List to Be Given

    43/64

    Expt 3 FIR DIGITAL FILTER DESIGN

    Program 1

    Design an FIR LPF for cut off frequency of.5*pi. Let the order of the filter be

    49.Use rectangular and hann windows.

    clear all;

    close all;

    wp=input('enter cut off frequency');

    N=input('enter the length of filter');

    t=(N-1)/2;

    e=0.001;

    n=0:N-1;

    hd=(sin((n-t+e)*wp))./((n-t+e)*pi);

    wr=boxcar(N);

    hn=hd.*wr';

    w=0:0.01:pi;

    h=freqz(hn,1,w);

    figure;

    plot(w,(20*log10(abs(h))));

    hold on;

    plot(w,unwrap(angle(h)),'r');

    grid on;

    xlabel('angular frequency');

    ylabel('magnitude and phase ');

    title('magnitude and phase response of lpf using rectangular window');

    hd=(sin((n-t+e)*wp))./((n-t+e)*pi);

    wr=hann(N);

    hn=hd.*wr';

    w=0:0.01:pi;

    h=freqz(hn,1,w);

    figure;plot(w,(20*log10(abs(h))));

    hold on;

    plot(w,unwrap(angle(h)),'r');

    grid on;

    xlabel('angular frequency');

    ylabel('magnitude ');

    title('magnitude response of lpf using hann window');

    enter cut off frequency.5*pi

    enter the length of filter7

  • 8/6/2019 Meril Final List to Be Given

    44/64

  • 8/6/2019 Meril Final List to Be Given

    45/64

    Program 2

    Design an FIR HPF for cut off frequency of.5*pi.Let the order of the filter be 49.Use

    hamming and blackmann windows.

    clc;

    clear all;

    close all;wp=input('enter cut off frequency');

    N=input('enter the length of filter');

    t=(N-1)/2;

    e=0.001;

    n=0:N-1;

    hd=(sin((n-t+e)*pi)-sin((n-t+e)*wp))./((n-t+e)*pi);

    wr=hamming(N);

    hn=hd.*wr';

    w=0:0.01:pi;

    h=freqz(hn,1,w);

    figure;

    plot(w,(20*log10(abs(h))));

    hold on;

    plot(w,unwrap(angle(h)),'r');

    grid on;

    xlabel('angular frequency');

    ylabel('magnitude ');

    title('magnitude response of lpf using hamming window');

    hd=(sin((n-t+e)*pi)-sin((n-t+e)*wp))./((n-t+e)*pi);

    wr=blackman(N);

    hn=hd.*wr';

    w=0:0.01:pi;

    h=freqz(hn,1,w);

    figure;

    plot(w,(20*log10(abs(h))));

    hold on;

    plot(w,unwrap(angle(h)),'r');grid on;

    xlabel('angular frequency');

    ylabel('magnitude ');

    title('magnitude response of lpf using blackman window');

    enter cut off frequency.5*pi

    enter the length of filter50

  • 8/6/2019 Meril Final List to Be Given

    46/64

  • 8/6/2019 Meril Final List to Be Given

    47/64

    Program 3

    Design an FIR BPF for cut off frequency of.5*pi.Let the order of the filter be 49.Use

    bartlett window.

    clc;

    clear all;close all;

    wp1=input('enter cut off frequency1');

    wp2=input('enter cut off frequency2');

    N=input('enter the length of filter');

    t=(N-1)/2;

    e=0.001;

    n=0:N-1;

    hd=(sin((n-t+e)*wp2)-sin((n-t+e)*wp1))./((n-t+e)*pi);

    wr=bartlett(N);

    hn=hd.*wr';

    w=0:0.01:pi;

    h=freqz(hn,1,w);

    figure;plot(w,(20*log10(abs(h))));

    hold on;

    plot(w,unwrap(angle(h)),'r');

    grid on;

    xlabel('angular frequency');

    ylabel('magnitude ');

    title('magnitude response of bpf using bartlett window');

    enter cut off frequency1.25*pi

    enter cut off frequency2.75*pi

    enter the length of filter50

  • 8/6/2019 Meril Final List to Be Given

    48/64

  • 8/6/2019 Meril Final List to Be Given

    49/64

    Program 4

    Design an FIR BSF for cut off frequency of.5*pi.Let the order of the filter be 49.Use

    hann window.

    clc;

    clear all;

    close all;

    wp1=input('enter cut off frequency1');

    wp2=input('enter cut off frequency2');

    N=input('enter the length of filter');

    t=(N-1)/2;

    e=0.001;

    n=0:N-1;

    w=0:0.01:pi;

    hd=(sin((n-t+e)*pi)-sin((n-t+e)*wp2)+sin((n-t+e)*wp1))./((n-t+e)*pi);

    wr=hann(N);

    hn=hd.*wr';

    h=freqz(hn,1,w);figure;

    plot(w,(20*log10(abs(h))));

    hold on;

    plot(w,unwrap(angle(h)),'r');

    grid on;

    xlabel('angular frequency');

    ylabel('magnitude ');

    title('magnitude response of bsf using hann window');

    enter cut off frequency1.25*pienter cut off frequency2.75*pi

    enter the length of filter50

  • 8/6/2019 Meril Final List to Be Given

    50/64

  • 8/6/2019 Meril Final List to Be Given

    51/64

    Program 5

    Design a high pass FIR filter using Dolph Chebychev window Let the order of the

    filter be 49.Let the cut off frequency is 0.5*pi

    clc;clear all;

    close all;

    wp=input('enter cut off frequency');

    N=input('enter the length of filter');

    t=(N-1)/2;

    e=0.001;

    n=0:N-1;

    hd=(sin((n-t+e)*pi)-sin((n-t+e)*wp))./((n-t+e)*pi);

    wr=chebwin(N);

    hn=hd.*wr';

    w=0:0.01:pi;

    h=freqz(hn,1,w);

    figure;plot(w,(20*log10(abs(h))));

    hold on;

    plot(w,unwrap(angle(h)),'r');

    grid on;

    xlabel('angular frequency');

    ylabel('magnitude ');

    title('magnitude response of hpf using dolph window');

    enter cut off frequency.5*pi

    enter the length of filter50

  • 8/6/2019 Meril Final List to Be Given

    52/64

  • 8/6/2019 Meril Final List to Be Given

    53/64

    Program 6

    Design a FIR bandpass filter using Kaiser window. Let the order of the filter be 49.

    Let the cut off frequencies are 1500Hz and 3000Hz.Let the sampling frequency is

    8KHz.

    clc;clear all;

    fp1=input('enter cut off frequency1');

    fp2=input('enter cut off frequency2');

    N=input('enter the order of filter');

    fs=input('enter the sampling frequency');

    wp1=2*pi*fp1/fs;

    wp2=2*pi*fp2/fs;

    hn=fir1(N,[(wp1/pi) (wp2/pi)],'bandpass',kaiser(N+1));

    w=0:0.01:pi;

    h=freqz(hn,1,w);

    figure;

    plot((w*fs)/(2*pi),(20*log10(abs(h))));

    hold on;

    plot((w*fs)/(2*pi),unwrap(angle(h)),'r');

    grid on;

    xlabel('angular frequency');

    ylabel('magnitude and phase ');

    title('magnitude and phase response of bpf using kaiser window');

    enter cut off frequency11500

    enter cut off frequency23000

    enter the order of filter50enter the sampling frequency8000

  • 8/6/2019 Meril Final List to Be Given

    54/64

  • 8/6/2019 Meril Final List to Be Given

    55/64

    Program 7

    Design a FIR bandpass filter using Kaiser window. Let the order of the filter be 49.

    Let the passband edge frequency 0.3pi and stopband edge frequency is 0.4pi.

    clc;clear all;

    close all;

    w=0:0.01:pi;

    wp=input('enter passband edgefrequency');

    ws=input('enter stopband edge frequency');

    f=[wp/pi ws/pi];

    a=[1 0];

    dev = [0.05 0.01];

    [n,wn,beta] = kaiserord(f,a,dev);

    b=fir1(n,wn,kaiser(n+1,beta));

    h=freqz(b,1,w);

    figure

    plot(w/pi,20*log10(abs(h)));grid on

    hold on

    a=unwrap(angle(h));

    plot(w/pi,a,'--');

    title('low pass filter using kaiser window');

    xlabel('normalised frequency in radians');

    ylabel('absolute magnitude in db');

    a2=[0 1];

    [n1,wn1,beta2,high] = kaiserord(f,a2,dev);

    b1=fir1(n1,wn1,'high',kaiser(n1+1,beta2));

    h1=freqz(b1,1,w);

    figure

    plot(w/pi,20*log10(abs(h1)));grid on

    hold on

    a1=unwrap(angle(h1));

    plot(w/pi,a1,'--');

    title('highpass filter using kaiser window');

    xlabel('normalised frequency in radians');

    ylabel('absolute magnitude in db');

    enter passband edgefrequency0.3*pienter stopband edge frequency0.4*pi

  • 8/6/2019 Meril Final List to Be Given

    56/64

  • 8/6/2019 Meril Final List to Be Given

    57/64

    Expt 4 Fast Fourier Transform

    Program 1

    Implement FFT using DITclc;clear all;close all;

    N=input('enter the lenth of fft');

    x=input('enter the sequence');

    X=bitrevorder(x); %taking the bit reversal of input sequencedisplay(X);

    j=sqrt(-1);

    w=exp(-j*2*pi/N);

    M=log2(N);%total no. of stages

    display(M);

    for m=1:M

    for t= 1:(2^(m-1))

    k(t)=N*(t-1)/2^m;%calculating exp factor

    end;

    l=k;

    for n=1:2^(M-m)-1

    l=[l k ];%replicating exp fator based on exp repeat factor(ERF)

    end

    display(l);

    inc=2^(m-1)

    jump=0;jump1=0;

    for c=1:N/2

    y(1+jump)=X(1+jump)+w^(l(c))*X(1+jump+2^(m-1));%(l(c)) taking

    individual elements from array

    y(1+jump+2^(m-1))=X(1+jump)-w^(l(c))*X(1+jump+2^(m-1));

    inc=inc-1

    if(inc==0)

    jump1=2^(m-1)+1%calculating the jumping location

    jump=jump+jump1

    inc=2^(m-1)

    else

    jump1=1;jump=jump+jump1%calculating the jumping location

    end

    end

    display(y)%output of each stage

    X=y;

    end

    display(X)%fft of input sequence

    xx=fft(x);

    display(xx)%fft of input sequence

    enter the lenth of fft8enter the sequence[1 2 3 4 4 3 2 1]

    X =

    1 4 3 2 2 3 4 1

  • 8/6/2019 Meril Final List to Be Given

    58/64

    M =

    3

    l =

    0 0 0 0

    inc =

    1

    inc =

    0

    jump1 =

    2

    jump =

    2

    inc =

    1

    inc =

    0

    jump1 =

    2

    jump =

  • 8/6/2019 Meril Final List to Be Given

    59/64

    4

    inc =

    1

    inc =

    0

    jump1 =

    2

    jump =

    6

    inc =

    1

    inc =

    0

    jump1 =

    2

    jump =

    8

    inc =

  • 8/6/2019 Meril Final List to Be Given

    60/64

    1

    y =

    5 -3 5 1 5 -1 5 3

    l =

    0 2 0 2

    inc =

    2

    inc =

    1

    jump =

    1

    inc =

    0

    jump1 =

    3

    jump =

    4

    inc =

    2

  • 8/6/2019 Meril Final List to Be Given

    61/64

    inc =

    1

    jump =

    5

    inc =

    0

    jump1 =

    3

    jump =

    8

    inc =

    2

    y =

    Columns 1 through 5

    10.0000 -3.0000 - 1.0000i 0 -3.0000 + 1.0000i 10.0000

    Columns 6 through 8

    -1.0000 - 3.0000i 0 -1.0000 + 3.0000i

    l =

    0 1 2 3

  • 8/6/2019 Meril Final List to Be Given

    62/64

    inc =

    4

    inc =

    3

    jump =

    1

    inc =

    2

    jump =

    2

    inc =

    1

    jump =

    3

    inc =

    0

    jump1 =

    5

  • 8/6/2019 Meril Final List to Be Given

    63/64

    jump =

    8

    inc =

    4

    y =

    Columns 1 through 5

    20.0000 -5.8284 - 2.4142i 0 -0.1716 - 0.4142i 0

    Columns 6 through 8

    -0.1716 + 0.4142i 0 -5.8284 + 2.4142i

    X =

    Columns 1 through 5

    20.0000 -5.8284 - 2.4142i 0 -0.1716 - 0.4142i 0

    Columns 6 through 8

    -0.1716 + 0.4142i 0 -5.8284 + 2.4142i

    xx =

    Columns 1 through 5

    20.0000 -5.8284 - 2.4142i 0 -0.1716 - 0.4142i 0

    Columns 6 through 8

    -0.1716 + 0.4142i 0 -5.8284 + 2.4142i

    >>

  • 8/6/2019 Meril Final List to Be Given

    64/64

    clc;