You are on page 1of 19

EXPERIMENT NO.

1A
Waveform Generation

Aim: To generate parabolic, step, sine, rectangular, square, ramp, impulse,


pulse, saw tooth, sinc, triangular, exponentially increasing and decreasing
signals using MATLAB and plot the outcomes.
Apparatus Required: MATLAB R2016A, Windows 10- 64 bit operating system
Theory:
Procedure: First we clear the command window and delete all the previous
variables. Then we decide the range of input values .Finally we define the
function. Lastly a graph is plotted between the function and the input values by
stem() if discrete function and plot() if continuous function.
MATLAB program:
%1- Program for generating a unit impulse function
clc;
clear all;
close all;
n=-10:20;
u=[zeros(1,10) 1 zeros(1,20)]
stem(n,u)

%2- Program for generating an unit step function


n=-20:20;
u=[zeros(1,20),1,ones(1,20)];
stem(n,u)

%3- Program for generating ramp function


n=-10:10;
z=[zeros(1,11),1:10];
axis([-10 10 0 10]);
title('ramp')
plot(n,z)

%4- Program for generating exponentially increasing functions


n=0:10;
a=2;
x=a.^n;
stem(n,x)

%5- Program for generating exponentially decreasing functions


n=0:10;
a=0.5;
x=a.^n;
stem(n,x)

%6- Program for generating sine wave


t=0:0.1:20;
x=3*sin(t);
plot(t,x)
%7- Program for generating cosine wave
t=0:0.1:20;
x=3*cos(t);
plot(t,x)

%8- Program for generating a triangular wave


a=2;
x1=1-abs(t)/a;
x2=0;
x=x1.*(abs(t)<=a)+ x2.*(abs(t)>a);
plot(t,x)

%9-Program for generating Gaussian signal


a=2;
x=exp(-a.*(t.^2));

%10- Program for generating a parabolic signal


a=0.4;
x1=(a*(t.^2))/2;
x2=0;
x=x1.*(t>=0)+x2.*(t<0);
plot(t,x);

%11-Program for generating a saw tooth function


clc;
clear all;
close all;
t=-5:0.01:5;
x=sawtooth(pi*t);
plot(t,x)
%12-Program for generating a rectangular pulse
clc;
clear all;
close all;
fs=500;
t=-5:1/fs:5;
y=rectpuls(t,0.5);
t1=t-2.5;
t2=t+2.5
y1=rectpuls(t1,0.5);
y2=rectpuls(t2,0.5);
plot(t,y,t,y1,t,y2);
axis([-4 5 0 1.5]);
title('Pulse');

Output graphs:
Unit impulse function
Unit step function

Ramp function

Exponentially increasing function


Exponentially decreasing function

Sine wave
Cosine wave

Triangular wave

Gaussian signal
Parabolic signal

Saw tooth function

Rectangular pulse
Result: From this experiment, I was able to generate parabolic, step, sine,
rectangular, square, ramp, impulse, pulse, sawtooth, sinc, triangular,
exponentially increasing and decreasing signals using MATLAB and plot the
outcomes.
Inference: By the help of this experiment, I was able to study about the signals
that use the elementary signals as their inputs and understand the behaviour of
these systems.
References:
1. Signals and Systems by P. Ramesh Babu and R. Anandanatarajan(4th
Edition)
2. Digital Signal Processing by P. Ramesh Babu(4th Edition)

EXPERIMENT NO. 1B
Convolution of Signals

Aim: To determine the linear and circular convolutions of any two sequences
manually using a method other than matrix multiplication and verify the results
using MATLAB.
Apparatus Required: MATLAB R2016A, Windows 10- 64 bit operating system
Theory: Convolution is a mathematical operation used to express the relation
between input and output of an LTI system. It relates input, output and impulse
response of an LTI system as
y(t)=x(t)∗h(t)y(t)=x(t)∗h(t)
Where y (t) = output of LTI
x (t) = input of LTI
h (t) = impulse response of LTI
There are two types of convolutions:
 Continuous convolution
 Discrete convolution
