Professional Documents
Culture Documents
EE304 LAB: Mihir Dalal 2019eeb1171 Mihir Kumar Srivastava 2019eeb1172
EE304 LAB: Mihir Dalal 2019eeb1171 Mihir Kumar Srivastava 2019eeb1172
Experiment: 3 and 4
Mihir Dalal 2019eeb1171
Mihir Kumar Srivastava 2019eeb1172
Matlab Codes
1) MATLAB code for Part 1
clear all
close all
clc
% x=u[n]-u[n-6],this is equivalent to x=[1,1,1,1,1,1] (taking 6 samples)
x=[1,1,1,1,1,1]
h=x;
n_x=length(x);
n_h=length(h);
end
end
fprintf("The linear convolution without using the inbuilt library: ");
linear_cov_output %just for printing it
fprintf("The linear convolution using the inbuilt library: ");
desired_linear_output = conv(x,h) %calculating linear convolution using the inbuilt library
%% Our linear convolution of two signals coming with and without using the inbuilt library are
similar.
clear all
close all
clc
% x=u[n]-u[n-6],this is equivalent to x=[1,1,1,1,1,1] (taking 6 samples)
x=[1,1,1,1,1,1,0,0,0,0,0];
h=x;
N=length(x);
n_axis=0:N-1; %discrete time corresponding to N samples
2
circular_cov_output=zeros(1,N); %since circular convolution of the 2 given signals will lead to
N samples in the output
for n=1:N
for m=1:N
j=mod(n-m,N);
j=j+1;
circular_cov_output(n)=circular_cov_output(n)+x(m)*h(j);
end
end
fprintf("The circular convolution without using the inbuilt library: ");
circular_cov_output %just for printing it
fprintf("The circular convolution using the inbuilt library: ");
desired_output = cconv(x,h,N) %calculating circular convolution using the inbuilt library
3) Part 3
We can see that the circular convolution and linear convolution comes out to be
equal in this case.
3
n_x=length(x);
n_h=length(h);
N = n_x+n_h-1;
naxis=0:N-1;
x1=[x zeros(1,N-n_x)];
h1=[h zeros(1,N-n_h)];
n_axis=0:N-1;
linear_cov_output=zeros(1,N);
for n=1:N
for k=1:n
linear_cov_output(n)=linear_cov_output(n)+x1(k)*h1(n-k+1);
end
end
fprintf("The linear convolution: ");
linear_cov_output
4
**************************