Friday, February 10, 2012

List Of Basic Simulation Mat Lab Programs 01 Basic operations on Matrices 02 Generation Of Various Signals and Sequence(periodic and aperiodic ) 03 Operations on signals and sequence 04 Even and Odd parts of signal and sequence 05 Convolution Between Signals and Sequences 06 Auto correlation & Cross correlation between signals & sequences 07 Computation of Unit sample, Unit step response of LTI system 08 Reconstruction of Periodic Signal by its Fourier Series 09 Computation of Mean, Mean square value & skew kurtosis and PSD 10 Fourier Transform (Magnitude and Phase Spectrum) 11 Locating Zeros and Poles on S-Plane and Z-Plane 12 Sampling Theorem 13 Removal of noise by Auto correlation / Cross Correlation 14 Impulse response of a raised cosine filter



S.No.
List Of Basic Simulation Mat Lab Programs 
01
Basic operations on Matrices
02
Generation Of Various Signals and Sequence(periodic and aperiodic )
03
Operations on signals and sequence
04
Even and Odd parts of signal and sequence
05
Convolution Between Signals and Sequences
06
Auto correlation & Cross correlation between signals & sequences
07
Computation of Unit sample, Unit step response of LTI system
08
Reconstruction of  Periodic Signal by its Fourier Series
09
Computation of Mean, Mean square value &  skew kurtosis and PSD
10
Fourier Transform (Magnitude and Phase Spectrum)
11
Locating Zeros and Poles on S-Plane and Z-Plane
12
Sampling Theorem
13
Removal of noise by Auto correlation / Cross Correlation
14
Impulse response of a raised cosine filter





Experiment No: 01                                            Date:
Basic operations on Matrices
What Is MATLAB?
MATLAB® is a high-performance language for technical computing. It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include Math and computation Algorithm development Data acquisition Modeling, simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building.

MATLAB is an interactive system whose basic data element is an array that does not require dimensioning. This allows you to solve many technical computing problems, especially those with matrix and vector formulations, in a fraction of the time it would take to write a program in a scalar noninteractive language such as C or Fortran.

The name MATLAB stands for matrix laboratory. MATLAB was originally written to provide easy access to matrix software developed by the LINPACK and EISPACK projects. Today, MATLAB engines incorporate the LAPACK and BLAS libraries, embedding the state of the art in software for matrix computation.

MATLAB has evolved over a period of years with input from many users. In university environments, it is the standard instructional tool for introductory and advanced courses in mathematics, engineering, and science. In industry, MATLAB is the tool of choice for high-productivity research, development, and analysis.

MATLAB features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others.

Basic Matrix Operations:
This is a demonstration of some aspects of the MATLAB language.

First, let's create a simple vector with 9 elements called a.
>>a = [1 2 3 4 6 4 3 4 5]     [Enter]
a =
     1     2     3     4     6     4     3     4     5
Now let's add 2 to each element of our vector, a, and store the result in a new vector.
Notice how MATLAB requires no special handling of vector or matrix math.
>>b = a + 2
b =
     3     4     5     6     8     6     5     6     7

Creating a matrix is as easy as making a vector, using semicolons (;) to separate the rows of a matrix.
>>A = [1 2 0; 2 5 -1; 4 10 -1]

A =
     1     2     0
     2     5    -1
     4    10    -1
We can easily find the transpose of the matrix A.
>>B = A'
B =

     1     2     4
     2     5    10
     0    -1    -1
Now let's multiply these two matrices together.

Note again that MATLAB doesn't require you to deal with matrices as a collection of numbers. MATLAB knows when you are dealing with matrices and adjusts your calculations accordingly.
>>C = A * B
C =
     5    12    24
    12    30    59
    24    59   117
Instead of doing a matrix multiply, we can multiply the corresponding elements of two matrices or vectors using the .* operator.
>>C = A .* B

C =
     1     4     0
     4    25   -10
     0   -10     1

Let's find the inverse of a matrix ...
>>X = inv(A)

X =
     5     2    -2
    -2    -1     1
     0    -2     1

