Electrical Engineer

Friday, April 8, 2011

MAT LAB CODING


Generation of a Unit Sample Sequence
In Put Out Put
clf;
n=-10:20;
%Generate a vector from -10 to 20
% Generate the unit sample sequence
% Plot the unit sample sequence
u=[zeros(1,10) 1 zeros(1,20)];
stem(n,u);                     
xlabel('Time index n');ylabel('Amplitude');
title('Unit Sample Sequence');
axis([-10 20 0 1.2]);

Out Put






Generation of a complex exponential sequence
Input 
clf;
c=-(1/12)+(pi/6)*i;
K=2;
n=0:40;
x=K*exp(c*n);
subplot(2,1,2);
stem(n,real(x));
xlabel('Time index n');
ylabel('Amplitude');
title('Real part');
subplot(2,1,1);
stem(n,imag(x));
xlabel('Time index n');
ylabel('Amplitude');
title('Imaginary part');


 Output






Generation of a real exponential sequence
Input
clf;
n=0:25;
a=1.2;  
K=0.2;
x=K*a.^n;
stem(n,x);
xlabel('Time index n');
ylabel('Amplitude');

Output  


 

Generation of a sinusoidal sequence
Input 
n=0:40;
f=0.1;         
phase=0;           
A=2;           
arg=2*pi*f*n-phase;
x=A*cos(arg);
clf;                % Clear old graph
stem(n,x);          % Plot the generated sequence
axis([0 50 -3 2]);
grid;
title('Sinusoidal Sequence');
xlabel('Time index n');
ylabel('Amplitude');
axis;

Output



Study the CT (continuous time) and DT (discrete time) sine signal:

 MATLAB command for continuous time sine signal:

A=4;
a=20*pi;
phi=pi/6;
t=0:.001:1;
sine=A*sin(a*t+phi);
plot(t,sine)

Out Put:

MATLAB command for discrete time sine signal:
Mat Lab Code:
A=1;
omega=2*pi/12;  % angular frequency
n=-10:10;
y=A*sin(omega*n);          
stem(n,y)


Out Put:


Study the CT (continuous time) and DT (discrete time) cosine signal
MATLAB command for continuous time cosine signal:
Mat Lad Code:
A=4;
a=20*pi;
phi=pi/6;
t=0:.001:1;
cosine=A*cos(a*t+phi);
plot(t,cosine)

Out Put:

MATLAB command for discrete time cosine signal:

Mat Lab Code:
A=1;
omega=2*pi/12;  % angular frequency
n=-10:10;
y=A*cos(omega*n);
stem(n,y)

Out Put:



No comments:

Post a Comment