Académique Documents
Professionnel Documents
Culture Documents
Windows XP
THEORY:
MATLAB, which stands for MATrix LABoratory, is a state-of-the-art mathematical software package, which is used extensively in both academia and industry. It is an interactive program for numerical computation and data visualization, which along with its programming capabilities provides a very useful tool for almost all areas of science and engineering. 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 is a 1-by-1 matrix and a row vector of length say 5, is a 1-by-5 matrix.. One of the many advantages of MATLAB is the natural notation used. It looks a lot like the notation that you encounter in a linear algebra. This makes the use of the program especially easy and it is what makes MATLAB a natural choice for numerical computations. The purpose of this experiment 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 by default 1. The default increment can be changed (to 0.1) by using increment field in between as e= [0:0.1:7]. d(1:2) allows to look into vector with increment 1 e(1:2:4) look with increment
Remember that the multiplication, power and division operators can be used in conjunction with a period to specify an element-wise operation.
Typical commands: 1. whos 2. who 3. clear 4. quit 5. save filename filename.mat 6. load filename - retrive 7. dairy filename - b4 and after ascii text file 8. help
Built in Functions: 1. Scalar Functions: Certain MATLAB functions are essentially used on scalars, but operate element-wise when applied to a matrix (or vector). They are summarized below. 1. sin - trigonometric sine 2. cos - trigonometric cosine 3. tan - trigonometric tangent 4. asin - trigonometric inverse sine (arcsine) 5. acos - trigonometric inverse cosine (arccosine) 6. atan - trigonometric inverse tangent (arctangent) 7. exp - exponential 8. log - natural logarithm 9. abs - absolute value 10. sqrt - square root 11. rem - remainder 12. round - round towards nearest integer 13. floor - round towards negative infinity 14. 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.
largest component : get the row in which the maximum element lies smallest component length of a vector sort in ascending order sum of elements product of elements median value mean value std standard deviation
0 0 0.2661
commands in the second sub-category of matrix functions are 1. size 2. det 3. inv 4. rank 5. rref 6. eig 7. poly 8. norm 9. cond 10. lu 11. qr 12. chol 13. svd size of a matrix determinant of a square matrix inverse of a matrix rank of a matrix reduced row echelon form eigenvalues and eigenvectors characteristic polynomial norm of matrix (1-norm, 2-norm, -norm) condition number in the 2-norm LU factorization QR factorization Cholesky decomposition singular value decomposition
Operations on matrices:
1. Transpose (single quote ) a= [ 1 2 3 ]; b=a; 2. extraction of submatrices a=[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 c d=a(1,:) ; first row of matrix a is sub-matrix d
We can check our result by verifying that AA1 = I and A1A = I . A*inv(A), inv(A)*A
The eigenvalues and eigenvectors of A (i.e. the numbers and vectors x that satisfy Ax = x ) can be obtained through the eig command. eig(A) produces a column vector with the eigenvalues [X,D]=eig(A) produces a diagonal matrix D with the eigen values on the main diagonal, and a full matrix X whose columns are the corresponding eigenvectors.
RESULT: MATLAB basic features and built in functions were practiced thoroughly.
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 axis represents. 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 be displayed 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 the case above) MATLAB will assign (and cycle through) the default ones as given in the table below. y yellow . point m magenta o circle c cyan x x-mark r red + plus g green - solid b blue * star w white : dotted k 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 a dashed 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
Common Sequences: Unit Impulse, Unit Step, and Unit Ramp Common Periodic Waveforms
The toolbox provides functions for generating widely used periodic waveforms: sawtooth generates a sawtooth wave with peaks at 1 and a period of 2. An optional width parameter specifies a fractional multiple of 2 at which the signal's maximum occurs. square generates a square wave with a period of 2. An optional parameter specifies duty cycle, the percent of the period for which the signal is positive.
Common Aperiodic Waveforms The toolbox also provides functions for generating several widely used aperiodic waveforms: gauspuls generates a Gaussian-modulated sinusoidal pulse with a specified time, center frequency, and fractional bandwidth. Optional parameters return in-phase and quadrature pulses, the RF signal envelope, and the cutoff time for the trailing pulse envelope. chirp generates a linear, log, or quadratic swept-frequency cosine signal. An optional parameter specifies alternative sweep methods. An optional parameter phi allows initial phase to be specified in degrees. The pulstran Function The pulstran function generates pulse trains from either continuous or sampled prototype pulses. The following example generates a pulse train consisting of the sum of multiple delayed interpolations of a Gaussian pulse.
Basic simulation lab 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 following equation 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 periodic sinc 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 magnitude of 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)]; unit_step = ones(100,1); ramp_sig= t; quad_sig=t.^2; sq_wave = square(4*pi*t); % Impulse % Step (with 0 initial cond.) % Ramp % Quadratic % 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 pulse repetition rate of 1 kHz; D specifies the delay to each pulse repetition in column 1 and an optional attenuation for each repetition in column 2. The pulse train is constructed by passing the name of the
x = 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
Plot of the sinc function for a linearly spaced vector with values ranging from -5 to 5
2.2 PROGRAM:
N = input('enter the length of sequence in even number') % step sequence x = ones(1,N) ;
n')
n=-N1:1:N1; figure(2) stem(n,x) axis([-(N1) N1 -1 2]) title('IMPULSE SEQUENCE') xlabel('samples ------ylabel('amplitude') grid % ramp sequence
n=0:1:N-1;
n')
x=n;
figure(3) stem(n,x) axis([-1 N -1 N]) title('RAMP SEQUENCE') xlabel('samples ------ylabel('amplitude') grid
n')
% 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;
n')
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 ------ylabel('amplitude')
n')
n')
%t=0:0.01:1 d=0:0.2:1 howmany times the waveform should repeat y1=pulstran(n,d,'tripuls',0.1) pulse d=0.1:0.2:1 y2=pulstran(n,d,'tripuls',0.1) % repetative frequency (defines
% generate train of tiangular
1.5
1
amplitude
0.5
-0.5
-1 -1
2 samples
3 ------- n
IMPULSE SEQUENCE 2
1.5
amplitude
0.5
-0.5
-1 -3
-2
-1 samples
0 ------- n
amplitude
-1 -1
2 samples
3 ------- n
EXPONENTIAL SEQUENCE 2
1.5
amplitude
0.5
-0.5
-1 -1
2 samples
3 ------- n
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.8
0.9
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
amplitude
0.5
-0.5 -5
-4
-3
-2
amplitude
0.5
-0.5 -5
-4
-3
-2
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
1 0.5
amplitude
0 -0.5 -1
0.1
0.2
0.3
0.7
0.8
0.9
Basic simulation lab 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
Power is a time average of energy (energy per unit time). This is useful when the energy of the signal goes to infinity.
output:
x(t)
0 -1 -2 -1 0 1 t multiplication 2
x(t)
0 -2 -2 -1 0 t scaled 1 2
500
x(t)
x(t)
0 -2 -1 0 t shifted 1 2
0 -2 -2 -1 0 t folded 1 2
x(t)
0 -2 -2 -1 0 t 1 2
x(t)
0 -1 -2 -1 0 t 1 2
clc; t=-2:0.01:2; f=input('enter the fundamental frequency:'); a=input('enter the amplitude:'); x=a*sin(2*pi*f*t);
OUTPUT SCREEN:
enter the fundamental frequency:2 enter the amplitude:2
test signal for energy calculation 2 1
x(t)
0 -1 -2 -2
-1.5
-1
-0.5
1.5
4 3
x 2(t)
2 1 0 -2
-1.5
-1
-0.5
0 t
0.5
1.5
subplot(2,1,2); stem(n,x2.^2); hold on; % red lines marking 1 & 20 plot([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
x 1(t)
0 -0.5 -1 -2
-1.5
-1
-0.5
1.5
1 0.5
x 2(n)
0 -0.5 -1 -40
-30
-20
-10
0 n
10
20
30
40
Figure(2)
Squared sines 1
x 2(t) 1
0.5
x 2(n) 2
0.5
RESULT: various functions on signals and sequences such as addition, multiplication, scaling, shifting, folding, computation of energy and power were performed in MATLAB ECE Dept., MITS 22
Basic simulation lab 4. FINDING EVEN AND ODD PARTS / REAL AND IMAGINARY PARTS OF A SIGNAL/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 highest degree 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. The corresponding 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 function title('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+b subplot(5,1,3); plot(c) title('complex signal'); d=real(c) subplot(5,1,4); plot(d)
OUTPUT:
-4
-3
-2
-1
0 seq 2
-4
-3
-2
-1 0 1 complex signal
49
49.5
50 real part
50.5
51
51.5
200
400
800
1000
1200
200
400
600
800
1000
1200
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:');a b=even(a); disp('even part of the polynomial is:');b c=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)
x1=(s1+s2)/2; x2=(s1-s2)/2; 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
amplitude
0 -0.5 -1 -1
-0.5
1.5
1 0.5
amplitude
0 -0.5 -1 -1
-0.5
1.5
% X(-n) sequence
n')
n')
n')
N =
4
X(n) SEQUENCE 4 3
amplitude
2 1 0 -1.5
-1
-0.5
1.5
4 3
amplitude
2 1 0 -1.5
-1
-0.5
0.5
1.5
samples
------- n
amplitude
0 -1.5
-1
-0.5
1.5
2 1
amplitude
0 -1 -2 -1.5
-1
-0.5 samples
0 ------- n
0.5
1.5
figure(5) subplot(2,1,1),plot(x1) title('Signal 1 - as real part') xlabel('time ------t') ylabel('amplitude') GRID subplot(2,1,2),plot(x2) title('Signal 2 - as Imaginary part') xlabel('time ------t') ylabel('amplitude') GRID figure(6) subplot(3,1,1),plot(x3) title('Complex Signal') xlabel('Real axes') ylabel('Imaginary axes')
Output:
Signal 1 - as real part 1 0.5
amplitude
0 -0.5 -1
20
40
100
120
1 0.5
amplitude
0 -0.5 -1
20
40 time
60 ------- t
80
100
120
amplitude
RESULT: MATLAB Functions to find Even and odd parts / real and imaginary parts of a signal/sequence were verified.
Basic simulation lab 5. CONVOLUTION AIM: To perform linear and Circular Convolution of two Sequences/ Signals. EQUIPMENT AND SOFTWARE: Personal Computer loaded with MATLAB 7.1 OPERATING SYSTEM:
Windows XP
and
is defined by
and
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:');n3 y=conv(x,h); figure; subplot(3,1,1);
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
x(n)
10
h(n)
5 0 0 0.2 0.4 0.6 1 1.2 1.4 n linear convoluted response 0.8 1.6 1.8 2
40
y(n)
output screen:
3 1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
0 -3 -7 -4 -4 -4 -4 -4 -4 -4
0 0 -6 0 -1
x(n)
y(n)
input sequence 1
x(n)
h(n)
0 -1 0 100 200 400 500 n linear convoluted response 300 600 700
500
y (n)
RESULT: Linear and Circular Convolution of Sequences/signals were verified using MATLAB
Basic simulation lab 6. AUTO CORRELATION AND CROSS CORRELATION 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:
The autocorrelation function is defined by the following equation.
output screen:
enter the first seq[ 1 2 3 4] enter the second seq[ 1 2 3 4] n1 = 3
3
cross correlated result is: r= 4.0000 11.0000 20.0000 30.0000 20.0000 11.0000 4.0000
Output:
seq 1
amplitude
amplitude
amplitude
40 20 0 -3 -2 -1 0 lag index 1 2 3
OUTPUT:
enter the fundamental freq: 2
n2 = 628
input for auto correlation 1 0.5
amplitude
0 -0.5 -1
100
200
300
500
600
700
400 200
amplitude
-600
-400
-200
0 lag index
200
400
600
800
RESULT: Auto and Cross Correlation of Sequences/ Signal was verified using MATLAB
Basic simulation lab 7. Linearity and Time Invariance AIM: 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) and superposition, 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 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(k1f1(t) +k2f2(t)) =k2H(f1(t)) +k2H(f2(t)) Time Invariant vs. Time Variant A time invariant system is one that does not depend on when it occurs: the shape of the output does not change with a delay of the input. ECE Dept., MITS 40
Basic simulation lab 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(tT)) =y(tT)
This block diagram shows what the condition for time invariance. The output is 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 timevarying.
7.1: Linearity check PROGRAM:
% linearity property
x1 x2 a1 a2 = = = = input('enter input('enter input('enter input('enter the value the value weighting weighting for first input'); for second input'); value for first input a1= '); value for second input a2= ');
f = menu('Chose a function','cos(x)','2*x(n)') % to chose which function for 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==y2 disp('y = cos(x) is linear system') else disp('y = cos(x) is non-linear system') end
else
y1 = a1*2*x1 + a2*2*x2; y2 = 2*((a1*x1)+(a2*x2)); if y1==y2 disp('y = 2*x is linear system') else disp('y = 2*x is non-linear system') end end
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)') you want to verify the time variancy % to chose which function
if f == 1
y1 = cos(x(p))
y2 = cos(x(m-k))
if y1 == y2 disp('The given system y(n) = cos(x(n)) is Time invarient') else disp('The given system y(n) = cos(x(n)) is Time varient') end
if y1 == y2 disp('The given system y(n) = n*x(n) is Time invarient') else disp('The given system y(n) = n*x(n) is Time varient') end end
p=
enter the time instant at which you want to calculate output5 m= k= f= 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. 5 2 1
Basic simulation lab 8. UNIT SAMPLE, UNIT STEP, SINUSOIDAL RESPONSES OF LTI SYSTEM TO VERIFY STABILITY AIM:
To Compute Unit Sample, Unit Step, Sinusoidal Responses of given LTI system and to verify its Stability using MATLAB
EQUIPMENT AND SOFTWARE: Personal Computer loaded with MATLAB 7.1 OPERATING SYSTEM:
Windows XP
THEORY: An LTI system is stable if every bounded input produces a bounded output, i.e.,
is true for all . But as the output and input of an LTI is related by convolution, we have:
i.e., In other words, the LTI system is stable if its impulse response function absolutely integrable. is
% To find the step response stp = step(sys) figure(1) plot(stp) title('STEP RESPONSE') xlabel('time ------ylabel('amplitude') GRID
t')
% 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:1 x=sin(2*pi*1*n) s=lsim(sys,x,n) % simulate time response of LTI system where x is type of input 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
ltiview({'step','impulse'},sys) % to find the stability of the system p=pole(sys) P=real(p) P1 = max(P) if P1 > 0 disp('the given system is unstable')
P = P1 =
-0.2500 -0.2500
amplitude
20
40 time
60 ------- t
80
100
120
amplitude
20
40 time
60 ------- t
80
100
120
1 0.5 0 -0.5 -1
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0.8
0.9
amplitude
0 -0.2 -0.4
0.1
0.2
0.3
0.7
0.8
0.9
RESULT: Unit Sample, Unit Step, Sinusoidal Responses of given LTI system were obtained and its Stability was enquired using MATLAB. ECE Dept., MITS 47
Basic simulation lab 9. DEMONSTRATION OF GIBBS PHENOMENON AIM: To demonstrate Gibbs Phenomenon using MATLAB EQUIPMENT AND SOFTWARE: Personal Computer loaded with MATLAB 7.1 OPERATING SYSTEM:
Windows XP
The Gibbs phenomenon involves both the fact that Fourier sums overshoot at a jump discontinuity, 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 discontinuous function is represented by a truncated set of Fourier expansion terms. The situation is similar if the truncated 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;
N= 3 2
y N(t)
1 0 -2 -1 0 Time N= 7 1 2
1 0 -2 -1 0 Time N= 19 1 2
2
y N(t)
2
y N(t)
1 0 -2 -1 0 Time N= 49 1 2
1 0 -2 -1 0 Time N= 70 1 2
2
y N(t)
2
y N(t)
1 0 -2 -1 0 Time 1 2
1 0 -2 -1 0 Time 1 2
Basic simulation lab 10. FOURIER TRANSFORM AIM: To obtain Fourier Transform and Inverse Fourier Transform of a given signal / sequence and to 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 a sequence; it is not a separate transform. It is particularly useful in areas such as signal and image 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, N X(k) = sum x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N. n=1 with elements
The inverse DFT (computed by IFFT) is given by N x(n) = (1/N) sum X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N. k=1 10.1: Program: Fourier Transform and Inverse FT of a Signal
N=input('enter the length of input signal'); %prepare to sample a signal for two seconds, % at a rate of 100 samples per second. Fs = 100; % Sampling rate t = [0:2*Fs+1]'/Fs % Time points for sampling x = sin(2*pi*t) + sin(4*pi*t); subplot(4,1,1); plot(t,x); title('signal in time domain'); XK=fft(x,N); disp(XK); m=abs(XK); subplot(4,1,2); plot(m); title('magnitude spectra'); a=angle(XK); subplot(4,1,3); plot(a); title('Phase spectra'); xn=ifft(XK,N); disp(xn); subplot(4,1,4); plot(xn);
Edited by Foxit Reader Copyright(C) by Foxit Software Company,2005-2007 Basic simulation lab For Evaluation Only.
title('inverse fourier transformed')
output:
Enter the length of input signal 1000
signal in time domain 2 0 -2 200 100 0 5 0 -5 2 0 -2 0 100 200 300 400 500 600 700 800 900 1000 0 100 200 300 400 500 600 700 inverse fourier transformed 800 900 1000 0 100 200 300 400 500 600 Phase spectra 700 800 900 1000 0 0.5 1 1.5 magnitude spectra 2 2.5
y=fft(x,N); disp(y); m=abs(y); f = (0:N-1)/(N/fs) subplot(4,1,2); plot(f,m); title('magnitude spectra'); a=angle(y); subplot(4,1,3); plot(f,a); title('Phase spectra'); xn=ifft(y); disp(xn);
output:
enter the frequency of signal 1 :50 f1 = 50 enter the frequency of signal 2 :100 f2 = 100 fs = 500 N = 500
signal in time domain 2 0 -2 400 200 0 5 0 -5 2 0 -2 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 50 100 150 200 250 300 350 inverse fourier transformed 400 450 500 0 50 100 150 200 250 300 Phase spectra 350 400 450 500 0 0.1 0.2 0.3 0.4 0.5 0.6 magnitude spectra 0.7 0.8 0.9 1
NOTE: From magnitude spectra the components at frequencies 50 and 100 are dominantly visible. RESULT: The Magnitude and Phase Spectra of Fourier Transformed Signal was Plotted
Basic simulation lab 11. LAPLACE TRANSFORM AIM: 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). The functions y(t) and Y(s) are partner functions. Note that Y(s) is indeed only a function of s since 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 Transform exists for some values of s. A function y(t) is of exponential order c if there is exist constants M and T such that
All polynomials, simple exponentials (exp(at), where a is a constant), sine and cosine functions, and products of these functions are of exponential order. An example of a function not of exponential order is exp(t^2). This function grows too rapidly. The integral
The inverse Laplace transform of the function Y(s) is the unique function y(t) that is continuous on [0,infty) and satisfies L[y(t)](s)=Y(s). ECE Dept., MITS 53
Basic simulation lab If all possible functions y(t) are discontinous one can select a piecewise continuous function to be the inverse transform. We will use the notation
PROGRAM:
% finding laplace trasform syms t s % specify that variables t and s are symbolic ones f=-1.25+3.5*t*exp(-2*t)+1.25*exp(-2*t) F=laplace(f,t,s) simplify(F) pretty(ans) %finding inverse laplace transform a=(s-5)/(s*(s+2)*2); f=ilaplace(a) simplify(f) pretty(f)
OUTPUT:
f= -5/4+7/2*t*exp(-2*t)+5/4*exp(-2*t) F= -5/4/s+7/2/(s+2)^2+5/4/(s+2) ans = (s-5)/s/(s+2)^2 s-5 ---------2 s (s + 2) f= 1/2*exp(-t)*(cosh(t)-6*sinh(t)) ans = 1/2*exp(-t)*(cosh(t)-6*sinh(t)) 1/2 exp(-t) (cosh(t) - 6 sinh(t)) RESULT : Laplace and inverse laplace transforms were verified using MATLAB functions.
Basic simulation lab 12. POLES AND ZEROS OF A TRANSFER FUNCTION AIM: 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 the Laplace 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:
Given a continuous-time transfer function in the Laplace domain, H(s) or a discrete-time one in the Z-domain, H(z), a zero is any value of s or z such that the transfer function is zero, and a 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 function
zero.
Poles: 1. The value(s) for z where the denominator of the transfer function equals zero 2. The complex frequencies that make the overall gain of the filter transfer function infinite.
OUTPUT:
Pole-Zero Map
0.5
0.5
Imaginary Axis
Imaginary Axis
-2 Real Axis 0 2
-0.5
-0.5
-1
-1
-1.5 -4
-1.5 -4
-2 Real Axis
RESULT: Poles and Zeros of given transfer function are located and plotted in S- plane and Z- plane
Basic simulation lab 13. GAUSSIAN NOISE AIM: To Generate Gaussian Noise and to Compute its Mean, M.S. Values, Skew, kurtosis, PSD and 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 that the noise can take on are Gaussian-distributed. It is most commonly used as additive white noise to yield additive white Gaussian noise (AWGN). Gaussian noise is properly defined as the noise with a Gaussian amplitude distribution. This says 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 use the 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)
output:
m= sd = 0.0538 0.9745
s = -0.2489 k= h= EstimationMethod: 'Welch' FFTLength: 'NextPow2' SegmentLength: 64 OverlapPercent: 50 WindowName: 'Hamming' SamplingFlag: 'symmetric'
AWGN 2.5 2 1.5 1 0.5 0 -0.5 -1 -1.5 -2 -2.5
2.6987
10
20
30
40
50
60
70
80
90
100
Power/frequency (dB/Hz)
10
15
20 25 30 Frequency (Hz)
35
40
45
50
10
20
30
40
50
60
70
80
90
100
RESULT: Additive White Gaussian noise was generated and its PSD and PDF were plotted and its Mean, Standrad Deviation, Kurtosis, Skew were Computed using MATLAB functions. ECE Dept., MITS 59
Basic simulation lab 14. SAMPLING THEORM AIM: 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 perfectly reconstructed from an infinite sequence of samples if the sampling rate exceeds 2B 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/(2B) 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*f disp('sampling theorem is satisfied ') %ploting of sinusoidal n=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')
else
disp('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)
OUTPUT: Case 1:
enter the frequency30 f= 30 enter the sampling frequency70 fs = 70 sampling theorem is satisfied
sinusoidal signal 1 0.8 0.6 0.4 0.2
amplitude
0.5
1.5 time
2 ------- t
2.5
3.5
amplitude
10
20
30
40 50 60 frequency ------- f
70
80
90
100
Case 2: enter the frequency20 f= 20 enter the sampling frequency30 fs = 30 sampling theorem is not satisfied
amplitude
10
15
20 25 30 frequency ------- f
35
40
45
50
RESULT: Sampling theorem was verified and aliasing was identified when the sampling frequency is less than the nyquist frequency using MATLAB.
Basic simulation lab 15. EXTRACTING PERIODIC SIGNAL FROM NOISE AIM: To generate a periodic sequence, corrupt it with zero mean White noise and extract the sequence 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 all frequencies. Hence we use correlation techniques.
v(k) x(k)
y(k)
M(k)
c_yd(k)
x^(k)
Circular CrossCorrelation
N/L
PROGRAM:
% Extracting a periodic signal from noise
N = 256; k = 0 : N-1; x = cos(32*pi*k/N) + sin(48*pi*k/N); % periodic signal which include %two sin components a = 0.5; y = f_randu(1,N,-a,a) + x; % + white noise uniformly distributed over %interval(-.5 , 0.5) figure plot (k,y) f_labels ('A noisy periodic signal','\it{k}','\it{y(k)}') f_wait M = N/8; L = floor(N/M);
% generation of N-point Periodic impulse train with period Msuch that % M<<N d = zeros(1,N); for i = 1 : N
OUTPUT:
A noisy periodic signal
2.5 2 1.5 1 0.5
y(k)
50
100
150
200
250
300
signals
10
20
30
40
50
60
70
RESULT: using Cross- correlation the periodic signal from noise was estimated using MATLAB.
Basic simulation lab 16. IMPULSE RESPONSE OF RAISED COSINE FILTER AIM: To Design an FIR Raised Cosine Filter and to plot its Magnitude, Phase and Impulse responses using MATLAB. EQUIPMENT AND SOFTWARE: Personal Computer loaded with MATLAB 7.1 OPERATING SYSTEM:
Windows XP
THEORY:
The ideal raised cosine filter frequency response consists of unity gain at low frequencies, a raised cosine function in the middle, and total attenuation at high frequencies. The width of the middle frequencies are defined by the roll off factor constant Alpha, (0<Altpha<=1). In Filter Solutions, the pass band frequency is defined as the 50% signal attenuation point. The group delay must remain constant at least out to 15 to 20 dB of attenuation. When the pass band frequency of a raised cosine filter is set to half the data rate, then the impulse response Nyquist's first criteria is satisfied in that the impulse response is zero for T = NTs, where N is an integer, and T is the data period. Filter Solutions provides analog, IIR and FIR raised cosine filters. FIR filters are the most accurate and are best to use. However, if it is not possible to use an FIR filter, analog filters may approximate the raised cosine response. The higher the order of the filter, the greater the raised cosine approximation. High order raised cosine filters also produce longer time delays. The lower alpha values use less bandwidth, however, they also produce more ISI due to element value errors and design imperfections. Mathematically, the frequency response may be written as:
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 order delay = filtorder/(Fs*2); % Group delay (# of input samples) rolloff = 0.25; % Rolloff factor of filter rcfilter = 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
-20
Magnitude (dB)
-40
-60
-80
-100
-120
0.1
0.2
0.8
0.9
Phase Response 0
-200
-400
Phase (degrees)
-600
-800
-1000
-1200
0.1
0.2
0.8
0.9
0.8
Amplitude
0.6
0.4
0.2
-0.2
10
15
20 Samples
25
30
35
40
RESULT: The Impulse Response of a Raised Cosine Filter was plotted using fvtool in MATLAB.
Basic simulation lab 17. WIENER-KHINCHIN THEORM AIM: 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 and sometimes as the WienerKhinchinEinstein theorem or the KhinchinKolmogorov theorem) states that the power spectral density of a wide-sense-stationary random process is the 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 realvalued. 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 frequency domain.
% calculate autocorrelations using Wiener-Khinchin theorem e=[e 0.*e]; ev=fft(e); ee=ifft(conj(ev).*ev); ee=ee(1:end/2);
ee(1)
% zero padding
ee=ee/Ne;
% scaling amplitude
10
20
30
40
50
60
70
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 noise k=length(x) y=fft(x,k); %fft of random process pyy=y.*conj(y)/k; % auto correlation f=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 object psd(h,x,'fs',fs) figure(3) h=spectrum.periodogram %instantiate a periodogram object to calculate psd psd(h,x,'fs',fs);
100
80
60
40
20
100
200
300
400
700
800
900
1000
Power/frequency (dB/Hz)
50
100
150
350
400
450
500
-10
Power/frequency (dB/Hz)
-20
-30
-40
-50
-60
50
100
150
350
400
450
500
RESULT: Calculation of Auto-correlation function using Weiner-Khinchin theorm was verified using MATLAB.
Basic simulation lab 18. WSS OF A RANDOM PROCESS AIM: 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 RXX (). 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, RXX (t, t + ).
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 Calculation 1) 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 sense stationary. 2) Consider the random process X(t)=A cos(0t+) Where is real-valued random variable and is uniformly distributed over [0, 2]. Check if the process is wide sense stationary.
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.