Friday 21 December 2012

MatLab Programs - IMPULSE - STEP - SINE - COSINE -TRIANGULAR - SAWTOOTH - EXPONENTIAL SIGNALS GROWING DECAYING -



 MatLab Programs

 
In this post the matlab code for basic DSP signal generation  are available. These are tested and outputs are also added.
  • Impulse signal
  • Step signal (Delayed Step)
  • Sine signal
  • Cosine signal
  • Triangular signal
  • Sawtooth signal
  • Exponential signals growing & decaying



Matlab code for unit impulse signal generation:
clc;
clear all;
close all;
disp('Unit Impulse Signal Generation');
N=input('Enter no of samples: ');
n=-N:1:N;
x=[zeros(1,N),1,zeros(1,N)];
stem(n,x);
xlabel('Sample');
ylabel('Amplitude');
title('Unit Impulse Signal');

In this, the impulse is generated by using ZEROS(x,y) function, which produces an array of size X,Y with all elements as ZERO.

 OUTPUT:


 Matlab code for unit ramp signal generation:

clc;

clear all;
close all;
disp('Unit Ramp Signal Generation');
N=input('Enter no of samples: ');
a=input('      Max Amplitude: ');
n=-N:1:N;
x=a*n/N;
stem(n,x);
xlabel('Sample');
ylabel('Amplitude');
title('Unit Ramp Signal');


  OUTPUT:





 Matlab code for unit step (delayed step) signal generation:

 clc;

clear all;

close all;
disp('Delayed Unit Step Signal Generation');
N=input('Enter no of samples: ');
d=input('Enter  delay  value: ');
n=-N:1:N;
x=[zeros(1,N+d),ones(1,N-d+1)];
stem(n,x);
xlabel('Sample');
ylabel('Amplitude');
title('Delayed Unit Step Signal');
  OUTPUT:



Matlab code for discrete sinusoidal signal generation:
clc;
clear all;
close all;
disp('Sinusoidal Signal generation');
N=input('Enter no of samples: ');
n=0:0.1:N;
x=sin(n);
figure, stem(n,x);
xlabel('Samples');
ylabel('Amplitude');
title('Sinusoidal Signal');
    
The SIN(n) function returns an array which corresponds to sine value of the array ‘n’
 OUTPUT:



Matlab code for discrete cosine signal generation:

clc;
clear all;
close all;
disp('Cosine wave generation');
N=input('Enter no of samples');
n=0:0.1:N;
x=cos(n);
figure, stem(n,x);
xlabel('Samples');
ylabel('Amplitude');
title('Cosine');


The COS(n) function returns an array which corresponds to cosine value of the array ‘n’
 OUTPUT:


Matlab code for  Trinangular or Sawtooth signal generation:


clc;clear all;
n=input('Enter the no samples: ');
x=0:0.1/n:20;

s=sawtooth(x);
t=sawtooth(x,0.5); % width=0.5 for Triangular signal

subplot(2,1,1),
plot(x,s),
xlabel('Time'),
ylabel('Amplitude'),
title('Sawtooth signal');

subplot(2,1,2),
plot(x,t),title('Triangular signal'),
xlabel('Time'),
ylabel('Amplitude');


 OUTPUT:



Matlab code for  exponentially decaying signal generation:


clc;
clear all;
close all;
disp('Exponential decaying signal');
N=input('Enter no of samples: ');

a=1;
t=0:0.1:N;
x=a*exp(-t);
figure,plot(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponentially Decaying Signal');

 OUTPUT:




Matlab code for  exponentially growing signal generation:
 clc;
clear all;
close all;
disp('Exponential growing signal');
N=input('Enter no of samples: ');
a=1;
t=0:0.1:N;
x=a*exp(t);
figure,stem(t,x);
xlabel('Time');
ylabel('Amplitude');
title('Exponentially Decaying Signal');

 OUTPUT:


Viewers  comments are encouraged. 
This helps us to much more.
Thank you!!!


4 comments:

Search Here...