... and then illustrate the fact that a matrix times its inverse is the identity matrix.
>>I = inv(A) * A
I =
     1     0     0
     0     1     0
     0     0     1
MATLAB has functions for nearly every type of common matrix calculation.
There are functions to obtain eigenvalues ...
>>eig(A)
ans =
    3.7321
    0.2679
    1.0000

The "poly" function generates a vector containing the coefficients of the characteristic polynomial.
The characteristic polynomial of a matrix A is
>>p = round(poly(A))

p =
     1    -5     5    -1
We can easily find the roots of a polynomial using the roots function.

These are actually the eigenvalues of the original matrix.
>>roots(p)
ans =
    3.7321
    1.0000
    0.2679

MATLAB has many applications beyond just matrix computation.
To convolve two vectors ...
>>q = conv(p,p)

q =
     1   -10    35   -52    35   -10     1

>>r = conv(p,q)
r =
     1   -15    90  -278   480  -480   278   -90    15    -1

Mathematical Functions
MATLAB contains a set of built-in mathematical functions. All of these functions are applied to arrays on an element by element basis.  Thus, they return an array having the same size as the input array with elements all modified in the same way.  We have already defined and used five of the functions.  These are
sqrt - square root
real - complex number real part
imag - complex number imaginary part
abs - complex number magnitude
angle - complex number angle
If a number is real, then abs produces the absolute value of the number.  Other available mathematical functions that are of interest to us in signal and system analysis include
exp - exponential base e
log  - logarithm base e
log 10 - logarithm base 10
sin - sine
cos - cosine
tan - tangent
asin - arcsine
acos - arccosine
atan - arctangent
atan2 - four quadrant arctangent
round - round to nearest integer
[The trigonometric functions all apply to angles expressed in radians.]
Mathematical Expressions
We can combine arithmetic operations, 0-1 arrays generated by logical operations, and mathematical functions into mathematical expressions.  Often, these expressions take the form of equations, although they may also be used in flow control statements.  The
arithmetic operations follow the usual precedence rules.  Many mathematical expressions require parentheses to construct the desired sequence of operations within the precedence rules.
>>   t=0.1;  x=2^t*sqrt(t) - sin(2*t)/3
x =
  0.2727
>>   y=2^(t*sqrt(t)) - sin(2*t)/3
y =
  0.9559
We can evaluate a mathematical expression for a set of independent variable values by expressing the independent variable as a one-dimensional array (vector) and using array operations.
>>   f=0:2:4;  w=2*pi*f;
>>   X=(3 - j*0.1*w)./(1.5+j*0.2*w)
X =
  2.0000 0.1566 - 1.1002i   -0.2956 - 0. 6850i
One important use of a 0-1 array for signal and system analysis is in the representation of a piecewise defined signal with a mathematical expression.
>>   t=-0.5:0.5:2.5;
>>   x=(t+1).*(t>=0&t<1)+2*(t>=1&t<=2)
x =
  0   1.0000   1.5000   2.0000   2.0000    2.0000   0
The notation .* is required for the first multiplication since we want element by element
multiplication of the two like-sized, one-dimensional arrays.  We can use just * for the
second multiplication since it is a constant times an array.
Experiment No: 02                                         Date:
Generation Of Various Signals and Sequence
( periodic and aperiodic)
AIM: To write a MATLAB program to generate the standard discrete time signals like unit impulse, unit step, unit ramp signals, discrete time signals, sinusoidal signals and exponential signals.
Program To Plot Standard Signals:

%Create a time base vector
t = [0:0.1:2];% Create a signal as a function of time
x = sin(pi*t/2);
subplot(3,3,1);
plot(t,x);

