bsl manual

Upload: venkat-srinu

Post on 07-Apr-2018

240 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/6/2019 BSL Manual

    1/78

    Basic simulation lab

    ECE Dept., MITS 1

    1. BASIC OPERATIONS ON MATRICES

    AIM: To understand MATLAB basic features and built in functions available in MATLAB.

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    MATLAB, which stands for MATrix LABoratory, is a state-of-the-art mathematicalsoftware package, which is used extensively in both academia and industry. It is aninteractive program for numerical computation and data visualization, which along with its

    programming capabilities provides a very useful tool for almost all areas of science andengineering. Unlike other mathematical packages, such as MAPLE or MATHEMATICA,MATLAB cannot perform symbolic manipulations without the use of additional Toolboxes.It remains however, one of the leading software packages for numerical computation.

    As you might guess from its name, MATLAB deals mainly with matrices. A scalar isa 1-by-1 matrix and a row vector of length say 5, is a 1-by-5 matrix.. One of the manyadvantages of MATLAB is the natural notation used. It looks a lot like the notation that youencounter in a linear algebra. This makes the use of the program especially easy and it is whatmakes MATLAB a natural choice for numerical computations. The purpose of thisexperiment is to familiarize MATLAB, by introducing the basic features and commands of the program.

    MATLAB is case-sensitive, which means that a + B is not the same as a + b.The MATLAB prompt ( ) in command window is where the commands are entered.

    Matrices :

    1. row matrix: Elements in a row are separated either by using white spaces or commas eg: a=[1 2 4 5]

    2. column matrix: Elements which differ by a column are seperated by enter or semicolumn eg: b=[1; 2; 3]

    Looking into matrix:a(row,column) allows to look the particular element in the matrix a

    Vectors :d= [0:7]d is a vector or row matrix with first element as 0 and last element as 7 and increment is bydefault 1.The default increment can be changed (to 0.1) by using increment field in between ase= [0:0.1:7].d(1:2) allows to look into vector with increment 1e(1:2:4) look with increment

  • 8/6/2019 BSL Manual

    2/78

    Basic simulation lab

    ECE Dept., MITS 2

    Operators:

    1. + addition2. - subtraction3. * multiplication4. ^ power 5. ' transpose6. \ left division7. / right division

    Remember that the multiplication, power and division operators can be used in conjunctionwith a period to specify an element-wise operation.

    Typical commands: 1. whos2. who3. clear 4. quit5. save filename filename.mat6. load filename - retrive7. dairy filename - b4 and after ascii text file

    8. helpBuilt in Functions:1. Scalar Functions:Certain MATLAB functions are essentially used on scalars, but operate element-wise whenapplied to a matrix (or vector). They are summarized below.

    1. sin - trigonometric sine2. cos - trigonometric cosine3. tan - trigonometric tangent4. asin - trigonometric inverse sine (arcsine)5. acos - trigonometric inverse cosine (arccosine)6. atan - trigonometric inverse tangent (arctangent)

    7. exp - exponential8. log - natural logarithm9. abs - absolute value

    10. sqrt - square root11. rem - remainder 12. round - round towards nearest integer 13. floor - round towards negative infinity14. ceil - round towards positive infinity

    2. Vector Functions:Other MATLAB functions operate essentially on vectors returning a scalar value. Some of these functions are given below.

    1. max largest component : get the row in which the maximum element lies2. min smallest component3. length length of a vector 4. sort sort in ascending order 5. sum sum of elements6. prod product of elements7. median median value8. mean mean value std standard deviation

  • 8/6/2019 BSL Manual

    3/78

    Basic simulation lab

    ECE Dept., MITS 3

    3. Matrix Functions:

    Much of MATLABs power comes from its matrix functions. These can be further separatedinto two sub-categories.

    The first one consists of convenient matrix building functions, some of which are given below.

    1. eye - identity matrix2. zeros - matrix of zeros3. ones - matrix of ones4. diag - extract diagonal of a matrix or create diagonal matrices5. triu - upper triangular part of a matrix6. tril - lower triangular part of a matrix7. rand - randomly generated matrix

    eg: diag([0.9092;0.5163;0.2661])ans =0.9092 0 00 0.5163 00 0 0.2661

    commands in the second sub-category of matrix functions are

    1. size size of a matrix2. det determinant of a square matrix3. inv inverse of a matrix4. rank rank of a matrix5. rref reduced row echelon form6. eig eigenvalues and eigenvectors7. poly characteristic polynomial8. norm norm of matrix (1-norm, 2-norm, -norm)9. cond condition number in the 2-norm

    10. lu LU factorization11. qr QR factorization12. chol Cholesky decomposition13. svd singular value decomposition

    Operations on matrices:

    1. Transpose (single quote )a= [ 1 2 3 ];

    b=a;2. extraction of submatricesa=[1,2;3,4;5,6];b=a(1:2,2:1;1:1;2:2);c=a(:,2) ; second column of matrix a is sub- matrix cd=a(1,:) ; first row of matrix a is sub-matrix d

  • 8/6/2019 BSL Manual

    4/78

  • 8/6/2019 BSL Manual

    5/78

    Basic simulation lab

    ECE Dept., MITS 5

    2. GENERATION OF VARIOUS SIGNALS AND SEQUENCESAIM: To generate various periodic and aperiodic signals and sequences such as UnitImpulse, Unit step, Square, Saw Tooth, Triangular, Sinusoidal, Ramp, Sinc functions usingMATLAB.

    EQUIPMENT AND SOFTWARE:

    Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    If x and y are two vectors of the same length then plot(x,y) plots x versus y.

    For example, to obtain the graph of y = cos( x) from to , we can first define the vector x

    with components equally spaced numbers between and , with increment, say 0.01. x=-pi:0.01:pi;

    We placed a semicolon at the end of the input line to avoid seeing the (long) output. Note that the smallest the increment, the smoother the curve will be. Next, we define the vector y y=cos(x);(using a semicolon again) and we ask for the plot plot(x,y)It is good practice to label the axis on a graph and if applicable indicate what each axisrepresents. This can be done with the xlabel and ylabel commands. xlabel('x') ylabel('y=cos(x)')Inside parentheses, and enclosed within single quotes, we type the text that we wish to bedisplayed along the x and y axis, respectively. We could even put a title on top using title('Graph of cosine from -pi to pi')

    Various line types, plot symbols and colors can be used. If these are not specified (as in thecase above) MATLAB will assign (and cycle through) the default ones as given in the table

    below.y yellow . pointm magenta o circlec cyan x x-markr red + plusg green - solidb blue * star

    w white : dottedk black -. dashdot-- dashed

    So, to obtain the same graph but in green , we type plot(x,y,g)where the third argument indicating the color, appears within single quotes. We could get adashed line instead of a solid one by typing plot(x,y,--)or even a combination of line type and color, say a blue dotted line by typing plot(x,y,b:)Multiple curves can appear on the same graph. If for example we define another vector

  • 8/6/2019 BSL Manual

    6/78

  • 8/6/2019 BSL Manual

    7/78

    Basic simulation lab

    ECE Dept., MITS 7

    The Sinc Function

    The sinc function computes the mathematical sinc function for an input vector or matrix x.Viewed as a function of time, or space, the sinc function is the inverse Fourier transform of the rectangular pulse in frequency centered at zero of width 2 and height 1. The followingequation defines the sinc function:

    The sinc function has a value of 1 whenx is equal to zero, and a value of

    for all other elements of x.

    The Dirichlet Function

    The toolbox function diric computes the Dirichlet function, sometimes called the periodicsinc or aliased sinc function, for an input vector or matrix x. The Dirichlet function is

    where N is a user-specified positive integer. For N odd, the Dirichlet function has a period of 2; for N even, its period is 4. The magnitude of this function is (1/N) times the magnitudeof the discrete-time Fourier transform of the N-point rectangular window.

    2.1 PROGRAM:t = (0:0.001:1)';

    % 1001-element row vector that represents time running from 0 to 1 s in steps of 1 ms.%the transpose operator (') changes the row vector into a column

    imp= [1; zeros(99,1)]; % Impulse

    unit_step = ones(100,1); % Step (with 0 initial cond.)

    ramp_sig= t; % Ramp

    quad_sig=t.^2; % Quadratic

    sq_wave = square(4*pi*t); % Square wave with period 0.5

    % To generate 1.5 s of a 50 Hz saw tooth wave with a sample rate of 10 kHz and plot 0.2 s of the%generated waveform

    fs = 10000;

    t = 0:1/fs:1.5;

    x = sawtooth(2*pi*50*t);

    plot(t,x), axis([0 0.2 -1 1])

    % To compute 2 s of a linear chirp signal with a sample rate of 1 kHz, that starts at DC and crosses %150 Hz at 1 s, use

    t = 0:1/1000:2;

    y = chirp(t,0,1,150);

    % To plot the spectrogram, use

    spectrogram(y,256,250,256,1000,'yaxis')

    % The pulse train is defined to have a sample rate of 50 kHz, a pulse train length of 10 ms, and a pulserepetition rate of 1 kHz; D specifies the delay to each pulse repetition in column 1 and an optionalattenuation for each repetition in column 2. The pulse train is constructed by passing the name of the

  • 8/6/2019 BSL Manual

    8/78

    Basic simulation lab

    ECE Dept., MITS 8

    gauspuls function to pulstran , along with additional parameters that specify a 10 kHz Gaussian pulsewith 50% bandwidth:

    T = 0:1/50E3:10E-3;

    D = [0:1/1E3:10E-3;0.8.^(0:10)]';

    Y = pulstran(T,D,'gauspuls',10E3,0.5);

    plot(T,Y)

    % To plot the sinc function for a linearly spaced vector with values ranging from -5 to 5x = linspace(-5,5);

    y = sinc(x);

    plot(x,y)

    %To plot the Dirichlet function over the range 0 to 4 for N = 7 and N = 8 , use

    x = linspace(0,4*pi,300);

    plot(x,diric(x,7)); axis tight;

    plot(x,diric(x,8)); axis tight;

    Output:

    1.5 s of a 50 Hz sawtooth wave with a sample rate of 10 kHz and plot 0.2 s

    linear chirp signal with a sample rate of 1 kHz

  • 8/6/2019 BSL Manual

    9/78

    Basic simulation lab

    ECE Dept., MITS 9

    The pulstran Function

    Plot of the sinc function for a linearly spaced vector with values ranging from -5 to 5

    Plot of Dirichlet function over the range 0 to 4 for N = 7 and N = 8

    2.2 PROGRAM:

    N = input( 'enter the length of sequence in even number' )

    % step sequence

    x = ones(1,N) ;

  • 8/6/2019 BSL Manual

    10/78

    Basic simulation lab

    ECE Dept., MITS 10

    n=0:1:N-1;figure(1)stem(n,x)axis([-1 N -1 2])title( 'STEP SEQUENCE' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )GRID

    % impulse sequence

    N1=N/2;

    x =[zeros(1,N1) ones(1,1) zeros(1,N1)];

    n=-N1:1:N1;figure(2)stem(n,x)axis([-(N1) N1 -1 2])title( 'IMPULSE SEQUENCE' )xlabel( 'samples ------- n' )

    ylabel( 'amplitude' )grid

    % ramp sequence

    n=0:1:N-1;

    x=n;

    figure(3)stem(n,x)axis([-1 N -1 N])title( 'RAMP SEQUENCE' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )grid

    % exponential sequence

    n=0:1:N-1;

    x=exp(-n);

    figure(4)stem(n,x)axis([-1 N -1 2])

    title( 'EXPONENTIAL SEQUENCE' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )grid

    % signal generation

    f = input ( 'enter the frequency = ' )fs = 10 * f;

    n=0:1/fs:1;

  • 8/6/2019 BSL Manual

    11/78

    Basic simulation lab

    ECE Dept., MITS 11

    ss = sin(2*pi*f*n) % SINUSOIDAL SIGNALGENERATION figure(5)

    subplot(2,1,1),plot(n,ss)title( 'sinusoidal signal' )xlabel( 'time ------- t' )

    ylabel( 'amplitude' )

    subplot(2,1,2),stem(n,ss)title( 'sinusoidal sequence' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )

    sq = square(2*pi*f*n)

    figure(6)

    subplot(2,1,1),plot(n,sq)title( 'square wave signal' )xlabel( 'time ------- t' )ylabel( 'amplitude' )

    subplot(2,1,2),stem(n,sq)title( 'square wave sequence' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )

    x= -5:0.1:5ts = sinc(x)

    figure(7)

    subplot(2,1,1),plot(x,ts)title( 'sinc wave form' )xlabel( 'time ------- t' )ylabel( 'amplitude' )

    subplot(2,1,2),stem(x,ts)title( 'sinc sequence' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )

    sas= Sawtooth(2*pi*2*n)figure(8)

    subplot(2,1,1),plot(n,sas)title( 'sawtooth signal' )xlabel( 'time ------- t' )ylabel( 'amplitude' )

    subplot(2,1,2),stem(n,sas)title( 'sawtooth sequence' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )

  • 8/6/2019 BSL Manual

    12/78

  • 8/6/2019 BSL Manual

    13/78

    Basic simulation lab

    ECE Dept., MITS 13

    output:

    -1 0 1 2 3 4 5 6-1

    -0.5

    0

    0.5

    1

    1.5

    2STEP SEQUENCE

    samples ------- n

    a m p l i t u d e

    -3 -2 -1 0 1 2 3-1

    -0.5

    0

    0.5

    1

    1.5

    2IMPULSE SEQUENCE

    samples ------- n

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    14/78

    Basic simulation lab

    ECE Dept., MITS 14

    -1 0 1 2 3 4 5 6-1

    0

    1

    2

    3

    4

    5

    6RAMP SEQUENCE

    samples ------- n

    a m p

    l i t u

    d e

    -1 0 1 2 3 4 5 6-1

    -0.5

    0

    0.5

    1

    1.5

    2EXPONENTIAL SEQUENCE

    samples ------- n

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    15/78

    Basic simulation lab

    ECE Dept., MITS 15

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

    -0.5

    0

    0.5

    1sinusoidal signal

    time ------- t

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1sinusoidal sequence

    samples ------- n

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1square wave signal

    time ------- t

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1square wave sequence

    samples ------- n

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    16/78

    Basic simulation lab

    ECE Dept., MITS 16

    -5 -4 -3 -2 -1 0 1 2 3 4 5-0.5

    0

    0.5

    1sinc wave form

    time ------- t

    a m p

    l i t u

    d e

    -5 -4 -3 -2 -1 0 1 2 3 4 5-0.5

    0

    0.5

    1sinc sequence

    samples ------- n

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1sawtooth signal

    time ------- t

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1sawtooth sequence

    samples ------- n

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    17/78

    Basic simulation lab

    ECE Dept., MITS 17

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

    -0.5

    0

    0.5

    1sweep signal

    time ------- t

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1sweep sequence

    samples ------- n

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1triangular waveform

    time ------- t

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1triangular sequence

    samples ------- n

    a m p

    l i t u

    d e

    RESULT: Various sequence were generated using MATLAB functions.

  • 8/6/2019 BSL Manual

    18/78

    Basic simulation lab

    ECE Dept., MITS 18

    3. OPERATIONS ON SIGNALS AND SEQUENCES

    AIM: To performs functions on signals and sequences such as addition, multiplication,scaling, shifting, folding, computation of energy and average power.

    EQUIPMENT AND SOFTWARE:

    Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    Signal energy and power:

    The energy of a signal is the area under the squared signal.

    Power is a time average of energy (energy per unit time). This is useful when the energy of the signalgoes to infinity.

    Energy vs. Power

    1 . "Energy signals" have finite energy.2 . "Power signals" have finite and non-zero power.

    3.1 Program: Addition, Multiplication, Scaling, Shifting, Folding

    clc; t=-2:0.01:2;f=input( 'enter the fundamental frequency:' );x=sin(2*pi*f*t);x1=x';x_sum=x+x;x_pro=x*x1;x_sca=2*(x);x_shi=(0.2-x);x_fol=-x;

    subplot(3,2,1)

    plot(t,x);grid on ;title( 'original' );xlabel( 't' );ylabel( 'x(t)' );

    subplot(3,2,2);plot(t,x_sum);grid on ;title( 'addition' );xlabel( 't' );ylabel( 'x(t)' );

    subplot(3,2,3);plot(t,x_pro);grid on ;

  • 8/6/2019 BSL Manual

    19/78

    Basic simulation lab

    ECE Dept., MITS 19

    title( 'multiplication' );xlabel( 't' );ylabel( 'x(t)' );

    subplot(3,2,4);plot(t,x_sca); grid on ;title( 'scaled' );xlabel( 't' );ylabel( 'x(t)' );

    subplot(3,2,5);plot(t,x_shi);grid on ;title( 'shifted' );xlabel( 't' );ylabel( 'x(t)' );

    subplot(3,2,6);plot(t,x_fol);grid on ;title( 'folded' );xlabel( 't' );ylabel( 'x(t)' );

    output:

    enter the fundamental frequency:1

    -2 -1 0 1 2-1

    0

    1original

    t

    x ( t )

    -2 -1 0 1 2-2

    0

    2addition

    t

    x ( t )

    -2 -1 0 1 20

    500

    multiplication

    t

    x ( t )

    -2 -1 0 1 2-2

    0

    2

    scaled

    t

    x ( t )

    -2 -1 0 1 2-2

    0

    2shifted

    t

    x ( t )

    -2 -1 0 1 2-1

    0

    1folded

    t

    x ( t )

    3.2 Program: Computation of Energy

    clc;t=-2:0.01:2;f=input( 'enter the fundamental frequency:' );a=input( 'enter the amplitude:' );x=a*sin(2*pi*f*t);

  • 8/6/2019 BSL Manual

    20/78

    Basic simulation lab

    ECE Dept., MITS 20

    subplot(2,1,1);title( 'test signal for energy calculation' );xlabel( 't' );ylabel( 'x(t)' );plot(t,x);grid on ;

    subplot(2,1,2);

    area(t,x.^2);xlabel( 't' );ylabel( 'x^2(t)' );title( 'The colored area gives the energy' )grid;

    OUTPUT SCREEN:

    enter the fundamental frequency:2enter the amplitude:2

    -2 -1.5 -1 -0.5 0 0.5 1 1.5 2-2

    -1

    0

    1

    2 test signal for energy calculation

    t

    x ( t )

    -2 -1.5 -1 -0.5 0 0.5 1 1.5 20

    1

    2

    3

    4

    t

    x 2 ( t )

    The colored area gives the energy

    3.3 Program: Power Calculation

    %Power calculation of analog and discrete signalt=-2:0.01:2;x1=sin(2*pi*t);n=-40:40;x2=sin(pi*(1/10)*n);

    figure(1);subplot(2,1,1)plot(t,x1);title( 'Analog sine' );xlabel( 't' );

  • 8/6/2019 BSL Manual

    21/78

    Basic simulation lab

    ECE Dept., MITS 21

    ylabel( 'x_1(t)' );

    subplot(2,1,2);stem(n,x2);xlabel( 'n' );ylabel( 'x_2(n)' );title( 'discrete sine' );

    figure(2);subplot(2,1,1);plot(t,x1.^2);

    hold on% red lines marking 0 & 1plot([0 0], [-.2 1.2], 'r' , [1 1], [-.2 1.2], 'r' );hold off

    axis([-2 2 -.2 1.2]);title( 'Squared sines' );xlabel( 't' );ylabel( 'x_1^2(t)' );

    subplot(2,1,2);stem(n,x2.^2);

    hold on ;% red lines marking 1 & 20plot([1 1], [-.2 1.2], 'r' , [20 20], [-.2 1.2], 'r' );hold off ;

    axis([-40 40 -.2 1.2]);xlabel( 'n' );ylabel( 'x_2^2(n)' );

    %calculating power of one period.disp( 'Power, one period:' );P = (1/20)*sum(x2(1:20).^2)

    OUTPUT SCREEN:

    Power, one period:

    P =

    0.5000

  • 8/6/2019 BSL Manual

    22/78

    Basic simulation lab

    ECE Dept., MITS 22

    Figure(1)

    -2 -1.5 -1 -0.5 0 0.5 1 1.5 2-1

    -0.5

    0

    0.5

    1Analog sine

    t

    x 1

    ( t )

    -40 -30 -20 -10 0 10 20 30 40-1

    -0.5

    0

    0.5

    1

    n

    x 2

    ( n )

    discrete sine

    Figure(2)

    -2 -1.5 -1 -0.5 0 0.5 1 1.5 2

    0

    0.5

    1

    Squared sines

    t

    x 1 2 (

    t )

    -40 -30 -20 -10 0 10 20 30 40

    0

    0.5

    1

    n

    x 2 2

    ( n )

    RESULT: various functions on signals and sequences such as addition, multiplication, scaling,shifting, folding, computation of energy and power were performed in MATLAB

  • 8/6/2019 BSL Manual

    23/78

    Basic simulation lab

    ECE Dept., MITS 23

    4. FINDING EVEN AND ODD PARTS / REAL AND IMAGINARY PARTS OF ASIGNAL/SEQUENCE

    AIM:

    To Verify Auto and Cross Correlation of Sequences / Signals Using MATLAB

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    C is a vector whose elements are the coefficients of the polynomial P and d is the highestdegree of the monomials of P.

    If m is the length of the vector C, P represents the following Laurent polynomial:

    P(z) = C(1)*z^d + C(2)*z^(d-1) + ... + C(m)*z^(d-m+1)

    P = laurpoly(C,'dmin',d)

    dmin specifies the lowest degree instead of the highest degree of monomials of P. Thecorresponding output P represents the following Laurent polynomial: P(z) = C(1)*z^(d+m-1)+ ... + C(m-1)*z^(d+1) + C(m)*z^d

    EVEN - Even part of a Laurent polynomial.E = EVEN(P) returns the even part E of the Laurent polynomial P.The polynomial E is such that:

    E(z^2) = [P(z) + P(-z)]/2

    ODD - Odd part of a Laurent polynomial.O = ODD(P) returns the odd part O of the Laurent polynomial P.The polynomial O is such that:

    O(z^2) = [P(z) - P(-z)] / [2*z^(-1)] 4.1 PROGRAM: Plot of Real and imaginary part of a complex signal

    x = -5:0.01:5;a=sinh(x*0.1);subplot(5,1,1);

    plot(x,a), grid on % hyperbolic sine functiontitle( 'hyperbolic sine in range -5 to 5' );b=50+10i+sin(2*pi*x);subplot(5,1,2);plot(x,b);title( ' seq 2' );c=a+bsubplot(5,1,3);plot(c)title( 'complex signal' );d=real(c)subplot(5,1,4);plot(d)

  • 8/6/2019 BSL Manual

    24/78

    Basic simulation lab

    ECE Dept., MITS 24

    title( 'real part' )e=imag(d)subplot(5,1,5);plot(e)title( 'imaginary part' )

    OUTPUT:

    -5 -4 -3 -2 -1 0 1 2 3 4 5-101

    hyperbolic sine in range -5 to 5

    -5 -4 -3 -2 -1 0 1 2 3 4 5495051

    seq 2

    48.5 49 49.5 50 50.5 51 51.59

    1011

    complex signal

    0 200 400 600 800 1000 1200485052

    real part

    0 200 400 600 800 1000 1200-101

    imaginary part

    4.2 PROGRAM: Even and odd part of a sequence expressed as Laurent polynomial.

    a = laurpoly([1:3], 'dmax' ,2);disp( 'the polynomial under test for seperating even and odd parts is:' );ab=even(a);disp( 'even part of the polynomial is:' );bc=odd(a);disp( 'odd part of the polynomial is:' );c

    OUTPUT:

    the polynomial under test for seperating even and odd parts is:

    a(z) = + z^(+2) + 2*z^(+1) + 3

    even part of the polynomial is: odd part of the polynomial is:

    c(z) = 2*z^(+1)

  • 8/6/2019 BSL Manual

    25/78

    Basic simulation lab

    ECE Dept., MITS 25

    4.3: PROGRAM: Even/ odd part of signal% SIGNALn=-1:0.01:2;s1=sin(2*pi*1*n)+cos(2*pi*2*n) % x(n)s2=sin(2*pi*1*(-n))+cos(2*pi*2*(-n)) % x(-n)

    figure(1)subplot(2,1,1),plot(n,s1)

    title( 'X(n) SIGNAL' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    subplot(2,1,2),plot(n,s2)title( 'X(-n) SIGNAL' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    x1=(s1+s2)/2; % even part of the signalx2=(s1-s2)/2; % odd part of the signal

    figure(2)subplot(2,1,1),plot(n,x1)title( 'EVEN SIGNAL' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    subplot(2,1,2),plot(n,x2)title( 'ODD SIGNAL' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

  • 8/6/2019 BSL Manual

    26/78

    Basic simulation lab

    ECE Dept., MITS 26

    OUTPUT:

    -1 -0.5 0 0.5 1 1.5 2-1

    -0.5

    0

    0.5

    1EVEN SIGNAL

    time ------- t

    a m p l

    i t u

    d e

    -1 -0.5 0 0.5 1 1.5 2-1

    -0.5

    0

    0.5

    1ODD SIGNAL

    time ------- t

    a m

    p l i t u

    d e

    4.4 PROGRAM: Even and odd part of sequence

    % SEQUENCE

    y1 = input( 'enter the sequence' ) % X(n) sequenceN = length(y1)

    n=-(N-1)/2:1:(N-1)/2;%n=1:1:N;y2=0;for i=1:N

    y2(i)= y1(N+1-i); % X(-n) sequenceend

    figure(3)subplot(2,1,1),stem(n,y1)title( 'X(n) SEQUENCE' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )GRID

    subplot(2,1,2),stem(n,y2)title( 'X(-n) SEQUENCE' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )GRID

    x1 = (y1+y2)/2; % Even part of the sequencex2 = (y1-y2)/2; % Odd part of the sequence

    figure(4)subplot(2,1,1),stem(n,x1)

  • 8/6/2019 BSL Manual

    27/78

    Basic simulation lab

    ECE Dept., MITS 27

    title( 'EVEN SEQUENCE' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )GRID

    subplot(2,1,2),stem(n,x2)title( 'ODD SEQUENCE' )xlabel( 'samples ------- n' )ylabel( 'amplitude' )GRID

    OUTPUT:

    enter the sequence [ 1 2 3 4]

    y1 = 1 2 3 4

    N = 4

    -1.5 -1 -0.5 0 0.5 1 1.50

    1

    2

    3

    4X(n) SEQUENCE

    samples ------- n

    a m p

    l i t u

    d e

    -1.5 -1 -0.5 0 0.5 1 1.50

    1

    2

    3

    4X(-n) SEQUENCE

    samples ------- n

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    28/78

  • 8/6/2019 BSL Manual

    29/78

    Basic simulation lab

    ECE Dept., MITS 29

    GRID

    subplot(3,1,2),plot(r)title( 'Real part of Complex Signal' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    subplot(3,1,3),plot(i)title( 'Imaginary part of Complex Signal' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    Output :

    0 20 40 60 80 100 120-1

    -0.5

    0

    0.5

    1Signal 1 - as real part

    time ------- t

    a m p

    l i t u

    d e

    0 20 40 60 80 100 120-1

    -0.5

    0

    0.5

    1Signal 2 - as Imaginary part

    time ------- t

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    30/78

    Basic simulation lab

    ECE Dept., MITS 30

    -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1-1

    0

    1Complex Signal

    Real axes

    I m a g

    i n a r y a x e s

    0 20 40 60 80 100 120-1

    0

    1Real part of Complex Signal

    time ------- t

    a m p

    l i t u

    d e

    0 20 40 60 80 100 120-1

    0

    1Imaginary part of Complex Signal

    time ------- t

    a m p

    l i t u

    d e

    RESULT :

    MATLAB Functions to find Even and odd parts / real and imaginary parts of asignal/sequence were verified.

  • 8/6/2019 BSL Manual

    31/78

    Basic simulation lab

    ECE Dept., MITS 31

    5. CONVOLUTIONAIM:

    To perform linear and Circular Convolution of two Sequences/ Signals.

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    Linear Convolution:

    Convolution is an integral concatenation of two signals. It is used for thedetermination of the output signal of a linear time-invariant system by convolving the inputsignal with the impulse response of the system.

    Note that convolving two signals is equivalent to multiplying the Fourier transform of the twosignals.

    Mathematic Formula:The linear convolution of two continuous time signals and is defined by

    For discrete time signals and , the integration is replaced by a summation

    Circular Convolution:

    For the discrete case, multiplication in the frequency domain translates to circular convolution in the time domain

    5.1 PROGRAM: Linear Convolution

    clc;clear all ;close all ;x=input( 'enter the input sequence' );h=input( 'enter the impulse response' );n1=length(x);disp(n1)n2=length(h);disp(n2)n3=n1+n2-1;disp( 'the resultant length is:' );n3y=conv(x,h);figure;subplot(3,1,1);

  • 8/6/2019 BSL Manual

    32/78

    Basic simulation lab

    ECE Dept., MITS 32

    t1=0:1:(n1-1);stem(t1,x);xlabel( 'n' );ylabel( 'x(n)' );title( 'input sequence' );subplot(3,1,2);t2=0:1:(n2-1);stem(t2,h);xlabel( 'n' );ylabel( 'h(n)' );title( 'impulse response' );subplot(3,1,3);t3=0:1:(n3-1);stem(t3,y);xlabel( 'n' );ylabel( 'y(n)' );title( 'linear convoluted response' );disp( 'the resultant signal is:' );y

    Output Screen :

    enter the input sequence[ 1 2 3 4]enter the impulse response[ 3 5 6]

    4

    3

    the resultant length is:n3 =

    6

    the resultant signal is:y =

    3 11 25 39 38 24

  • 8/6/2019 BSL Manual

    33/78

  • 8/6/2019 BSL Manual

    34/78

  • 8/6/2019 BSL Manual

    35/78

    Basic simulation lab

    ECE Dept., MITS 35

    0 0.5 1 1.5 2 2.5 3 3.5 4-5

    0

    5

    n

    x ( n )

    first seq after zero padding

    0 0.5 1 1.5 2 2.5 3 3.5 40

    2

    4

    n

    y ( n )

    second seq after zero padding

    0 0.5 1 1.5 2 2.5 3 3.5 4-10

    0

    10

    n c

    i r c u

    l a r c o n v o

    l u t e d r e s u

    l t

    5.3 PROGRAM: Convolution between signals

    clc;clear all ;close all ;t= -pi:0.01:pi;f=input( 'enter the fundamental freq' );x=sin(2*pi*f*t);h=cos(2*pi*f*t);

    n1=length(x);disp(n1)n2=length(h);disp(n2)n3=n1+n2-1;disp( 'the resultant length is:' );n3y=conv(x,h);figure;subplot(3,1,1);t1=0:1:(n1-1);stem(t1,x);xlabel( 'n' );ylabel( 'x(n)' );title( 'input sequence' );subplot(3,1,2);t2=0:1:(n2-1);stem(t2,h);xlabel( 'n' );ylabel( 'h(n)' );title( 'impulse response' );subplot(3,1,3);t3=0:1:(n3-1);stem(t3,y);xlabel( 'n' );ylabel( 'y(n)' );title( 'linear convoluted response' );disp( 'the resultant signal is:' );y

  • 8/6/2019 BSL Manual

    36/78

    Basic simulation lab

    ECE Dept., MITS 36

    OUTPUT SCREEN:

    fundamental frequency is choosen as 2 Hz

    0 100 200 300 400 500 600 700-1

    01

    n

    x ( n )

    input sequence

    0 100 200 300 400 500 600 700-1

    0

    1

    n

    h ( n )

    impulse response

    0 200 400 600 800 1000 1200 1400-500

    0

    500

    n

    y ( n )

    linear convoluted response

    RESULT: Linear and Circular Convolution of Sequences/signals were verified usingMATLAB

  • 8/6/2019 BSL Manual

    37/78

    Basic simulation lab

    ECE Dept., MITS 37

    6. AUTO CORRELATION AND CROSS CORRELATIONAIM:

    To Verify Auto and Cross Correlation of Sequences / Signals Using MATLAB

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    The autocorrelation function is defined by the following equation.

    6.1 PROGRAM: Cross correlation of sequences:clc;clear all ;close all ;x=input( 'enter the first seq' );y=input( 'enter the second seq' );n1=(length(y)-1)n2=(length(x)-1)k=(-n1):n2';subplot(3,1,1);t1=0:1:n2;stem(t1,x);xlabel( 'n' );ylabel( 'amplitude' );title( 'seq 1' );subplot(3,1,2);t2=0:1:n1;stem(t2,y);xlabel( 'n' );ylabel( 'amplitude' );title( 'seq 2' );r=xcorr(x,y);subplot(3,1,3);stem(k,r);xlabel( 'lag index' );ylabel( 'amplitude' );title( 'cross correlated result' );disp( 'cross correlated result is:' );r

    output screen:

    enter the first seq[ 1 2 3 4]enter the second seq[ 1 2 3 4]

    n1 =

    3

  • 8/6/2019 BSL Manual

    38/78

  • 8/6/2019 BSL Manual

    39/78

  • 8/6/2019 BSL Manual

    40/78

    Basic simulation lab

    ECE Dept., MITS 40

    7. Linearity and Time InvarianceAIM:

    To Verify the Linearity and Time Invariance Properties of a given system using MATLAB

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    Linear and Non-linear Systems:

    A linear system is any system that obeys the properties of scaling (homogeneity) andsuperposition, while a nonlinear system is any system that does not obey at least one of these.

    To show that a system H obeys the scaling property is to show that

    H (kf (t )) =kH ( f (t )

    A block diagram demonstrating the scaling property of linearity

    To demonstrate that a system H obeys the superposition property of linearity is to show that

    H ( f 1(t ) + f 2(t )) = H ( f 1(t )) + H ( f 2(t ))

    A block diagram demonstrating the superposition property of linearity

    It is possible to check a system for linearity in a single (though larger) step. To do this,simply combine the first two steps to get

    H (k 1 f 1(t ) +k 2 f 2(t )) =k 2 H ( f 1(t )) +k 2 H ( f 2(t ))

    Time Invariant vs. Time Variant

    A time invariant system is one that does not depend on when it occurs: the shape of theoutput does not change with a delay of the input.

  • 8/6/2019 BSL Manual

    41/78

    Basic simulation lab

    ECE Dept., MITS 41

    That is to say that for a system H where H ( f (t )) = y(t ), H is time invariant if for all T

    H ( f (t T )) = y(t T )

    This block diagram shows what the condition for time invariance. The outputis the same whether the delay is put on the input or the output.

    When this property does not hold for a system, then it is said to be time variant , or time-varying.

    7.1: Linearity check

    PROGRAM:

    % linearity property

    x1 = input( 'enter the value for first input' );x2 = input( 'enter the value for second input' );a1 = input( 'enter weighting value for first input a1= ' );a2 = input( 'enter weighting value for second input a2= ' );

    f = menu( 'Chose a function' , 'cos(x)' , '2*x(n)' ) % to chose which functionfor which you want to verify the Linearity property

    if f == 1 % defined system function y = cos(x)

    y1 = a1*cos(x1) + a2*cos(x2);

    y2 = cos((a1*x1)+(a2*x2));

    if y1==y2disp( 'y = cos(x) is linear system' )

    elsedisp( 'y = cos(x) is non-linear system' )

    end

    else % defined system function y = 2*x

    y1 = a1*2*x1 + a2*2*x2;

    y2 = 2*((a1*x1)+(a2*x2));

    if y1==y2disp( 'y = 2*x is linear system' )

    elsedisp( 'y = 2*x is non-linear system' )

    endend

  • 8/6/2019 BSL Manual

    42/78

    Basic simulation lab

    ECE Dept., MITS 42

    Output:

    enter the value for first input2enter the value for second input3enter weighting value for first input a1= 4enter weighting value for second input a2= >> 3

    f =

    1

    y = cos(x) is non-linear system

    7.2 Time invariance:

    PROGRAM:

    % Time variancy property

    x = input( 'enter input applied to the system' ) p= input( 'enter the time at which the input arrived' )

    m = input( 'enter the time instant at which you want to calculate output' )

    k= m-p

    x(p)=x; f = menu( 'Chose a function' , 'cos(x)' , 'n*x(n)' ) % to chose which functionyou want to verify the time variancy

    if f == 1 % defined system function y(n) = cos(x(n))

    y1 = cos(x(p))

    y2 = cos(x(m-k))

    if y1 == y2disp( 'The given system y(n) = cos(x(n)) is Time invarient' )

    elsedisp( 'The given system y(n) = cos(x(n)) is Time varient' )

    end

    else % defined system function y(n) = n x(n)

    y1 = p*x(p)y2 = m*x(m-k)

    if y1 == y2disp( 'The given system y(n) = n*x(n) is Time invarient' )

    elsedisp( 'The given system y(n) = n*x(n) is Time varient' )

    endend

  • 8/6/2019 BSL Manual

    43/78

    Basic simulation lab

    ECE Dept., MITS 43

    OUTPUT

    enter input applied to the system2x = 2enter the time at which the input arrived3

    p = 3

    enter the time instant at which you want to calculate output5

    m = 5

    k = 2

    f = 1

    y1 =

    -0.4161

    y2 =

    -0.4161

    The given system y(n) = cos(x(n)) is Time invariant

    RESULT: Linearity and Time Invariance Properties of a given System was verified.

  • 8/6/2019 BSL Manual

    44/78

  • 8/6/2019 BSL Manual

    45/78

    Basic simulation lab

    ECE Dept., MITS 45

    Program:

    num = input( 'enter the numerator polynomial = ' )den = input( 'enter the denominator polynomial = ' )

    sys=tf(num,den) % the transfer function of system is defined by its num& den

    % To find the step response

    stp = step(sys)

    figure(1)plot(stp)title( 'STEP RESPONSE' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    % To find the impulse response

    i=impulse(sys)

    figure(2)plot(i)title( 'IMPULSE RESPONSE' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    % To find sinusoidal response

    n=0:0.01:1x=sin(2*pi*1*n)

    s=lsim(sys,x,n) % simulate time response of LTI system where x is type ofinput

    figure(3)subplot(2,1,1),plot(n,x)subplot(2,1,2),plot(n,s)title( 'SINUSOIDAL RESPONSE' )xlabel( 'time ------- t' )ylabel( 'amplitude' )GRID

    % alternate method to plot system response

    ltiview({ 'step' , 'impulse' },sys)

    % to find the stability of the system

    p=pole(sys)P=real(p)

    P1 = max(P)

    if P1 > 0disp( 'the given system is unstable' )

  • 8/6/2019 BSL Manual

    46/78

    Basic simulation lab

    ECE Dept., MITS 46

    elsedisp( 'the given system is stable' )

    end

    OUTPUT

    enter the numerator polynomial = [ 1 2]

    num =

    1 2

    enter the denominator polynomial = [3 1]

    den =

    3 1

    Transfer function:s + 2

    -------3 s + 1

    p = -0.2500

    P = -0.2500

    P1 = -0.2500

    the given system is stable

    0 20 40 60 80 100 1200.2

    0.4

    0.6

    0.8

    1

    1.2

    1.4

    1.6

    1.8

    2STEP RESPONSE

    time ------- t

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    47/78

    Basic simulation lab

    ECE Dept., MITS 47

    0 20 40 60 80 100 1200

    0.05

    0.1

    0.15

    0.2

    0.25

    0.3

    0.35

    0.4

    0.45IMPULSE RESPONSE

    time ------- t

    a m p

    l i t u

    d e

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

    -0.5

    0

    0.5

    1

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

    -0.2

    0

    0.2

    0.4SINUSOIDAL RESPONSE

    time ------- t

    a m p

    l i t u

    d e

    RESULT:

    Unit Sample, Unit Step, Sinusoidal Responses of given LTI system were obtained and itsStability was enquired using MATLAB.

  • 8/6/2019 BSL Manual

    48/78

    Basic simulation lab

    ECE Dept., MITS 48

    9. DEMONSTRATION OF GIBBS PHENOMENONAIM:

    To demonstrate Gibbs Phenomenon using MATLAB

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    Gibbs Phenomenon:

    The peculiar manner in which the Fourier series of a piecewise continuously differentiable periodic function behaves at a jump discontinuity: the nth partial sum of the Fourier serieshas large oscillations near the jump, which might increase the maximum of the partial sumabove that of the function itself. The overshoot does not die out as the frequency increases,

    but approaches a finite limit.

    The Gibbs phenomenon involves both the fact that Fourier sums overshoot at a jumpdiscontinuity, and that this overshoot does not die out as the frequency increases.

    The best known version of the Gibbs phenomenon is the overshoot that arises when a discontinuousfunction is represented by a truncated set of Fourier expansion terms. The situation is similar if thetruncated Fourier expansion is instead obtained by means of interpolation on an equispaced grid.

    PROGRAM:

    %%% MATLAB script to demonstrate the%%% Gibb's phenomenon.

    t=linspace(-2,2,2000);u=linspace(-2,2,2000);sq=[zeros(1,500),2*ones(1,1000),zeros(1,500)];k=2;N=[1,3,7,19,49,70];for n=1:6;an=[];for m=1:N(n)

    an=[an,2*k*sin(m*pi/2)/(m*pi)];end;fN=k/2;for m=1:N(n)

    fN=fN+an(m)*cos(m*pi*t/2);end;

    nq=int2str(N(n));subplot(3,2,n),plot(u,sq,'r','LineWidth',2);hold on;plot(t,fN,'LineWidth',2); hold off; axis([-2 2 -0.5 2.5]);grid;xlabel('Time'), ylabel('y_N(t)');title(['N= ',nq]);end;

    OUTPUT:

  • 8/6/2019 BSL Manual

    49/78

  • 8/6/2019 BSL Manual

    50/78

    Basic simulation lab

    ECE Dept., MITS 50

    10. FOURIER TRANSFORMAIM:

    To obtain Fourier Transform and Inverse Fourier Transform of a given signal / sequence andto plot its Magnitude and Phase Spectra.

    EQUIPMENT AND SOFTWARE:

    Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    The fast Fourier transform (FFT) is an efficient algorithm for computing the DFT of asequence; it is not a separate transform. It is particularly useful in areas such as signal andimage processing, where its uses range from filtering, convolution, and frequency analysis to

    power spectrum estimation

    For length N input vector x, the DFT is a length N vector X, with elements

    NX(k) = sum x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1

  • 8/6/2019 BSL Manual

    51/78

  • 8/6/2019 BSL Manual

    52/78

    Basic simulation lab

    ECE Dept., MITS 52

    subplot(4,1,4);plot(t,xn);title( 'inverse fourier transformed' )

    output:

    enter the frequency of signal 1 :50

    f1 = 50enter the frequency of signal 2 :100f2 = 100fs = 500N = 500

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

    0

    2signal in time domain

    0 50 100 150 200 250 300 350 400 450 5000

    200

    400 magnitude spectra

    0 50 100 150 200 250 300 350 400 450 500-5

    0

    5Phase spectra

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

    0

    2inverse fourier transformed

    NOTE: From magnitude spectra the components at frequencies 50and 100 are dominantly visible.

    RESULT: The Magnitude and Phase Spectra of Fourier Transformed Signal was Plotted

  • 8/6/2019 BSL Manual

    53/78

    Basic simulation lab

    ECE Dept., MITS 53

    11. LAPLACE TRANSFORMAIM:

    To obtain Laplace and Inverse Laplace Transforms of different functions.

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    The Laplace Transform of a function y(t) is defined by

    if the integral exists. The notation L[y(t)](s) means take the Laplace transform of y(t). Thefunctions y(t) and Y(s) are partner functions. Note that Y(s) is indeed only a function of ssince the definite integral is with respect to t.

    Example :

    Let y(t)=exp(t). We have

    The integral converges if s>1. The functions exp(t) and 1/(s-1) are partner functions.

    Existence of the Laplace Transform

    If y(t) is piecewise continuous for t>=0 and of exponential order, then the Laplace Transformexists for some values of s. A function y(t) is of exponential order c if there is exist constantsM and T such that

    All polynomials, simple exponentials (exp(at), where a is a constant), sine and cosinefunctions, and products of these functions are of exponential order. An example of a functionnot of exponential order is exp(t^2). This function grows too rapidly. The integral

    does not converge for any value of s.

    The inverse Laplace transform of the function Y(s) is the unique function y(t) that iscontinuous on [0,infty) and satisfies L[y(t)](s)=Y(s).

  • 8/6/2019 BSL Manual

    54/78

  • 8/6/2019 BSL Manual

    55/78

    Basic simulation lab

    ECE Dept., MITS 55

    12. POLES AND ZEROS OF A TRANSFER FUNCTIONAIM:To Plot Pole-Zero map for a given Transfer Function in S- Plane and Z-Planes

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    A Transfer Function is the ratio of the output of a system to the input of a system, in theLaplace domain considering its initial conditions to be zero. If we have an input function of X(s), and an output function Y(s), we define the transfer function H(s) to be:

    transfer function is the Laplace transform of a systems impulse response.

    Given a continuous-time transfer function in the Laplace domain, H ( s) or a discrete-time onein the Z-domain, H ( z ), a zero is any value of s or z such that the transfer function is zero, anda pole is any value of s or z such that the transfer function is infinite.

    Zeros :1. The value(s) for z where the numerator of the transfer function equals zero

    2. The complex frequencies that make the overall gain of the filter transfer functionzero.

    Poles : 1. The value(s) for z where the denominator of the transfer function equals zero2. The complex frequencies that make the overall gain of the filter transfer functioninfinite.

  • 8/6/2019 BSL Manual

    56/78

  • 8/6/2019 BSL Manual

    57/78

    Basic simulation lab

    ECE Dept., MITS 57

    13. GAUSSIAN NOISEAIM:

    To Generate Gaussian Noise and to Compute its Mean, M.S. Values, Skew, kurtosis, PSDand PDF

    EQUIPMENT AND SOFTWARE:

    Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    Gaussian noise is statistical noise that has a probability density function (abbreviated pdf) of the normal distribution (also known as Gaussian distribution). In other words, the values thatthe noise can take on are Gaussian-distributed. It is most commonly used as additive whitenoise to yield additive white Gaussian noise (AWGN).

    Gaussian noise is properly defined as the noise with a Gaussian amplitude distribution. Thissays nothing of the correlation of the noise in time or of the spectral density of the noise.

    Labeling Gaussian noise as 'white' describes the correlation of the noise. It is necessary to usethe term "white Gaussian noise" to be correct. Gaussian noise is sometimes misunderstood to

    be white Gaussian noise, but this is not the case.

    PROGRAM:

    % Generate white gaussian noise

    x=wgn(100,1,1)

    figure(1)plot(x)title( 'AWGN' );

    % to find mean of x

    m = mean(x)

    % to find standard deviation

    sd = std(x)

    % to find skewness

    s = skewness(x)

    % to find Kurtosis

    k = kurtosis(x)

    % to find psd of x

    fs =100;h=spectrum.welch

  • 8/6/2019 BSL Manual

    58/78

    Basic simulation lab

    ECE Dept., MITS 58

    figure(2)psd(h,x, 'fs' ,fs)

    % to find probability distribution function

    p = pdf( 'norm' ,x,0,1)figure(3)

    plot(p)title( 'pdf' );

    output:

    m = 0.0538

    sd = 0.9745

    s = -0.2489

    k = 2.6987

    h =

    EstimationMethod: 'Welch'FFTLength: 'NextPow2'

    SegmentLength: 64OverlapPercent: 50

    WindowName: 'Hamming'SamplingFlag: 'symmetric'

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

    -2

    -1.5

    -1

    -0.5

    0

    0.5

    1

    1.5

    2

    2.5AWGN

  • 8/6/2019 BSL Manual

    59/78

    Basic simulation lab

    ECE Dept., MITS 59

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

    -30

    -28

    -26

    -24

    -22

    -20

    -18

    -16

    -14

    -12

    Frequency (Hz)

    P o w e r /

    f r e q u e n c y

    ( d B / H z )

    Power Spectral Density Estimate via Welch

    0 10 20 30 40 50 60 70 80 90 1000

    0.05

    0.1

    0.15

    0.2

    0.25

    0.3

    0.35

    0.4pdf

    RESULT: Additive White Gaussian noise was generated and its PSD and PDF were plottedand its Mean, Standrad Deviation, Kurtosis, Skew were Computed using MATLABfunctions.

  • 8/6/2019 BSL Manual

    60/78

    Basic simulation lab

    ECE Dept., MITS 60

    14. SAMPLING THEORMAIM:To Demonstrate Sampling Theorem and aliasing effect using MATLAB.

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    The theorem shows that a band limited analog signal that has been sampled can be perfectlyreconstructed from an infinite sequence of samples if the sampling rate exceeds 2 B samples

    per second, where B is the highest frequency in the original signal.

    If a signal contains a component at exactly B hertz, then samples spaced at exactly 1/(2 B)seconds do not completely determine the signal, Shannon's statement notwithstanding.

    PROGRAM:

    f= input( 'enter the frequency' )fs= input( 'enter the sampling frequency' )t=0:1:fs+f-1;

    if fs >= 2*fdisp( 'sampling theorem is satisfied ' )

    %ploting of sinusoidaln=0:1/fs:pi;x=sin(2*pi*f*n);figure(1)plot(n,x)title( 'sinusoidal signal' )xlabel( 'time ------- t' )ylabel( 'amplitude' )

    % to plot the frequency spectrum (indirect method)

    s1=0:1/f:1-1/f;s2=(1-1/f)-s1;

    w1=[s2,zeros(1,(fs))];w2=[zeros(1,fs-f),s1,s2];figure(2)plot(t,w1, 'r' ,t,w2, 'b' )title( 'Frequency plot' )xlabel( 'frequency ------- f' )ylabel( 'amplitude' )legend( 'original signal' , 'lower side band & upper side band' )

    elsedisp( 'sampling theorem is not satisfied' )

    % to plot the frequency spectrum (indirect method)s1=0:1/f:1-1/f;s2=(1-s1);

    w1=[s2,zeros(1,(fs))];w2=[zeros(1,fs-f),s1,s2];

    figure(2)

  • 8/6/2019 BSL Manual

    61/78

    Basic simulation lab

    ECE Dept., MITS 61

    plot(t,w1, 'r' ,t,w2, 'b' )title( 'Frequency plot' )xlabel( 'frequency ------- f' )ylabel( 'amplitude' )legend( 'original signal' , 'lower side band & upper side band' )

    end

    OUTPUT:

    Case 1:

    enter the frequency30

    f =

    30

    enter the sampling frequency70

    fs =

    70

    sampling theorem is satisfied

    0 0.5 1 1.5 2 2.5 3 3.5-1

    -0.8

    -0.6

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1sinusoidal signal

    time ------- t

    a m p

    l i t u

    d e

  • 8/6/2019 BSL Manual

    62/78

  • 8/6/2019 BSL Manual

    63/78

    Basic simulation lab

    ECE Dept., MITS 63

    0 5 10 15 20 25 30 35 40 45 500

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1Frequency plot

    frequency ------- f

    a m p

    l i t u

    d e

    original signallower side band & upper side band

    RESULT: Sampling theorem was verified and aliasing was identified when the samplingfrequency is less than the nyquist frequency using MATLAB.

  • 8/6/2019 BSL Manual

    64/78

    Basic simulation lab

    ECE Dept., MITS 64

    15. EXTRACTING PERIODIC SIGNAL FROM NOISE

    AIM: To generate a periodic sequence, corrupt it with zero mean White noise and extract thesequence using periodic circular cross correlation.

    EQUIPMENT AND SOFTWARE:

    Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:Removal of noise by Filtering is not the solution because noise contains power at allfrequencies. Hence we use correlation techniques.

    v(k) y(k) M(k) c_yd(k) x^(k)

    x(k)

    PROGRAM:% Extracting a periodic signal from noise

    clear

    clc

    rand( 'state' ,1000)

    % Construct signals x and y

    N = 256;k = 0 : N-1;x = cos(32*pi*k/N) + sin(48*pi*k/N); % periodic signal which include%two sin componentsa = 0.5;y = f_randu(1,N,-a,a) + x; % + white noise uniformly distributed over%interval(-.5 , 0.5)

    figureplot (k,y)f_labels ( 'A noisy periodic signal' , '\it{k}' , '\it{y(k)}' )f_wait

    M = N/8;L = floor(N/M); %no. of complete cycles of x(k) in y(k)

    % generation of N-point Periodic impulse train with period Msuch that% M

  • 8/6/2019 BSL Manual

    65/78

    Basic simulation lab

    ECE Dept., MITS 65

    if rem(i-1,M) == 0d(i) = 1;

    endend% Compute cross-correlation with periodic pulse trainc_yd = f_corr (y,d,1,0); % fast cross correlation.

    % Plot portions of x and rhofigurem = 0 : N/4;plot (m,x(m+1),m,(N/L)*c_yd(m+1))f_labels ( 'Comparison of {\itx(k)} and{\it(N/L)c_{y\delta_M}(k)}' , '\it{k}' , 'signals' )

    OUTPUT:

    0 50 100 150 200 250 300-2.5

    -2

    -1.5

    -1

    -0.5

    0

    0.5

    1

    1.5

    2

    2.5A noisy periodic signal

    k

    y ( k )

  • 8/6/2019 BSL Manual

    66/78

    Basic simulation lab

    ECE Dept., MITS 66

    0 10 20 30 40 50 60 70-2.5

    -2

    -1.5

    -1

    -0.5

    0

    0.5

    1

    1.5

    2

    Comparison of x(k) and (N/L)c y M

    (k)

    k

    s i g n a

    l s

    RESULT: using Cross- correlation the periodic signal from noise was estimated usingMATLAB.

  • 8/6/2019 BSL Manual

    67/78

  • 8/6/2019 BSL Manual

    68/78

    Basic simulation lab

    ECE Dept., MITS 68

    PROGRAM:

    Fd=input( 'enter Fd the sampling frequency of digital i/p signal:' );disp( 'The ratio Fs/Fd must be a positive integer greater than 1' );

    % Define filter-related parameters.

    Fs=input( 'enter Fs the sampling frequency for the filter:' );filtorder = 40; % Filter orderdelay = filtorder/(Fs*2); % Group delay (# of input samples)rolloff = 0.25; % Rolloff factor of filterrcfilter = rcosine(Fd,Fs, 'fir' ,rolloff,delay);H=tf(rcfilter)% Plot impulse response.%figure; impz(rcfilter,1)

    fvtool(rcfilter)

    OUTPUT:

    enter Fd the sampling frequency of digital i/p signal:1

    The ratio Fs/Fd must be a positive integer greater than 1

    enter Fs the sampling frequency for the filter:4

  • 8/6/2019 BSL Manual

    69/78

  • 8/6/2019 BSL Manual

    70/78

    Basic simulation lab

    ECE Dept., MITS 70

    0 5 10 15 20 25 30 35 40-0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    Samples

    Impulse Response

    A m p

    l i t u

    d e

    RESULT:

    The Impulse Response of a Raised Cosine Filter was plotted using fvtool in MATLAB.

  • 8/6/2019 BSL Manual

    71/78

    Basic simulation lab

    ECE Dept., MITS 71

    17. WIENER-KHINCHIN THEORMAIM:

    To calculate auto-correlation function using Wiener- Khinchin Theorm in MATLAB.

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    The WienerKhinchin theorem (also known as the WienerKhintchine theorem andsometimes as the WienerKhinchinEinstein theorem or the KhinchinKolmogorovtheorem ) states that the power spectral density of a wide-sense-stationary random process isthe Fourier transform of the corresponding autocorrelation function.

    Continuous case:

    where

    is the autocorrelation function defined in terms of statistical expectation, and where

    is the power spectral density of the function . Note that the autocorrelation function is

    defined in terms of the expected value of a product, and that the Fourier transform of

    does not exist in general, because stationary random functions are not square integrable.

    The asterisk denotes complex conjugate, and can be omitted if the random process is real-valued.

    Discrete case:

    where

    and where is the power spectral density of the function with discrete values .Being a sampled and discrete-time sequence, the spectral density is periodic in the frequencydomain.

  • 8/6/2019 BSL Manual

    72/78

  • 8/6/2019 BSL Manual

    73/78

    Basic simulation lab

    ECE Dept., MITS 73

    OUTPUT:

    0 10 20 30 40 50 60 70-0.1

    0

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    X: 1.1Y: 0.2776

    17.2 PROGRAM:

    clear all ;clc;fs=1000;t=0:1/fs:.5;x=cos(2*pi*t*200)+randn(size(t)); %a cosine of 200Hz plus noisek=length(x)y=fft(x,k); %fft of random processpyy=y.*conj(y)/k; % auto correlationf=1000*(0:k-1)/k;figure(1)plot(f,pyy(1:k));title( 'frequency content of y' );xlabel( 'frq in hz' );figure(2)h=spectrum.welch; %instantiate a welch objectpsd(h,x, 'fs' ,fs)figure(3)h=spectrum.periodogram %instantiate a periodogram object tocalculate psd

    psd(h,x, 'fs' ,fs);

  • 8/6/2019 BSL Manual

    74/78

    Basic simulation lab

    ECE Dept., MITS 74

    output:

    0 100 200 300 400 500 600 700 800 900 10000

    20

    40

    60

    80

    100

    120frequency content of y

    frq in hz

    0 50 100 150 200 250 300 350 400 450 500-34

    -32

    -30

    -28

    -26

    -24

    -22

    -20

    -18

    -16

    Frequency (Hz)

    P o w e r /

    f r e q u e n c y

    ( d B / H z

    )

    Welch Power Spectral Density Estimate

  • 8/6/2019 BSL Manual

    75/78

    Basic simulation lab

    ECE Dept., MITS 75

    0 50 100 150 200 250 300 350 400 450 500-60

    -50

    -40

    -30

    -20

    -10

    0

    Frequency (Hz)

    P o w e r /

    f r e q u e n c y

    ( d B / H z )

    Periodogram Power Spectral Density Estimate

    RESULT:

    Calculation of Auto-correlation function using Weiner-Khinchin theorm was verified usingMATLAB.

  • 8/6/2019 BSL Manual

    76/78

    Basic simulation lab

    ECE Dept., MITS 76

    18. WSS OF A RANDOM PROCESSAIM:

    To generate a Random process and to check for its Wide Sense Stationary using MATLAB

    EQUIPMENT AND SOFTWARE:Personal Computer loaded with MATLAB 7.1

    OPERATING SYSTEM:Windows XP

    THEORY:

    A random process is wide sense stationary (WSS) if the mean function and

    autocorrelation function are invariant to a time shift. In particular, this implies that

    All strict sense stationary random processes are also WSS, provided that the mean and

    autocorrelation function exist. The converse is not true. A WSS process does not necessarily

    need to be stationary in the strict sense. We refer to a process that is not WSS as non -

    stationary.

    Many of the processes we deal with are WSS and hence have a constant mean

    function and an autocorrelation function that depends only on a single time variable. Hence,in the remainder of the text, when a process is known to be WSS or if we are assuming it to

    be WSS, then we will represent its autocorrelation function by R XX ( ). If a process is non -

    stationary or if we do not know if the process is WSS, then we will explicitly write the

    autocorrelation function as a function of two variables, R XX (t , t + ).

  • 8/6/2019 BSL Manual

    77/78

    Basic simulation lab

    ECE Dept., MITS 77

    PROGRAM:

    clc;

    clear all;

    close all;

    syms pi a wo t t1 t2 theta

    l=input('Enter the lower limit');

    u=input('Enter the upper limit');

    x=input('Enter the PDF');

    f=a*cos((wo*t)+theta);

    f1=f*x;

    y1=int(f1,theta,l,u);

    disp('The Expectation is:');

    disp(y1);f2=a*cos((wo*t1)+theta);

    f3=a*cos((wo*t2)+theta);

    f4=f2*f3*x;

    y2=int(f4,theta,l,u);

    disp('The AutoCorrelation is:');

    disp(y2);

    Manual Calculation1) Consider the random process X(t)=Acos (0t+) Where is real -valued random

    variable and is uniformly distributed over [0 , ]. Check if the process is wide sensestationary.

    2) Consider the random process X(t)=A cos( 0t+) Where is real -valued random variableand is uniformly distributed over [0, 2 ]. Check if the process is wide sense stationary.

    OUTPUT:

    Enter the lower limit0

    Enter the upper limit2*piEnter the PDF1/(2*pi)

    The Expectation is: 0

    The AutoCorrelation is:

    1/2*a^2*(cos(wo*t1)*cos(wo*t2)+sin(wo*t1)*sin(wo*t2))

  • 8/6/2019 BSL Manual

    78/78

    Basic simulation lab

    RESULT:

    Thus the given random processes are identified whether they are WSS or not through

    calculating the mean and autocorrelation functions manually and verified these results

    through MATLAB simulation.