Exp 2
Exp 2
for k = 1:N
if(k<M)
x(k)=1;
else
x(k)=0;
end
end
for k = 1:N
X(k) = 0;
for n = 1:N
X(k) = X(k)+ x(k)*(cos(2*pi*k*n/N)-sqrt(-1)*sin(2*pi*k*n/N));
end
end
k = 1:N;
subplot(2,1,1)
stem(abs(X));
title('Amplitude plot');
ylabel('amplitude');
xlabel('Time');
subplot(2,1,2)
stem(angle(X));
title('Phase plot');
ylabel('amplitude');
xlabel('Time');
N_point_DFT
Enter length of DFT
10
M =
10
1.0e-14 *
Columns 1 through 6
-0.0444 + 0.0245i -0.0444 + 0.0268i -0.0222 + 0.0513i
0.0000 + 0.0425i 0.0000 + 0.0612i 0.0333 + 0.0914i
Columns 7 through 10
-0.4885 + 0.4934i 0.1221 + 0.1182i 0.2331 + 0.5535i
0.0000 + 0.000
Fig representing the N point DFT for M=10 and different values of N =10 && 100 && 256
DFT with given impulse response
u = n/2;
for l = 1:n
if(x(l)==0)
h(l)=0.5;
else
h(l)=sin(0.5*pi*(l-u-1))/(pi*(l-u-1));
end
end
for k = 1:n
X(k) = 0;
for l = 1:n
X(k) = X(k)+ h(k)*(cos(2*pi*k*l/n)-sqrt(-
1)*sin(2*pi*k*l/n));
end
end
subplot(2,1,1)
stem(abs(X))
title('Amplitude plot')
grid on
ylabel('amplitude');
xlabel('Time');
subplot(2,1,2)
stem(angle(X))
title('Phase plot')
grid on
ylabel('amplitude');
xlabel('Time');
Fig representing DFT of impulse response h(n) for n=[-8:7],[-
16:15],[-64,63]
Linear Convolution via DFT based approach:
x=input('Input First Sequence');
n1=length(x);
n2=length(h);
N=n1+n2-1;
x1=[x zeros(1,N-n1)];
x2=[h zeros(1,N-n2)];
a=fft(x, N);
b=fft(h, N);
c=a.*b;
d=ifft(c, N);
disp('First Sequence');
disp(x)
disp('Second Sequence');
disp(h)
disp('Convolved Sequence');
disp(d)
n=0:N-1;
subplot(3,1,1);
stem(x);
title('First Sequence');
ylabel('Signal');
xlabel('Time');
subplot(3,1,2);
stem(h);
title('Second Sequence');
ylabel('Signal');
xlabel('Time');
subplot(3,1,3);
stem(d);
title('Convolved Sequence');
ylabel('Signal');
xlabel('Time');
Fig representing Linear Convolution via DFT based approach of
two sequences