%Non periodic Signals
t = linspace(0,1,11);
%Step:
y = ones(1,11);
subplot(3,3,2);
stem(y);
axis([-1 6 0 2]);
% Impulse:
y = [1 zeros(1,10)];
subplot(3,3,3);
stem(y);
axis([-1 6 0 2]);
% Ramp:
y = 2*t;
subplot(3,3,4);
plot(y);
axis([-1 6 0 2])
%Useful Matlab functions  step, impulse, gen signal
%Step function:
fs = 10;
ts = [0:1/fs:5 5:1/fs:10];
x = [zeros(1,51) ones(1,51)];
subplot(3,3,5);
stairs(ts,x);
%Impulse function with width w:fs = 10;
w = 0.1;
ts = [-1:1/fs:-w 0 w:1/fs:1];
x = [zeros(1,10) 1 zeros(1,10)];
subplot(3,3,6);
plot(ts,x);
%Sinusoids
%Sinusoid parameters
%Amplitude, A
%Frequency, f
%Phase shift, j
%Vertical offset, B
%The general form of a sine wave is
%y = Asin(2 ft + j) + B
%Example: generate a sine wave given the following speculations:
%A = 5
%f = 2 Hz
%PS=π/8 radians
t = linspace(0,1,1001);
A = 5;
f = 2;
PS = pi/8;
sinewave = A*sin(2*pi*f*t + PS);
subplot(3,3,7);
plot(t, sinewave);
%Square Waves
%Square wave generation is like sine wave generation, but you specify a duty cycle, which is the percentage of the time over one period that the amplitude is high.
%Example:
% duty cycle is 75, frequency is 4 Hz.
t = linspace(0,1,1001);
sqw2 = square(2*pi*4*t,75);
subplot(3,3,8);
plot(t,sqw2);
axis([-0.1 1.1 -1.1 1.1]);
%Sawtooth Waves
%Sawtooth waves are like square waves except that instead of specifying a duty cycle, you specify the location of the peak of the sawtooth.
%Example:
%peak is halfway through the period ,frequency is 3 Hz.
t = linspace(0,1,1001);
saw2 = sawtooth(2*pi*3*t,1/2);
subplot(3,3,9);
plot(t,saw2);
RESULT
Figure :Periodic and aperiodic signals
Questions:
1.   Define the different signals like step, ramp, impulse, sinusoidal and exponential.
2.   What is the difference between analog signals and digital signals?
3.   Express the ramp signal in terms of step.
4.   Draw the different signal waveforms.
5.    t=-25:0.1:25; a=1; b=((sin(t))./t); x=b.*(t<0)+a.*(t==0)+b.*(t>0); plot(t,x);
What will be the plotted graph Name?

Experiment No: 03                                                    Date:

Operations on signals and sequence

AIM: To perform various operations on signals and sequence such as addition, multiplication, scaling, shifting and folding computation of energy and average power using MATLAB Code.

Program demonstrating Basic Signal Manipulation:

N=128;
f1=150;
f2=450;
f3=1500;
fs=8000;
n=0:N-1;
x1=sin(2*pi*(f1/fs)*n);
x2=(1/3)*sin(2*pi*(f2/fs)*n);
x3=sin(2*pi*(f3/fs)*n);
figure(1);
subplot(1,1,1);
subplot(2,3,1);
plot(n,x1);
grid;
title('Signal, x1(n)');
subplot(2,3,2);
plot(n,x2);
grid;
title('Signal, x2(n)');
subplot(2,3,3);
plot(n,x3);
grid;
title('Signal, x3(n)');
% Signal Delay
x1d=[zeros(1,20), x1(1:N-20)];
subplot(2,3,4);
plot(n,x1d);
grid;
title('Delayed x(n), [x1(n-20)]');
% Signal Addition
xadd=x1+x2;
subplot(2,3,5);
plot(n,xadd);
grid;
title('x1(n)+x2(n)');
% Signal Multiplication
xmult=x1.*x3;
subplot(2,3,6);
plot(xmult);
grid;
title('x1*x3');












RESULTS:




















Figure : Basic signal Manipulation with respect to time
Questions:
1.   What are the various mathematical operations on signals?
2.   Define the various mathematical operations like addition, multiplication, division and average with respect to signals.
3.   Define scaling of a signal.
4.   What is the difference between frequency scaling and amplitude scaling?




Experiment No:04                                                                  Date:

Even and Odd parts of signal or sequence