Continuous Convolution
y(t)=x(t)∗h(t)y(t)=x(t)∗h(t)
=∫x(τ)h(t−τ)dτ=∫x(τ)h(t−τ)dτ (integrating from -∞ to ∞)
(or)
=∫x(t−τ)h(τ)dτ=∫x(t−τ)h(τ)dτ (integrating from -∞ to ∞)
Discrete Convolution
y(n)=x(n)∗h(n)y(n)=x(n)∗h(n)
=Σx(k)h(n−k)=Σx(k)h(n−k) (summation from -∞ to ∞)
(or)
=Σx(n−k)h(k)=Σx(n−k)h(k) (summation from -∞ to ∞)
By using convolution we can find zero state response of the system.
Procedure: First we clear the command window and delete all the previous
variables. Then we get the two sequences as the user input and find the third
sequence by means of convolution by logic or by using conv() function directly
and plot the graph by using stem() function. We do the same for circular
convolution i.e. find the third sequence by means of circular convolution by
logic or by cconv() command.
Manual calculations:
MATLAB program:
%Program for linear convolution using syntax
clc;
clear all;
close all;
x=input('Enter the first sequence');
N1=length(x);
h=input('Enter the second sequence');
N2=length(h);
n=0:1:N1-1;
subplot(2,2,1);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('X Sequence Response');
n=0:1:N2-1;
subplot(2,2,2);
stem(n,h);
xlabel('Time');
ylabel('Amplitude');
title('H Sequence Response');
y=conv(x,h)
N=N1+N2-1;
n=0:1:N-1;
subplot(2,2,4);
stem(n,y);
xlabel('Time');

y=conv(x,h)
N=N1+N2-1;
n=0:1:N-1;
subplot(2,2,4);
stem(n,y);
xlabel('Time');
ylabel('Amplitude');
title('Convolution of X&H Response');

%Program for linear convolution using logic


clc
close all;
clear all;
x=input('Samples of x[n]');
h=input('Sample of h[n]');
xlen=lenght(x);
hlen=lenght(h);
k=0;
for i=1:xlen;
for j=1:hlen;
y(i,j+k)=x(i)*h(j);
end
k=k+1;
end;
disp('Convolution of two signals');
z=sum(y);
stem(z);

%Program for circular convolution using logic


clc;
clear all;
close all;
x=input('Enter the first sequence');
N1=length(x);
h=input('Enter the second sequence');
N2=length(h);
n=0:1:N1-1;
subplot(2,2,1);
stem(n,x);
xlabel('Time');
ylabel('Amplitude');
title('X Sequence Response');
n=0:1:N2-1;
subplot(2,2,2)
stem(n,h)
xlabel('Time')
ylabel('Amplitude')
title('Frequency response')
N=max(N1,N2)
x=[x,zeros(1,N-N1)];
h=[h,zeros(1,N-N2)];

for n=1:N
y(n)=0;
for i=1:N
j=n-i+1;
if(j<=0)
j=N+j;
end
y(n)=y(n)+x(i)*h(j);
end
end
disp('Convolution of x and h is');
subplot(2,2,3);
stem(y);
xlabel('Time');
ylabel('Amplitude');
title('Convolution of X and H response');

%Program for circular convolution using syntax


clc
close all;
clear all;
x=input('Samples of x[n]');
h=input('Samples of h[n]');
xlen=length(x);
hlen=length(h);
k=0;
y=cconv(x,h,4)
disp('Circular Convolution');
stem(y);

Input and Output:


Enter the first sequence[3 1 3 1]
Enter the second sequence[2 1 2 1]

y=

6 5 13 10 8 5 1

y=

6 5 13 10 8 5 1
Samples of x[n][3 1 3 1]
Sample of h[n][2 1 2 1]
Convolution of two signals

Enter the first sequence[1 -1 -2 3]


Enter the second sequence[1 2 3]

N=

4
Convolution of x and h is

Samples of x[n][1 -1 -2 3]
Samples of h[n][1 2 3]

y=

1 10 -1 -4

Circular Convolution
Result: From this experiment, I was able to determine the linear and circular
convolutions of any two sequences manually using a method other than matrix
multiplication and verify the results using MATLAB.
Applications:

1. Image Processing
2. Signal Filtering
Inference: From this experiment, I was able to understand that convolution is a
mathematical way of combining two signals to form a third signal. Systems are
described by a signal called the impulse response. Convolution is important
because it relates the three signals of interest: the input signal, the output signal,
and the impulse response.
References:
1. Signals and Systems by P. Ramesh Babu and R. Anandanatarajan(4th
Edition)
2. Digital Signal Processing by P. Ramesh Babu(4th Edition)

You might also like