Experiment3 DSP
Experiment3 DSP
Lh=length(h);
Lx=length(x);
N=Lh+Lx-1;
x=[x zeros(1,N-Lx)];
h=[h zeros(1,N-Lh)];
for i=1:N
y(i)=0;
for j=1:Lx
if(i-j+1)>0
H(j,i)=h(i-j+1);
y(i)=y(i)+x(j).*H(j,i);
end
end
end
end
1)observation
clc;
clear all;
n=0:1:99;
f=[0,1/10,1/5,1/4,1,1/2];
h1=[1,1];
h2=[1,-1];
h3=(1/3)*[1,1,1];
h4=(1/4)*[1,1,-4,1,1];
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H1]=myconv(h1,x);
disp(H1);
end
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H2]=myconv(h2,x);
disp(H2);
end
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H3]=myconv(h3,x);
disp(H3);
end
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H4]=myconv(h4,x);
disp(H4);
end
2) observation:-
clc;
clear all;
n=0:1:99;
f=[0,1/10,1/5,1/4,1,1/2];
h1=[1,1];
h2=[1,-1];
h3=(1/3)*[1,1,1];
h4=(1/4)*[1,1,-4,1,1];
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H1]=myconv(h1,x);
y1=conv(h1,x);
z=0:1:100;
subplot(5,2,((2*i)-1));
stem(y);
title("Convolution of h1");
subplot(5,2,2*i);
stem(y1);
title("Inbuilt Convolution of h1");
end
figure;
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H2]=myconv(h2,x);
y1=conv(h2,x);
z=0:1:100;
subplot(5,2,((2*i)-1));
stem(y);
title("Convolution of h2");
subplot(5,2,2*i);
stem(y1);
title("Inbuilt Convolution of h2");
end
figure;
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H3]=myconv(h3,x);
y1=conv(h3,x);
z=-1:1:100;
subplot(5,2,((2*i)-1));
stem(y);
t=sprintf("Convolution of h3");
title(t);
subplot(5,2,2*i);
stem(y1);
t=sprintf("Inbuilt Convolution h3");
title(t);
end
figure;
for i=1:5
x=cos(2*pi*f(i)*n);
[y,H4]=myconv(h4,x);
y1=conv(h4,x);
z=-2:1:101;
subplot(5,2,((2*i)-1));
stem(y,z);
t=sprintf("Convolution of h4");
title(t);
subplot(5,2,2*i);
stem(y1,z);
t=sprintf("Inbuilt Convolution of h4");
title(t);
end
my dft function:-
D=zeros(N,N);
for n=1:N
y(n)=0;
for k=1:N
D(n,k)=exp(-1j*2*pi*(n-1)*(k-1)/N);
end
end
end
part 3)
clc;
clear all;
close all;
N=[8,16,32,64];
n=0:1:99;
f=[0,1/10,1/5,1/4,1,1/2];
x1=ones(1,8);
x2=ones(1,16);
x3=ones(1,64);
[y1,D1]=mydft(x1,8);
disp(D1);
[y2,D2]=mydft(x2,16);
disp(D2);
[y3,D3]=mydft(x3,64);
disp(D3);
part 4)
clc;
clear all;
close all;
N=[8,16,32,64];
n=0:1:99;
f=[0,1/10,1/5,1/4,1,1/2];
x1=ones(1,8);
x2=ones(1,16);
x3=ones(1,64);
[y1,D1]=mydft(x1,8);
subplot(4,2,1);
stem(y1);
title("Fourier Transform for N=8");
y11=fft(x1,8);
subplot(4,2,2);
stem(y11),
title("In Built Fourier Transform for N=8");
[y2,D2]=mydft(x2,16);
subplot(4,2,3);
stem(y2);
title("Fourier Transform for N=16");
y22=fft(x2,16);
subplot(4,2,4);
stem(y22),
title("In Built Fourier Transform for N=16");
[y3,D3]=mydft(x3,64);
subplot(4,2,5);
stem(y3);
title("Fourier Transform for N=64");
y33=fft(x3,64);
subplot(4,2,6);
stem(y33),
title("In Built Fourier Transform for N=64");