AIM: To write a MATLAB code for finding the
a)    Even and Odd parts of signal or sequence
b)   Real and imaginary parts of signal.
% Finding the even and odd part of the signal x(n)=0.8^n
n=-5:  1:  5;   %specify the range of n
A=0.8;
x1=A.^(n);   %generate the given signal
x2=A.^(-n);   %generate the folded signal
if(x2==x1)
  disp('The given signal is even signal');
else if (x2==(-x1))
disp('The given signal is odd signal');
else
disp('The given signal is neither even nor odd signal');
end
end
xe=(x1+x2)/2;    %compute even part
xo=(x1-x2)/2;    %compute odd part
subplot(2,2,1);stem(n,x1);
xlabel('n');ylabel('x1(n)');title('signal  x(n)');
subplot(2,2,2);stem(n,x2);
xlabel('n');ylabel('x2(n)');title('signal  x(-n)');
subplot(2,2,3);stem(n,xe);
xlabel('n');ylabel('xe(n)');title('even part of  x(n)');
subplot(2,2,4);stem(n,xo);
xlabel('n');ylabel('xo(n)');title('odd part of x(n)');

RESULT:














Figure : Even and odd parts of given signal













B) Finding Real and imaginary parts of signal.
t = [-0.5:0.01:0.5];
w=20;
y = exp(i*pi*w*t/2);

a=real(y);
subplot(2,2,1);
plot(t,a);
b=imag(y);
subplot(2,2,2);
plot(t,b);
c=abs(y);
subplot(2,2,3);
plot(t,c);
d=angle(y);
subplot(2,2,4);
plot(t,d);
                Figure: Real and imaginary parts of signal
Questions:
1.   Define the Even and Odd Signals.
2.   Give the expressions for the Even and Odd signals.
3.   What is the real and imaginary part of the signal?

Experiment No: 05                                                        Date:
(A)Convolution Between Signals

AIM: To write a MATLAB program to perform convolution of the following two signals.
X1(t)   =1;   0<t<2                    
x2(t)   =1;     0<t<1
                   =-1;    1<t<2
Program:
tmin=0; tmax=4; dt=0.01;
t=tmin:dt:tmax;      %set time vector for given signal
x1=1.*(t>=0&t<=2);   %generate signal x1(t)
xa=1;
xb=-1;
x2=xa.*(t>=0&t<=1)+ xb.*(t>=1&t<=2);
                           % generate signal x2(t)
x3=conv(x1,x2);   % perform convolution of xl(t) & x2(t)
n3=length(x3);
t1=0:1:n3-1; %set time vector for signal x3(t)
subplot(3,1,1);plot(t,x1);
xlabel(‘t’);ylabel(‘x1(t)’);title(‘signal x1(t)’);
subplot(3,1,2);plot(t,x2);
xlabel(‘t’);ylabel(‘x2(t)’);title(‘signal x2(t)’);
subplot(3,1,3);plot(t1,x3);
xlabel(‘t/dt’);ylabel(‘x3(t)/dt’);title(‘signal, x3(t)=x1(t)*x2(t)’);

RESULTS:
 













Figure :Convolution between  CT signals










(B)Convolution Between Sequences
AIM: To write a MATLAB program to perform convolution of the following two discrete time signals.
x1(n)=1;  1<n<10
x2(n)=1;       2<n<10
Program to perform convolution of two signals:
clear all
n=0:1:15;                 %specify range of n
x1=1.*(n>=1 & n<=10) ;    %generate signal x1(n)
x2=1.*(n>=2 & n<=10);     % generate signal x2(n)
N1=length(x1);
N2=length(x2);
x3=conv(x1,x2);    % convolution of signals x1(n)and x2(n)
n1=0:  1:  N1+N2-2;     %specify range of  n for x3(n)
subplot(3,1,1);stem(n,x1);
xlabel('n');ylabel('x1(n)');
title('signal x1(n)');
subplot(3,1,2);stem(n,x2);
xlabel('n');ylabel('x2(n)');
title('signal x2(n)');
subplot(3,1,3);stem(n1,x3);
xlabel('n');ylabel('x3(n)');                                  
title('signal , x3(n)=x1(n)*x2(n)');


RESULT:












Figure :Convolution between DT signals


Questions:
  1. Define convolution.
  2. What is the difference between sequence and signal?






