You are on page 1of 14

Generation of Signals

%% sinusoidal signal
x=linspace(0,2*pi,25); %0 to 2pi is divided in 25 equidistant
points
Continuous
y=sin(x); 1

subplot(2,1,1); 0.5
title('Continuous');
0
subplot(2,1,2); stem(x,y);
-0.5
title('Discrete');
-1
0 1 2 3 4 5 6 7

Discrete
1

0.5

-0.5

-1
0 1 2 3 4 5 6 7
1

%% unit impluse 0.9

n1=input('Lower limit') 0.8

n2=input('Upper limit') 0.7

0.6
x=n1:n2; 0.5
y=[x==0]; 0.4

stem(x,y); 0.3

0.2

0.1

0
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1

%% unit step-discrete signal


n1=input('Enter the lower limit');
n2=input('Enter the upper limit');
Unit Step Signal - Discrete
n=n1:n2; x=[n>=0]; 1

0.9
stem(n,x); 0.8

title('Unit Step Signal - Discrete'); 0.7

0.6

0.5

0.4

0.3

0.2

0.1

0
-5 -4 -3 -2 -1 0 1 2 3 4 5
Sinc Function
%% sinc function 1
t2 = linspace(-5,5);
y2 = sinc(t2); 0.8

plot(t2,y2); 0.6
xlabel('Time (sec)');
ylabel('Amplitude'); 0.4

Amplitude
title('Sinc Function');
0.2

-0.2

-0.4
-5 -4 -3 -2 -1 0 1 2 3 4 5
Time (sec)
Assignment problem
Triangular x1(t)
2.5
clc;
close all;
% Generation of x1(t), Trinagular pulse 2

fs= 10000; %Sampling Frequency


w=2; % width is 2sec 1.5

Trinagular, x1
t = -1:1/fs:3;
x1 = 2*tripuls(t-1,w);% wave shifted by 1 1
sec towards positive side
plot(t,x1)
0.5
xlim([-1 3])
ylim([0 2.5])
xlabel('Time (secounds)') 0
-1 -0.5 0 0.5 1 1.5 2 2.5 3
ylabel('Trinagular, x1') Time (secounds)

title('Triangular x1(t)')
% Generation of x2(t)rectangular pulse 1.5
Triangular x1(t)

fs= 10000; %Sampling Frequency


w=2; % width is 2sec
t = -2:1/fs:2; 1

x2 = rectpuls(t,w);

Trinagular, x1
plot(t,x2)
xlim([-2 2]) 0.5

ylim([0 1.5])
xlabel('Time (secounds)')
ylabel('Trinagular, x1') 0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
Time (secounds)
title('Triangular x1(t)')
clc;
clear all;
close all; OPERATIONS ON SIGNALS AND SEQUENCE
N=128; Signal, x1(n) Signal, x2(n) Signal, x3(n)
1 0.4 1
f1=150;
f2=450; 0.5 0.2 0.5

f3=1500; 0 0 0

fs=8000; -0.5 -0.2 -0.5


n=0:N-1; -1 -0.4 -1
x1=sin(2*pi*(f1/fs)*n); 0 100 200 0 100 200 0 100 200

x2=(1/3)*sin(2*pi*(f2/fs)*n);
x3=sin(2*pi*(f3/fs)*n);
figure(1);
subplot(2,3,1);
plot(n,x1);
grid;
title('Signal, x1(n)');
subplot(2,3,2);
plot(n,x2);
grid;
title('Signal, x2(n)');
subplot(2,3,3);
plot(n,x3);
grid;
OPERATIONS ON SIGNALS AND SEQUENCE

% Signal Addition 1
Signal, x1(n)
0.4
Signal, x2(n)
1
Signal, x3(n)

0.5 0.2 0.5


xadd=x1+x2;
0 0 0
subplot(2,3,5);
plot(n,xadd); -0.5 -0.2 -0.5

grid; -1
0 100 200
-0.4
0 100 200
-1
0 100 200
title('x1(n)+x2(n)'); x1(n)+x2(n) x1*x3
% Signal Multiplication 1 1

xmult=x1.*x3; 0.5 0.5

subplot(2,3,6); 0 0
plot(xmult); -0.5 -0.5
grid;
-1 -1
title('x1*x3'); 0 100 200 0 100 200
clc;
close all;
% Generation of x1(t), Trinagular pulse
fs= 10000; %Sampling Frequency 3

