06 December 2007

Basic Waveform Generation

Basic Waveform Generation Using MATLAB

Unit Impulse Function

Algorithm

  1. Get the length of the function to be generated
  2. Make the impulse function =1 when variable n=0
  3. Make the impulse function =0 elsewhere

Program:

% To generate impulse function

t = -2:1:2

y=[zeros(1,2),ones(1,1),zeros(1,2)];

figure(1);

stem (t,y);

Unit Step Function

Algorithm

  1. Get the length of the function to be generated
  2. Use MATLAB function ones(1,length of sequence) to produce a step function u(n)
  3. Plot the response

Program

% To generate unit step function

N=input ('length of the sequence : ');

u=ones(1,N);

n=0: 1: N-1;

figure(2);

stem (n,u);

Ramp Function

Algorithm

  1. Get the length of the function to be generated
  2. Plot the length of the sequence from 0 to N

Program

% To generate ramp function

r=0:N;

figure(3);

stem(r);

Exponential Function

Algorithm

  1. Get the length of the function to be generated
  2. Define e(n) as some exponential by making use of ".^" operator.
  3. Plot the function

Program

% To generate exponential function

n=0: 1: N-1;

e=0.8 .^(n) ; %defining certain exponential sequence

figure(4);

stem (n,e);


Sinusoidal Function

Algorithm

  1. Get the length of the function to be generated
  2. Define the sequence x=2*pi*f*t by taking proper sampling frequency.
  3. Plot the function

Program

% To generate sinusoidal function

f=input ('Enter the frequency : ');

t=0:0.0005:0.02;

s=sin(2*pi*f*t);

figure(5);

stem (t,s);



No comments:

Post a Comment

Your Comments... (comments are moderated)