Experiment No: 06                                                    Date:
Auto correlation and Cross correlation between
signals and sequences

AIM: To find Auto correlation and Cross correlation between signals and sequences using MATLAB Code.

Program for auto correlation:

N=1024; % Number of samples
f1=1; % Frequency of the sine wave
FS=200; % Sampling Frequency
n=0:N-1; % Sample index numbers
x=sin(2*pi*f1*n/FS); % Generate the signal, x(n)
t=[1:N]*(1/FS); % Prepare a time axis
subplot(2,1,1); % Prepare the figure
plot(t,x); % Plot x(n)
title('Sinwave of frequency 1000Hz [FS=8000Hz]');
xlabel('Time, [s]');
ylabel('Amplitude');
grid;
Rxx=xcorr(x); % Estimate its autocorrelation
subplot(2,1,2); % Prepare the figure
plot(Rxx); % Plot the autocorrelation
grid;
title('Autocorrelation function of the sinewave');
xlable('lags');
ylabel('Autocorrelation');




RESULT:
























Figure :Auto correlation function of the Sine wave




Program for cross correlation:

N=1024; % Number of samples to generate
f=1; % Frequency of the sinewave
FS=200; % Sampling frequency
n=0:N-1; % Sampling index
x=sin(2*pi*f1*n/FS); % Generate x(n)
y=x+10*randn(1,N); % Generate y(n)
subplot(3,1,1);
plot(x);
title(‘Pure Sinewave’);
grid;
subplot(3,1,2);plot(y);
title(‘y(n), Pure Sinewave + Noise’);
grid;
Rxy=xcorr(x,y); % Estimate the cross correlation
subplot(3,1,3);
plot(Rxy);
title(‘Cross correlation Rxy’);
grid;










RESULT:




















Figure : Cross correlation function of sine wave and Noise

Questions:

1.   Define auto correlation.
2.   Define cross correlation.
3.   What is the difference between auto and cross correlations?












Experiment No: 07                                                    Date:
Computation of Unit sample, Unit step and sinusoidal response of LTI system
AIM: Write a MATLAB program to compute and sketch the impulse response of a discrete time system governed by the following transfer function,
H(Z)=1/(1-0.8Z^-1+0.16 Z^-2)
Program to find 'impulse response of a discrete time System:
clear all
syms    z     n
H=1/(1-0.8*(z^(-1))+0.16*(z^(-2)));
disp('impulse response   h(n) is');
h=iztrans(H) ;     %compute impulse response
simplify(h)
N=15;
b=[0  0  1];       %numerator coefficients
a=[1   -0.8   0.16];   %denominator coefficients
[H,n]=impz(b,a,N); %compute N samples of impulse response
Stem(n,H);          %sketch impulse response
xlabel('n');
ylabel('h(n)');
title('impulse response of a DT System');





RESULT:













Figure:Impulse Response of a DT system









AIM: To write a  MATLAB program to find  the step response of the first and second order LTI systems  governed by the following transfer functions,
H(s)=1/(s+2)  and    H(s)=1/(s2+2.5s+25) .

Program to find the step response of I and  II order systems:
syms   s  complex;
H1=1/(s+2);
disp('step response of first order system is');
h1= ilaplace(H1);
simplify(h1)
H2=1/(s^2+2.5*s+25);
disp('step response of second order system is');
h2= ilaplace(H2);
simplify(h2)
s=tf('s');
H1=1/(s+2);
H2=1/(s^2+2.5*s+25);
t1=0: 0.0005 :5;  %set a time vector
s1=step(H1,t1);   % step response of first order system
s2=step(H2,t1);   % step response of second order system
subplot(2,1,1);plot(t1,s1);
xlabel('Time in seconds');ylabel('s1(t)');
title('step response of first order system');
subplot(2,1,2);plot(t1,s2);
xlabel('Time in seconds');
ylabel('s2(t)');
title('step response of second order system');        



RESULT:















Figure : Unit Step Response for given I and II order systems




Questions:
  1. Define impulse signal and step signal.
  2. What is impulse response and step response?
  3. What are the time response specifications?





