You are on page 1of 9

S.P.

TUSHAR BALAJI
3122 21 3002 114

GENERATION OF DT SEQUENCES
DATE:02/03/2023
EX.NO : 1

Aim:
To write a MATLAB Program to generate the Basic Discrete Time sequences and Random
Sequences
1.Unit Impulse Signal
2.Unit Step Signal
3.Ramp Signal
4.Exponential signal
5.Sinusoidal sequence
6.Cosine wave
7.Sinc Signal
8.Rectangular Pulse
9.Triangular Pulse
10.Random Signal

Software Used:
MATLAB INTERPRETER – R2022 b VERSION

Description:
Elementary signals are those that are basically used to analyse basic systems.
Impulse signal , Unit step signal , sinusoidal signal , exponential signal and ramp signal are some of
the elementary signals. Random Signals are those which are not precisely predictable ; that is , given
the past history of a signal and the amplitude values it has taken on , it is not possible to precisely
predict what particular value it will take on at certain instants in the future.

MATLAB Program:
clear;
clc;
close all;
S.P.TUSHAR BALAJI
3122 21 3002 114

1.Unit Impulse Signal


Code:
n=-3:3;
d_n=n==0;
subplot(3,1,1);
stem(n,d_n);
xlabel('time index');
ylabel('amplitude');
title('Unit Impulse ');

Simulated Graph:

2.Unit step sequence


Code:
u_m=n>=0;
subplot(3,1,2);
stem(n,u_m);
xlabel('time index');
ylabel('amplitude');
title('Unit step sequence');

Simulated Graph:

3.Ramp sequence
Code:
r_t= (n>=0).*n;
subplot(3,1,3)
stem(n,r_t);
xlabel('time');
ylabel('amplitude');
title('Unit ramp sequence');
S.P.TUSHAR BALAJI
3122 21 3002 114
Simulated Graph:

4.Exponential Signals
4.1.Exponential sequence: Case 1 : 0<a<1 a=0.5
Code:
n=-20:1:20;
A=0.95;
x=A.^n;
subplot(2,2,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Exponenetial sequence 1');

Simulated Graph:

4.2.Exponential sequence : case 2 : a>1 a=2


Code:
n=-5:5;
A=2;
x=A.^n;
subplot(2,2,2);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Exponenetial sequence 2');
S.P.TUSHAR BALAJI
3122 21 3002 114
Simulated Graph:

4.3.Exponential sequence : case 3 : -1<a<0 a=-0.95


Code:
n=-20:20;
A=-0.95;
x=A.^n;
subplot(2,2,3);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Exponenetial sequence 3');

Simulated Graph:

4.4.Exponential sequence : case 4 : a<-1


Code:
n=-5:5;
A=-2;
x=A.^n;
subplot(2,2,4);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Exponenetial sequence 4');
S.P.TUSHAR BALAJI
3122 21 3002 114
Simulated Graph:

4.5.Complex Exponential sequence :


Code:
n=-20:20;
alfa=-0.1+0.3j;
x_n=exp(alfa*n);
subplot(4,1,1);
stem(n,real(x_n));
xlabel('Time Samples');
ylabel('Real Part');
subplot(4,1,2);
stem(n,imag(x_n));
xlabel('Time Samples');
ylabel('Imaginary Part');

Simulated Graph:

5.Sinusoidal signal
Code:
n=0:20;
N=20;
f=1/N;
x=sin(2*pi*f*n);
subplot(3,1,1);
stem(n,x);
xlabel('n');
ylabel('sin(n)');
title('sinusoidal sequence');
S.P.TUSHAR BALAJI
3122 21 3002 114
Simulated Graph:

6.Cosine Wave
Code:
n=0:20;
N=20;
f=1/N;
x=cos(2*pi*f*n);
subplot(1,1,1);
stem(n,x,'r');
xlabel('n');
ylabel('sin(n)');
title('cosinusoidal sequence');

Simulated Graph:

7.Sinc function
Code:
n=linspace(-8,8);
y=sinc(n);
subplot(3,1,3);
stem(n,y);
S.P.TUSHAR BALAJI
3122 21 3002 114
xlabel('n');
ylabel('sinc(n)');
title('sinc function');

Simulated Graph:

8.Rectangular pulse
Code:
n=-5:5;
rect_n = n>=-3 & n<=3;
subplot(2,1,1);
stem(n,rect_n,'r');
xlabel('n');
ylabel('rect(n)');
title('Unit rectangular sequence');

Simulated Graph:

9.Triangular pulse
Code:
clc;
close all;
clear;
N=20;
f=1/N;
t=-1:f:1;
x=tripuls(t)
stem(t,x);
xlabel('time');
ylabel('Amplitude');
title('Triangular pulse');
S.P.TUSHAR BALAJI
3122 21 3002 114

Simulated Graph:

10. Random Signal

10.1 Uniform Random Variable Function


Code:
N=1e8;
a=-0.5;
b=0.5;
x=a+(b-a)*rand(1,N);
subplot(2,1,1);
histogram(x);
xlabel(‘time’);
ylabel(‘Amplitude’);
title(‘Uniform Random Variable fn’);
S.P.TUSHAR BALAJI
3122 21 3002 114
Simulated Graph:

10.2 Gaussian Variable Function

Code:

N=10^8;
mu=3;
s=3;
rand(1,N);
rand(0,1);
x=sqrt(s)*randn(1,N)+mu;
subplot(2,1,2);
histogram(x);
xlabel('time');
ylabel('Amplitude');
title('Gaussian Variable function')

Simulated Graph:

Result:
Thus , the MATLAB Programs to generate the Basic and Random Discrete Time Sequences is
executed and the output is verified.

You might also like