Assignment#2
Assignment#2
Linear Convulution
Program for Linear Convolution of the seqeunce x = [1,2] and h = [1,2,4]
clc;
clear all;
close all;
x = [1,2];
h = [1,2,4];
y = conv(x,h);
figure;
subplot(3,1,1);
stem(x)
ylabel('Amplitude')
xlabel('(a)n');
subplot(3,1,2);
stem(h)
ylabel('Amplitude')
xlabel('(b)n');
subplot(3,1,3);
stem(h)
ylabel('Amplitude')
xlabel('(c)n');
DISCRETE CORRELATION
Auto Correlation
Program for Cross Correlation of the seqeunce x = [1,2,3,4] and h = [4,3,2,1]
clc;
clear all;
close all;
x = [1,2,3,4];
h = [4,3,2,1];
y = xcorr(x,h);
figure;
subplot(3,1,1);
stem(x)
ylabel('Amplitude')
xlabel('(a)n');
subplot(3,1,2);
stem(h)
ylabel('Amplitude')
xlabel('(b)n');
subplot(3,1,3);
stem(h)
ylabel('Amplitude')
xlabel('(c)n');
Auto Correlation
Program for Cross Correlation of the seqeunce x = [1,2,3,4] and h = [4,3,2,1]
clc;
clear all;
close all;
x = [1,2,3,4];
y = xcorr(x,x);
figure;
subplot(2,1,1);
stem(x)
ylabel('Amplitude')
xlabel('(a)n');
subplot(2,1,2);
stem(fliplr(y));
ylabel('Amplitude');
xlabel('(b)n');
fliplr(y);
SAMPLING
clc;
clear all;
close all;
f1 = 1/128;
f2 = 5/128;
n = 0: 255;
fc = 50/128;
x = cos(2*pi*f1*n)+ cos(2*pi*f2*n);
xa = cos(2*pi*fc*n);
xamp = x.*xa;
subplot(2,2,1);
plot(n,x);
title('x(n)');
xlabel('n');
ylabel('Amplitue');
subplot(2,2,2);
plot(n,xa);
title('xa(n)');
xlabel('n');
ylabel('Amplitue');
subplot(2,2,3);
plot(n,xamp);
title('x(n)');
xlabel('n');
ylabel('Amplitue');
%128 point DFT computation-solution fro 0 to 127
n = 0:127;
figure;
n1 = 128;
f1 = 1/128;
f2 = 5/128;
fc = 50/128;
x = cos(2*pi*f1*n)+cos(2*pi*f2*n);
xc = cos(2*pi*fc*n);
xa = cos(2*pi*fc*n);
xamp = x.*xa;
xam = fft(xamp,n1);
stem(n,xam);
title('xamp(n)');
xlabel('n');
ylabel('amplitude');
128 point DFT computation-solution fro 0 to 127
n = 0:99;
figure;
n2 = 0:n1-1;
f1 = 1/128;
f2 = 5/128;
fc = 50/128;
x = cos(2*pi*f1*n)+cos(2*pi*f2*n);
xc = cos(2*pi*fc*n);
xa = cos(2*pi*fc*n);
xamp = x.*xa;
for i = 1:100
xamp1(i) = xamp(i);
end
xam = fft(xamp1,n1);
stem(n2,xam);
title('xamp(n)');
xlabel('n');
ylabel('amplitude');