Experiment No: 08                                                    Date:
Reconstruction of  Periodic Signal by its Fourier Series

AIM: Write a MATLAB program to reconstruct the following periodic signal represented by its fourier series , by considering only 3,5 and 59 terms.
x(t)=(1/2)+ bn sinnΩ0 . where bn=2/n; Ω0=2nF; F=1
Program:
syms   t   real;
N=input('Enter number of signals to reconstruct');
n_har=input('enter number of harmonics in each signal as array');
t=-1: 0.002:1;
omega_o=2*pi;
for k=1:N
n=[  ];
n=[1:2:n_har(k)];
b_n=2./(pi*n);
L_n=length(n);
x=0.5+b_n*sin(omega_o*n'*t);
subplot(N,1,k);
plot(t,x);
xlabel('t');
ylabel('recons signal');
axis( [-1   1   -0.5  1.5]);
text(.55, 1.0,['no.of har.=',num2str(n_har(k))]);
end




RESULT:
Enter number of signals to reconstruct :  3
enter number of harmonics in each signal as array[3 5 59]




Figure : Gibbs phenomenon
Questions:
  1. What is fourier series?
  2. Define periodic and non periodic signals.
  3. What is the difference between FS and DFS?




Experiment No: 09                                                    Date:

Computation of Mean, Mean square value & skew kurtosis and PSD

AIM: Write a MATLAB program on Generation of Gaussian noise (real and Complex), Computation of its Mean, Mean square value and its skew kurtosis and PSD, probability Distribution function.
Program
%Use the randn function in Matlab to produce a large set (O(106)) of normally distributed random numbers. Plot the pdf of these numbers. Compute the ?rst four moments of the empirical pdf. What are the skewness and kurtosis?
 %Here's code to carry out this calculation.
%generate random data
%use randn to make normally distributed data
x=randn(1.e6,1);

% make the pdf
[a,b]=hist(x,-5:.1:5);
plot(b,a/.1/sum(a)); xlabel('x'); ylabel('pdf');
% compute moments using Matlab moment function.
Moments=[moment(x,1) moment(x,2) moment(x,3) moment(x,4)]
 % alternatively compute moments using mean or sum function.
Moments=[mean(x) sum((x-mean(x)).^2)/(length(x)-1) ...
sum((x-mean(x)).^3)/(length(x)-1) sum((x-mean(x)).^4)/(length(x)-1)]

% compute skewness and kurtosis using Matlab functions
Skewness=[skewness(x)]
Kurtosis=[kurtosis(x)]

% compute skewness and kurtosis using mean, variance, sum
Skewness=[sum((x-mean(x)).^3)/var(x)^1.5]
Kurtosis=[sum((x-mean(x)).^4)/var(x)^2]

%The resulting pdf is shown in Figure 1.
%The ?rst moment (the mean) is approximately zero, the second moment (the variance)
%is one, the third moment is approximately zero, and the fourth moment should be about 3.
%Skewness is zero; kurtosis is 3. These results agree with expectations for a normal distribution.

Moments =
         0    0.9979   -0.0001    2.9863

Moments =
    0.0005    0.9979   -0.0001    2.9863

Skewness =
 -8.2605e-005

Kurtosis =
    2.9988

Skewness =
  -82.6047

Kurtosis =
  2.9988e+006


POWER SPECTRAL DENSITY
Fs = 100;
t = 0:1/Fs:10;
y = sin(2*pi*15*t) + sin(2*pi*30*t);
nfft = 512;
Y = fft(y,nfft);
f = Fs*(0:nfft-1)/nfft;
Power = Y.*conj(Y)/nfft;
plot(f,Power)
title('Periodogram')
figure
ryy = xcorr(y,y);
Ryy = fft(ryy,512);
plot(f, abs(Ryy));
title('DFT of Autocorrelation');

Result
Experiment No: 10                                                    Date:

Fourier Transform (Magnitude and Phase Spectrum)

AIM: Write a MATLAB program to plot Fourier Transform (Magnitude and Phase Spectrum
Program
t=[0:0.025:50];
w=logspace(-3,3,601);
h=5.*exp(-2.*t);
numft=(5);
denft=(2+1i*w);
magft=(abs(numft)./abs(denft));
phft=(unwrap(angle(numft))-unwrap(angle(denft)));
figure(1);
plot(t,h),grid;
xlabel('Time(sec)'),ylabel('Amplitude');
title('Impulse Response of h(t)');
figure(2),semilogx(w,20.*log10(magft)),grid;
xlabel('Frequency(Hz)'),ylabel('Magnitude(dB)');
title('FT Magnitude Response of H(w)');
figure(3),semilogx(w,phft),grid;
xlabel('Frequency(Hz)'),ylabel('Phase Angle(Deg) ');
title('FT Phase Angle Response of H(w)');

Result


Experiment No: 11                                            Date:
Locating Zeros and Poles on S-Plane and Z-Plane

AIM: To write a MATLAB program for finding residues and poles of s-domain transfer function
         
Program:
clc;
close all;
clear all;
disp('Enter the transfer function of the original system');
N=input('Enter the co efficients of the numarator:');
D=input('Enter the co efficients of the denominator:');
disp('The transfer function of the original system:');
G=tf(N,D);
ltiview(G);











RESULT:
Enter the transfer function of the original system
Enter the co efficients of the numarator:              [1 2 3]

Enter the co efficients of the denominator:          [2 3 3]
The transfer function of the original system:


Figure : Pole-zero map for s-domain transfer function
Questions:
1.   H = tf([2 5 1],[1 2 3]); sgrid; pzmap(H);grid on;
Plot the poles and zeros of the continuous-time system

2.   z = zpk('z',0.1); H = (z+.1)*(z+.2)/(z^2+.6*z+.09);
What will be the Result?.Check it

       
AIM: To write a MATLAB program for finding residues and poles of z-domain signal is given below
                              (Z^2+0.8Z+0.8)/(Z^2+0.49),
 And  sketch the pole zero plot.

Program
syms z
num_coeff=[1 0.8 0.8];
disp('Roots of numerator polynomial Z^2+0.8Z+0.8 are');
zeros=roots(num_coeff)

den_coeff=[1 0 0.49];
disp('Roots of denominator polynomial Z^2+0.49 are');
poles=roots(den_coeff)
H=tf('z');
Ts=0.1;

a=tf([num_coeff], [den_coeff], Ts);
zgrid on;
pzmap(a);   %pole -zero plot
Roots of numerator polynomial Z^2+0.8Z+0.8 are

zeros =

  -0.4000 + 0.8000i
  -0.4000 - 0.8000i

Roots of denominator polynomial Z^2+0.49 are

poles =

        0 + 0.7000i
        0 - 0.7000i


RESULT:

Figure : Pole- Zero map for Z-domain signal
















Experiment No: 12                                                 Date:

Sampling Theorem


AIM: To verify the Sampling Theorem

Program
clear all
t=-100:.01:100;
fm=input('Enter the modulating signal frequency:');%give value .02
x=cos(2*pi*t*fm);
subplot(2,2,1),plot(t,x);
xlabel('Time in sec');ylabel('x(t)');
title('continous time signal');
fs1=fm;%under sampling frequency
n=-2:2;
x1=cos(2*pi*fm*n/fs1);
subplot(2,2,2);stem(n,x1);
hold on
subplot(2,2,2);plot(n,x1,':')
title('Discrete time signal x(n) with fs<2fm');
xlabel('n');ylabel('x(n)');
fs2=2*fm;%normal sampling
n1=-4:4;
x2=cos(2*pi*fm*n1/fs2);
subplot(2,2,3);stem(n1,x2);
xlabel('n1');ylabel('x(n)');
n2=-50:50;
fs3=24*fm;%over sampling
x3=cos(2*pi*fm*n2/fs3);
subplot(2,2,4);stem(n2,x3);
hold on
title('Discrete time signal x(n) with fs=2fm');
subplot(2,2,4);plot(n2,x3,':')
xlabel('n2');ylabel('x(n)');
title('Discrete time signal x(n) with fs>2fm');




Questions:
1.   Define sampling theorem in both frequency and time domain.
2.   What is the sampling rate?
3.   What is the multiple sampling rate?
4.   What is  the Nyquist Sampling Rate?

Experiment No: 13                                            Date:
Removal of noise by Auto correlation / Cross Correlation

AIM: Removal  of noise by Auto / Cross Correlation in a given signal corrupted by noise by using MATLAB Code.

Program
% AutoCorrelation of White Noise
% Loops are used in this program for easier portability to
% C or assembly code.
%
%************************************************************
% N = Length of Time Domain Signal

N = 512;

%************************************************************
% Create an index matrix for graphing:
%************************************************************
for n = 1: 1: N;
            index(n) = n;
end

%************************************************************
% Create an expanded index matrix from -N to N for graphing:
%************************************************************
index_expanded = 1:(2*N - 1);

for n = 1: 1: (N - 1);
            index_expanded(n) = -(index(N - n));
end
index_expanded(N) = 0;
for n = (N + 1): 1: (2*N - 1);
            index_expanded(n) = index(n - N);
end

%************************************************************
%  Generate the flat +- 0.1 white noise:
%************************************************************

w_2 = 1:N;
w_2 = 0.1*rand(1,N);
w_2 = w_2 - mean(w_2);

%************************************************************
% Compute 0.1 white noise Autocorrelation:
%************************************************************

r_xx_w_2 = 1:N;
for m = 1: 1: N;
F = 0;
            for k = 1: 1: (N+1-m);
                        F = F + w_2(k)*w_2(k-1+m);
            end
            r_xx_w_2(m) = F/(N+1-m);
end

%************************************************************
% Create an expanded 0.1 white noise Autocorrelation Function
% from -N to N for graphing purposes:
%************************************************************

r_xx_w__expanded = 1:(2*N - 1);
for m = 1: 1: N;
            r_xx_w_2_expanded(m) = r_xx_w_2(N - m + 1);
end
for m = N: 1: (2*N - 1);
            r_xx_w_2_expanded(m) = r_xx_w_2(m + 1 - N);
end

%************************************************************
% Plot the Results
%************************************************************

figure
plot(index_expanded,r_xx_w_2_expanded)
title(['Auto Correlation Function of 0.1 w.n Input'])

RESULT:
Figure : Auto Correlation function of 0.1 White noise input

Questions:
1.   Define noise.
2.   How the signals are affected by the noise?
3.   What are the differences between random noise and white noise?

Experiment No: 14                                                Date:
Impulse response of a raised cosine filter

AIM: write a MATLAB code to find the Impulse Response of a Raised Cosine Filter.

Program:
% Script for plotting the time domain and frequency domain representation
% of raised cosine filters for various values of alpha
clear all
fs = 10;
% defining the sinc filter
sincNum = sin(pi*[-fs:1/fs:fs]); % numerator of the sinc function
sincDen = (pi*[-fs:1/fs:fs]); % denominator of the sinc function
sincDenZero = find(abs(sincDen) < 10^-10);
sincOp = sincNum./sincDen;
sincOp(sincDenZero) = 1; % sin(pix/(pix) =1 for x =0

alpha = 0;
cosNum = cos(alpha*pi*[-fs:1/fs:fs]);
cosDen = (1-(2*alpha*[-fs:1/fs:fs]).^2);
cosDenZero = find(abs(cosDen)<10^-10);
cosOp = cosNum./cosDen;
cosOp(cosDenZero) = pi/4;
gt_alpha0 = sincOp.*cosOp;
GF_alpha0 = fft(gt_alpha0,1024);

close all
figure
plot([-fs:1/fs:fs],[gt_alpha0],'b','LineWidth',2)

grid on
xlabel('time, t')
ylabel('amplitude, g(t)')
title('Time domain waveform of raised cosine pulse shaping filters')

figure
plot([-512:511]/1024*fs, abs(fftshift(GF_alpha0)),'b','LineWidth',2);
axis([-2 2 0 14])
grid on
xlabel('frequency, f')
ylabel('amplitude, |G(f)|')
title('Frequency domain representation of raised cosine pulse shaping filters')
 

No comments:

Post a Comment

Search This Blog