ankit final report(ankit)HIET1.doc

Embed Size (px)

Citation preview

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    1/25

    EXPERIMENT NO-1

    AIM:Introduction to MATLAB.

    INTRODUCTION:

    MATLAB is a software package for high performance numerical

    computation and visualization. It provides an interactive environment for with

    hundreds of built in function for technical computing, graphical and animation. It

    also provides easy extensibility with its own high level programming language.

    MATLAB stands for matrix laboratory.

    MATLABs built in function provides excellent tool for linear algebra

    computations, data analysis, signal processing, optimization, and numerical

    solution of ordinary differential equations, quadrature and many other types of

    scientific computations. MATLAB provides external interface to run FORTRAN or c

    codes from within MATLAB. User can also write his own functions in MATLABlanguage. These functions behave just like built in functions.

    In education it is the standard instructional tool for introductory and advanced

    courses in math, engg. Science and industry MATLAB is a tool of choice for high

    productivity, research, development and analysis. MATLAB has extensive facility

    for displaying vectors, matrices and graphs as well as printing these graphs. It

    includes high level function for 2d and 3d data visualization, image processing,

    animation and graphic presentation. It also include low level function that allow

    you to fully customize appearance of graphics and to build complete graphical

    interfaces

    Basics of MATLAB:

    MATLAB WINDOWS

    MATLAB works through three basic windows:

    (1) MATLAB desktop: this is where puts you when you launch it MATLABdesktop by

    default consist of following sub windows:

    a) COMMAND WINDOWS: this is main window. It is characterized byMATLAB command prompt(>>)

    b) CURRENT DIRECTORY: this is where all your files currently in use are listed.You can run M files, rename them, delete them etc.

    c) WORKSPACE: this sub window lists all variable that you have generated so farand shows their type and size.

    d) COMMAND HISTORY: all command typed on MATLAB prompt in the commandwindow get recorded in this window.

    2) FIGURE WINDOW: The output of all graphics command typed in the

    command window are flushed to the graphics or the figure window, a

    separate gray window with (default) white back ground color.

    1

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    2/25

    3) EDITOR WINDOW: This is where user writes, edit, create and save his

    program his program in files called M-files. User can use any text editor to

    carry out these tasks.

    File Types:

    MATLAB can read write several types of files. Her are mainly 5

    types of files for storing data and programs.

    1. MFILES-These standard ASCII text files, with .m extension to the file name.

    2. MAT files- These are binary data files with .mat extensions to the file

    name, Mat files are created by MATLAB when users save command.

    3. FIG-These are binary figure files with .fig extension that can be opened

    again in MATLAB as figures.

    4. PFILES- These are compiled m files with .p extension that can be executed

    in MATLAB directly. These files are created with pcode command.

    5. MEX-FILES- These are MATLAB capable FORTRAN and C program with

    .MEX extension to the file name.

    COMMANDS commonly used in MATLAB:

    1-Subplot: subplot (m, n, and p) divides the graphic window into m*n sub

    windows and puts the plot generated by next plotting command into pth sub

    window, where the sub windows are counted row wise.

    2-Disp: disp(x) displays an array, without printing the array name. If x contains a

    text string, the string is displayed.

    3-Stem: stem(x, y) plots x versus columns of y, x and y must vector or matrices

    of the same size.

    4-Clc: clc clears all input and output from commands window display by giving to

    user a clean screen.

    5-Exp: exp(x) is an elementary function that operates element wise on arrays.

    6-plot: plot(y) plots the columns of y versus their index if y is a real no: if y iscomplex, plot(y) is equivalent to splot (real(y), image(y)).

    7-Xlabel: xlabel (string) labels the x axis of current axis.

    8-Ylabel: ylabel (string) labels the y-axis of the current axis.

    2

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    3/25

    EXPERIMENT NO-2

    Aim: Write a program to the following functions:

    (a) To plot impulse function (b) To plot unit step function

    (c) To plot unit ramp function (d) To plot sinusoidal function

    (e) To plot cosine function (f) To plot exponential function

    %% To plot impulse function

    x=-2:1:2;

    y=[0 0 1 0 0];

    subplot(2,3,1)

    stem(x,y)

    xlabel('time')

    ylabel('amplitude')

    title('impulse function')

    %% To plot unit step functionx=0:1:20;

    y=ones(1,21);

    subplot(2,3,2)

    stem(x,y)

    xlabel('time')

    ylabel('amplitude')

    title('unit step function')

    %% To plot unit ramp function

    x=0:1:20;

    subplot(2,3,3)

    stem(x,x)

    xlabel('time')

    title('unit ramp function')

    %% To plot sinusoidal function

    x=0:.1:10;

    y=sin(x);

    subplot(2,3,4)

    stem(x,y)

    xlabel('time')ylabel('amplitude')

    title('sinosuidal function')

    %% To plot cosine function

    x=0:.1:10;

    y=cos(x);

    subplot(2,3,5)

    stem(x,y)

    xlabel('time')

    ylabel('amplitude')

    title('cosine function')

    3

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    4/25

    %% To plot exponential function

    x=0:.1:10;

    y=exp(x);

    subplot(2,3,6)

    stem(x,y)

    xlabel('time')ylabel('amplitude')

    title('exponential function')

    OUTPUT:-

    4

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    5/25

    EXPERIMENT NO-3

    Aim: Write a program to find convolution, cross-correlation & auto-correlation of sequence

    using in-built convolution and correlation function.

    x=[2 3 4 5 6 7 8]; %% input sequence

    h=[3 4 5 6]; %% impulse sequencel1=length(x)

    5

    - 2 - 1 0 1 20

    0 . 2

    0 . 4

    0 . 6

    0 . 8

    1

    t i m e

    am

    plitude

    i m p u l s e f u n c t i o n

    0 5 1 0 1 5 2 00

    0 . 2

    0 . 4

    0 . 6

    0 . 8

    1

    t i m e

    am

    plitude

    u n i t s a m p l e f u n c t i o n

    0 5 1 0 1 5 2 00

    5

    1 0

    1 5

    2 0

    t i m e

    am

    plitude

    u n i t r a m p f u n c t i o n

    0 5 1 0- 1

    - 0 . 5

    0

    0 . 5

    1

    t i m e

    am

    plitude

    s i n u s o i d a l f u n c t i o n

    0 5 1 0- 1

    - 0 . 5

    0

    0 . 5

    1

    t i m e

    am

    plitude

    c o s i n e f u n c t i o n

    0 5 1 00

    0 . 5

    1

    1 . 5

    2

    2 . 5x 1 0

    4

    t i m e

    am

    plitude

    e x p o n e n t i a l f u n c t i o n

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    6/25

    l2=length(h)

    n=0:1:l1+l2-2;

    n1=0:1:l1-1;

    n2=0:1:l2-1;

    % % to plot input sequencesubplot(2,3,1)

    stem(n1,x);grid;

    xlabel('n')

    ylabel('x(n)')

    title('input sequence'); %% to plot input sequence

    %% to plot impulse sequence

    subplot(2,3,2);

    stem(n2,h);grid;

    xlabel('n')

    ylabel('h(n)')title('impulse response sequence'); %% to plot impulse response

    %% to plot convolution of two sequence

    y=conv(x,h);

    subplot(2,3,3);

    stem(n,y);grid;

    xlabel('n')

    ylabel('x(n)')

    title('output of convolution of two sequence'); %% to plot convolution of two sequence

    %% auto-corelation

    n3=-(l1-1):(l1-1)

    y1=xcorr(x,x);

    subplot(2,3,4);

    stem(n3,y1);grid;

    xlabel('n')

    ylabel('x(n)')

    title('output sequence'); %% to plot auto-corelation of two sequence

    %% cross-corelation

    n4=-(l2-1):(l1-1)y2=xcorr2(x,h);

    subplot(2,3,5);

    stem(n4,y2);grid;

    xlabel('n')

    ylabel('x(n)')

    title('output sequence'); %% to plot cross-corelation of two sequence

    6

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    7/25

    OUTPUT:-

    7

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    8/25

    EXPERIMENT NO-4

    8

    0 1 2 30

    1

    2

    3

    4

    num

    x

    plotx

    0 1 2 30

    1

    2

    3

    4

    5

    num

    h

    plot h

    0 2 4 60

    5

    10

    15

    20

    25

    30

    35

    -4 -2 0 2 40

    10

    20

    30

    40

    Num

    y2

    Cross coorlation

    -4 -2 0 2 40

    5

    10

    15

    20

    25

    30

    num

    y3

    Auto coorlation

    num

    convolution

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    9/25

    Aim:Define a function to compute DTFT of a finite length signal. Plot the magnitude &Phase plots using subplots to obtain DTFT Of 21 points triangular pulse over domain

    10

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    10/25

    EXPERIMENT NO-5

    10

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    11/25

    Aim: Write a program to verify the properties of Discrete Fourier Transform(DFT).

    Linearity Property

    n=0:10;

    x1=(0.5).^n;x2=(0.7).^n;

    a=5; b=7;

    x3=a*x1+b*x2;

    X3=fft(x3);

    subplot(2,2,1)

    stem(n,real(X3));grid;

    xlabel('frequency');

    ylabel('amplitude');

    title('real part of X3'); %% to plot real part of DFT(ax1+bx2)

    subplot(2,2,2)

    stem(n,imag(X3));grid;

    xlabel('frequency');

    ylabel('amplitude');

    title('imaginary part of X3'); %% to plot imaginary part of DFT(ax1+bx2)

    X1=fft(x1);

    X2=fft(x2);

    X4=a*X1+b*X2;

    subplot(2,2,3)

    stem(n,real(X4));grid;

    xlabel('frequency');

    ylabel('amplitude');

    title('real part of X4'); %% to plot real part of (a*DFT(x1)+b*DFT(x2))

    subplot(2,2,4)

    stem(n,imag(X4));grid;

    xlabel('frequency');

    ylabel('amplitude');title('imag part of X4'); %% to plot imag part of (a*DFT(x1)+b*DFT(x2))

    OUTPUT:-

    11

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    12/25

    0 5 1 00

    1 0

    2 0

    3 0

    4 0

    f r e q u e n c y

    am

    plitude

    r e a l p a r t o f X 3

    0 5 1 0- 2 0

    - 1 0

    0

    1 0

    2 0

    f r e q u e n c y

    am

    plitude

    i m a g p a r t o f X 3

    0 5 1 00

    1 0

    2 0

    3 0

    4 0

    f r e q u e n c y

    am

    plitude

    r e a l p a r t o f X 4

    0 5 1 0- 2 0

    - 1 0

    0

    1 0

    2 0

    f r e q u e n c y

    am

    plitude

    i m a g p a r t o f X 4

    Symmetry property

    n=0:10;

    12

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    13/25

    x=(0.5).^n;

    X=fft(x);

    subplot(2,2,1)

    stem(n,real(X));grid;

    xlabel('frequency')

    ylabel('amplitude')title('real part of X') %% plot of real part of DFT(X)

    subplot(2,2,2)

    stem(n,imag(X));grid;

    xlabel('frequency')

    ylabel('amplitude')

    title('imaginary part of X') %% plot of imaginary part of DFT(X)

    y=x(mod(-n,11)+1);

    xe=(x+y)/2; %% even component

    xo=(x-y)/2; %% odd component

    XE=fft(xe); %% dft of even component

    XO=fft(xo); %% dft of odd component

    subplot(2,2,3)

    stem(n,real(XE));grid;

    xlabel('frequency')

    ylabel('amplitude')

    title('real part of XE') %% plot of real part of DFT(XE)

    subplot(2,2,4)

    stem(n,imag(XO));grid;

    xlabel('frequency')

    ylabel('amplitude')

    title('imaginary part of XO') %% plot of imaginary part of DFT(XO)

    OUTPUT:-

    13

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    14/25

    0 2 4 6 8 1 00

    0 . 5

    1

    1 . 5

    2

    f r e q u e n c y

    am

    plitude

    r e a l p a r t o f X

    0 2 4 6 8 1 0- 1

    - 0 . 5

    0

    0 . 5

    1

    f r e q u e n c y

    am

    plitude

    i m a g i n a r y p a r t o f X

    0 2 4 6 8 1 00

    0 . 5

    1

    1 . 5

    2

    f r e q u e n c y

    am

    plitude

    r e a l p a r t o f X E

    0 2 4 6 8 1 0- 1

    - 0 . 5

    0

    0 . 5

    1

    f r e q u e n c y

    am

    plitude

    i m a g i n a r y p a r t o f X O

    EXPERIMENT NO-6

    14

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    15/25

    Aim: Write a program to plot real, imaginary & phase and magnitude of exponential

    function. x=exp(-0.1+0.3j)n

    n= -10:10;

    x=exp((-0.1+0.3j)*n); %% exponential function

    subplot(2,2,1)

    stem(n,real(x));grid;

    xlabel(' frequency ')

    ylabel('amplitude ')

    title('real part of x(n)') %% plot of real part of x(n)

    subplot(2,2,2)

    stem(n,imag(x));grid;

    xlabel(' frequency ')

    ylabel('amplitude ')

    title('img part of x(n)') %% plot of imaginary part of x(n)

    subplot(2,2,3)

    stem(n,abs(x));grid;

    xlabel(' frequency ')

    ylabel('amplitude ')

    title('abs part of x(n)') %% plot of magnitude part of x(n)

    subplot(2,2,4)

    stem(n,angle(x));grid;

    xlabel(' frequency ')

    ylabel('amplitude')

    title('angle part of x(n)') %% plot of phase part of x(n)

    OUTPUT:-

    15

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    16/25

    - 1 0 - 5 0 5 1 0- 3

    - 2

    - 1

    0

    1

    2

    f r e q u e n c y

    am

    plitude

    r e a l p a r t o f x ( n )

    - 1 0 - 5 0 5 1 0- 2

    - 1 . 5

    - 1

    - 0 . 5

    0

    0 . 5

    1

    f r e q u e n c y

    am

    plitude

    i m g p a r t o f x ( n )

    - 1 0 - 5 0 5 1 00

    0 . 5

    1

    1 . 5

    2

    2 . 5

    3

    f r e q u e n c y

    am

    plitude

    a b s p a r t o f x ( n )

    - 1 0 - 5 0 5 1 0- 3

    - 2

    - 1

    0

    1

    2

    3

    f r e q u e n c y

    am

    plitude

    a n g l e p a r t o f x ( n )

    EXPERIMENT NO-7

    16

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    17/25

    Aim: Write a program to convert a continuous time signal to a discrete signal and then

    reconstruct the original signal.

    t= -0.005:0.00005:0.005;

    x=exp(-1000*abs(t));

    subplot(2,2,1)

    plot(t,x);

    xlabel('t');

    ylabel('amplitude');

    title('analog signal'); %% to plot continuous time signal

    n=-25:1:25;

    T=1/5000;

    z=exp(-1000*abs(n*T));

    subplot(2,2,2)stem(n*T,z);

    xlabel('n');

    ylabel('amplitude');

    title('sampled signal'); %% to plot discrete time signal

    xi=-0.005:0.00005:0.005;

    yi=spline(T*n,z,xi);

    subplot(2,2,3)

    plot(xi,yi);

    xlabel('t');

    ylabel('amplitude');

    title('reconstructed signal'); %% to plot reconstructed signal

    OUTPUT:-

    17

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    18/25

    - 5 0 5

    x 1 0- 3

    0

    0 . 2

    0 . 4

    0 . 6

    0 . 8

    1

    t

    am

    plitude

    a n a l o g s i g n a l

    - 5 0 5

    x 1 0- 3

    0

    0 . 2

    0 . 4

    0 . 6

    0 . 8

    1

    n

    am

    plitude

    s a m p l e d s i g n a l

    - 5 0 5

    x 1 0- 3

    0

    0 . 2

    0 . 4

    0 . 6

    0 . 8

    1

    t

    am

    plitude

    r e c o n s t r u c t e d s i g n a l

    EXPERIMENT NO-8

    18

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    19/25

    Aim: Write a program to plot a BUTTERWORTH low pass filter.

    pa=4; %PASSBAND ATTENUATION

    sa=10; %STOPBAND ATTENUATION

    fp=400; %PASSBAND FREQUENCY

    fs=800; %STOPBAND FREQUENCYf=4000; %SAMPLING FREQUENCY

    fp1=2*3.14*fp/f; %PASSBAND EDGE FREQUENCY

    fs1=2*3.14*fs/f; %STOPBAND EDGE FREQUENCY

    [N,Wn]=buttord(fp1,fs1,pa,sa); % N : ORDER & WN : NATURAL FREQUENCY

    [B,A]=butter(N,Wn); %% filter co-efficients

    [H,W]=freqz(B,A,N);

    w1=0:0.01:pi;

    [H]=freqz(B,A,w1);

    z=abs(H);x=angle(H);

    subplot(1,2,1);

    plot(w1,z);

    xlabel('FREQUENCY');

    ylabel('MAGNITUDE');

    title('MAGNITUDE VS FREQUENCY'); %%To plot magnitude

    subplot(1,2,2);

    plot(w1,x);

    xlabel('FREQUENCY');label('PHASE ANGLE');

    title('PHASE ANGLE VS FREQUENCY'); %%To plot phase

    OUTPUT:-

    19

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    20/25

    0 1 2 3 40

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    FREQUENCY

    MAGNITUDE

    MAGNOITUDE VS FREQUENCY

    0 1 2 3 4-4

    -3

    -2

    -1

    0

    1

    2

    3

    4

    FREQUENCY

    PHASE

    ANGLE

    PHASE ANGLE VS FREQUENCY

    EXPERIMENT NO-9

    Aim: Write a program to plot an ELLIPTICAL low pass filter.

    20

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    21/25

    pa=1; %PASSBAND ATTENUATION

    sa=15; %STOPBAND ATTENUATION

    fp=.2; %PASSBAND FREQUENCY

    fs=.3; %STOPBAND FREQUENCY

    [N,Wn]=ellipord(fp,fs,pa,sa); %N is ORDER & WN is NATURAL FREQUENCY

    [B,A]=ellip(N,pa,sa,Wn); %% filter co-efficients[H,W]=freqz(B,A,N);

    w1=0:0.01:pi;

    [H]=freqz(B,A,w1);

    z=abs(H);

    x=angle(H);

    subplot(1,2,1);

    plot(w1,z);

    xlabel('FREQUENCY');ylabel('MAGNITUDE');

    title('MAGNITUDE VS FREQUENCY'); %%To plot magnitude

    subplot(1,2,2);

    plot(w1,x);

    xlabel('FREQUENCY');

    ylabel('PHASE ANGLE');

    title('PHASE ANGLE VS FREQUENCY'); %%To plot phase

    OUTPUT:-

    21

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    22/25

    0 1 2 3 40

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    FREQUENCY

    MAGNITUDE

    MAGNOITUDE VS FREQUENCY

    0 1 2 3 4-4

    -3

    -2

    -1

    0

    1

    2

    3

    4

    FREQUENCY

    PHASE

    ANGLE

    PHASE ANGLE VS FREQUENCY

    EXPERIMENT NO-10

    Aim: Generate and plot the following windows(i)Rectangular (ii ) Hanning (iii) Hamming (iv)Blackman

    22

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    23/25

    take the window length = 31 & windows to be causal & also plot amplitude plots

    of these windows.

    m=31

    n=0:m-1;

    %% rectangular windowwr=boxcar(m);

    subplot(4,2,1)

    stem(n,wr);

    xlabel('time index,n')

    ylabel('w[n]')

    title('rectangular window')

    %% amplitude response of rectangular window

    [frq_wr,w1]= freqz(wr,1,512);

    subplot(4,2,2)

    plot(w1/pi,20*log10(abs(frq_wr))); grid;xlabel('normalized frequency,w/pi')

    ylabel('amplitude response,dB')

    title('amplitude response of rectangular window')

    %% hanning window

    wc= hanning(m)

    subplot(4,2,3)

    stem(n,wc)

    xlabel('time index,n')

    ylabel('w[n]')

    title('hanning window')

    %% amplitude response of hanning window

    [frq_wc,w2]= freqz(wc,1,512);

    subplot(4,2,4)

    plot(w2/pi, 20*log10(abs(frq_wc))); grid;

    xlabel('normalized frequency,w/pi')

    ylabel('amplitude response,dB')

    title('amplitude response of hanning window')

    %% hamming windowwh= hamming(m)

    subplot(4,2,5)

    stem(n,wh)

    xlabel('time index,n')

    ylabel('w[n]')

    title('hamming window')

    %% amplitude response of hamming window

    [frq_wh,w3]= freqz(wh,1,512);

    subplot(4,2,6)

    plot(w3/pi, 20*log10(abs(frq_wh))); grid;xlabel('normalized frequency,w/pi')

    23

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    24/25

    ylabel('amplitude response,dB')

    title('amplitude response of hamming window')

    %% blackman window

    wb= blackman(m)

    subplot(4,2,7)stem(n,wc)

    xlabel('time index,n')

    ylabel('w[n]')

    title('blackman window')

    %% amplitude response of blackman window

    [frq_wb,w4]= freqz(wb,1,512);

    subplot(4,2,8)

    plot(w4/pi, 20*log10(abs(frq_wb))); grid;

    xlabel('normalized frequency,w/pi')

    ylabel('amplitude response,dB')title('amplitude response of blackman window')

    OUTPUT:-

    24

  • 7/29/2019 ankit final report(ankit)HIET1.doc

    25/25

    25