w=2; % width is 2sec


2.5
t = -2:1/fs:2;
x1 = 2*tripuls(t-1,w);% wave shifted by 1
2
x2 = rectpuls(t,w);

additon of x1&x2
y=x1+x2; 1.5
plot(t,y)
xlim([-2 3]) 1
ylim([0 3])
xlabel('Time (secounds)') 0.5
ylabel('additon of x1&x2')
title('Addition of x1(t) and x2(t)') 0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2 2.5 3
Time (secounds)
clear all;
CONVOLUTION BETWEEN SIGNALS
clc;
tmin=0; tmax=4; dt=0.01;
t=tmin:dt:tmax; %set time vector for given signal x1(t)
signal 1

x1(t)
0.5
x1=1.*(t>=0&t<=2); %generate signal x1(t) 0

xa=1; 0 0.5 1 1.5 2


t
2.5 3 3.5 4

signal x2(t)
xb=-1; 1

x2(t)
x2=xa.*(t>=0&t<=1)+ xb.*(t>=1&t<=2); 0

-1
% generate signal x2(t) 0 0.5 1 1.5 2
t
2.5 3 3.5 4

signal, x3(t)=x1(t)*x2(t)
x3=conv(x1,x2); % perform convolution of 100

xl(t) & x2(t)

x3(t)
0

-100
n3=length(x3); 0 100 200 300 400
t
500 600 700 800

t1=0:1:n3-1; %set time vector for signal


x3(t)
subplot(3,1,1);plot(t,x1);
xlabel('t');ylabel('x1(t)');title('signal
x1(t)');
subplot(3,1,2);plot(t,x2);
xlabel('t');ylabel('x2(t)');title('signal
x2(t)');
subplot(3,1,3);plot(t1,x3);
xlabel('t');ylabel('x3(t)');title('signal,
x3(t)=x1(t)*x2(t)');
CONVOLUTION BETWEEN SEQUENCES
clear all
n=0:1:15; %specify range of n
x1=1.*(n>=1 & n<=10) ; %generate signal
signal x1(n)
x1(n) 1

x2=1.*(n>=2 & n<=10); % generate signal

x1(n)
0.5

x2(n) 0
0 5 10 15
N1=length(x1); n
signal x2(n)
N2=length(x2); 1

x3=conv(x1,x2); % convolution of signals

x2(n)
0.5
x1(n)and x2(n) 0
0 5 10 15
n1=0: 1: N1+N2-2; %specify range of n for n
x3(n) 10
signal , x3(n)=x1(n)*x2(n)

subplot(3,1,1);stem(n,x1);

x3(n)
5
xlabel('n');ylabel('x1(n)');
0
title('signal x1(n)'); 0 5 10 15
n
20 25 30

subplot(3,1,2);stem(n,x2);
xlabel('n');ylabel('x2(n)');
title('signal x2(n)');
subplot(3,1,3);stem(n1,x3);
xlabel('n');ylabel('x3(n)');
title('signal , x3(n)=x1(n)*x2(n)');
% Convoultion of x1(t) and x2(t)
signal x1(t)
fs= 10000; %Sampling Frequency 2

x1(t)
w=2; % width is 2sec 1

t = -2:1/fs:2; 0
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
x1 = 2*tripuls(t-1,w);% gneration of Triangular wave x1(t) t
signal x2(t)
x2 = rectpuls(t,w);% gneration of rectangular wave x2(t) 1

x2(t)
0.5

x3=conv(x1,x2) % perform convolution of xl(t) & x2(t) 0


-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
n3=length(x3); t
4
x 10 signal, x3(t)=x1(t)*x2(t)
2
t1=0:1:n3-1; %set time vector for signal x3(t)

x3(t)
1
subplot(3,1,1);plot(t,x1); 0
0 1 2 3 4 5 6 7 8
xlabel('t');ylabel('x1(t)');title('signal x1(t)'); t 4
x 10
subplot(3,1,2);plot(t,x2);
xlabel('t');ylabel('x2(t)');title('signal x2(t)');
subplot(3,1,3);plot(t1,x3);
xlabel('t');ylabel('x3(t)');title('signal, x3(t)=x1(t)*x2(t)');

You might also like