You are on page 1of 5

Linear convolution

%2011028
x=[1 2 3 1];
h=[1 1 1];
N=length(x);
L=length(h);
x=[x,zeros(1,L)];
h=[h,zeros(1,N)];
y=[];
for n=1:N+L-1
y(n)=0;
for k=1:N
if(n-k+1>=1)
y(n)=y(n)+(x(k)*h(n-k+1));
end
end
end
figure;
stem(x);
figure;
stem(h);
figure;
stem(y);
INPUT SIGNAL STEP RESPONSE SIGNAL

OUTPUTSIGNAL
CIRCULAR CONVOLUTION
%2011028
clc;
clear all;
close all;
x=[1 -1 -2 3 -1];
h=[1 2 3];
N=length(x);
L=length(h);
if(max([N,L])==N)
h=[h,zeros(1,N-L)];
end
if(max([N,L])==L)
x=[x,zeros(1,L-N)];
end
x=[x,zeros(1,L)];
h=[h,zeros(1,N)];
y=[];
for n=1:N
y(n)=0;
for k=1:N
g=abs(mod(n-k+1,N));
if(g>=1)
y(n)=y(n)+(x(k)*h(g));
end
end
end
figure;
stem(x);
figure;
stem(h);
figure;
stem(y);
d=cconv(x,h,N);
figure;
stem(d) INPUTSIGNAL STEP RESPONSE SIGNAL

OUTPUT SIGNAL
AUTO CORRELATION
%2011028
clc;
clear all;
close all;
x=[1 -1 -2 3 -1];
h=[1 -1 -2 3 -1];
N=length(x);
L=length(h);
if(max([N,L])==N)
h=[h,zeros(1,N-L)];
end
if(max([N,L])==L)
x=[x,zeros(1,L-N)];
end
x=[x,zeros(1,L)];
h=[h,zeros(1,N)];
y=[];
b=[];
for n=1:N
y(n)=0;
b(n)=0;
for k=1:N
y(n)=(y(n)+(x(k)*h(n+k-1)));
if(k-n+1>=1)
b(n)=b(n)+(x(k)*h(k-n+1));
end
end
end
figure;
stem(x);
figure;
stem(h);
b=flip(b);
autocrr=[b,y];
figure;
stem(autocrr);
d=xcorr(x);
figure;
stem(d)

REFERENCE SIGNAL CORRELATED SIGNAL


CROSS CORRELATION
%2011028

%cross correlation

clc;

clear all;
close all;
x=[1 -1 2 3 -2];
h=[1 -1 2 3 -2 -3 4 -1];
N=length(x);
L=length(h);
if(max([N,L])==N)
h=[h,zeros(1,N-L)];
end
if(max([N,L])==L)
x=[x,zeros(1,L-N)];
end
x=[x,zeros(1,L)];
h=[h,zeros(1,N)];
y=[];
b=[];
for n=1:N
y(n)=0;
b(n)=0;
for k=1:N
y(n)=(y(n)+(x(k)*h(n+k-1)));
if(k-n+1>=1)
b(n)=b(n)+(x(k)*h(k-n+1));
end
end
end
figure;
stem(x);
xlabel('Samples')
ylabel('Amplitude')
title("Reference Signal");
figure;
stem(h);
xlabel('Samples')
ylabel('Amplitude')
title("Reference Signal");
b=flip(b);
crosscrr=[b,y];
figure;
stem(crosscrr);
xlabel('Samples')
ylabel('Amplitude')
title("Correlated Signal")

You might also like