**Basic Waveform Generation Using MATLAB**

** **

**Unit Impulse Function**

Algorithm

- Get the length of the function to be generated
- Make the impulse function =1 when variable n=0
- 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**

- Get the length of the function to be generated
- Use
**MATLAB**function ones(1,length of sequence) to produce a step function u(n) - 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**

- Get the length of the function to be generated
- 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**

- Get the length of the function to be generated
- Define e(n) as some exponential by making use of ".^" operator.
- 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**

- Get the length of the function to be generated
- Define the sequence x=2*pi*f*t by taking proper sampling frequency.
- 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)