quotes--

The aim of education is the knowledge, not of facts, but of values

Thursday 20 September 2012

Matlab for beginners continue...

Here are some example to understand the discrete function in signal system engineering.....

% Plot unit step sequence , sinusoidal sequence exponential sequence
% to generate a unit step sequence
N= 31;
x1 =  ones(1,N);   % the one give 1 by N matrix of ones
n = 0:1:N-1;
subplot(2,2,1),stem(n,x1);  % stem is use to plot descret point
xlabel('n'),ylabel('x_1(n)');
title('Unit Step Sequence');   % title command give the title of graph
axis([0 30 0 2]);

%sinusoidal sequence
x2= 2*cos(.1*pi*n);
subplot(2,2,2),stem(n,x2);
xlabel('n'),ylabel('x_2(n)');
title('Sinusoidal Sequence');

%Exponetial Sequence
x3= 0.6.^(n);
subplot(2,2,3),stem(n,x3);
xlabel('n'),ylabel('x_3(n)');
title('Exponential Sequence');

% Addition of two sinusoidal sequence
x4 = sin(.5*pi*n)+ sin(.25*pi*n)
subplot(2,2,4),stem(n,x4);
xlabel('n'),ylabel('x_4(n)');
title('Addition of two Sequence');

% plot a typical exponental sequence a^n when 1. 0<a<1 ,2. -1<a<0...
...3. a>1, 4. a<-1
 
clear all;
a= .8
n= -10:1:10;
x1 = a.^n;
subplot(2,2,1),stem(n,x1);
xlabel('n'),ylabel('x_1(n)');

a=-0.8;
x2 = a.^n;
subplot(2,2,2),stem(n,x2);
xlabel('n'),ylabel('x_2(n)');

a=1.15;
x3 = a.^n;
subplot(2,2,3),stem(n,x3);
xlabel('n'),ylabel('x_3(n)');

a= -1.15;
x4 = a.^n;
subplot(2,2,4),stem(n,x4);
xlabel('n'),ylabel('x_4(n)');

%plot impulse , step and ramp signal

clear all;
n = -4:1:4;

% impulse sequence
x1 = [zeros(1,4),1,zeros(1,4)];
subplot(3,1,1),stem(n,x1);
xlabel('n'),ylabel('x_1(n)');
title('Unit Impulse sequence');

%unit step sequence
x2 = [zeros(1,4),ones(1,5)];
subplot(3,1,2),stem(n,x2);
xlabel('n'),ylabel('x_2(n)');
title('Unit step sequence');

%unit ramp
n1= 0:1:10;
x3=n1;
subplot(3,1,3),stem(n1,x3);
xlabel('n'),ylabel('x_3(n)');
title('Unit ramp sequence');

The MATLAB file is avaliable at ELECTRODATA

DOWNLAOD




No comments:

Post a Comment