% DFT and IDFT Computation Using Equations
% DFT and IDFT Computation Using Equations
% zero padding
if N > L
x = [x,zeros(1,N-L)];
end
% computation of DFT
for k = 0:1:N-1;
X(k+1) = 0;
for n = 0:1:N-1;
X(k+1) = X(k+1)+(x(n+1)*exp(-1i*2*pi*n*k/N));
end
end
disp('The DFT of x[n] using direct method of DFT computation is')
disp(X);
% computation of magnitude and phase
Xm = abs(X);
Xp = phase(X);
1
% plotting x[n],Xm(k),Xp(k) and xr[n]
n = 0:1:N-1;
k = 0:1:N-1;
subplot(411),stem(n,x),xlabel('n'),ylabel('x(n)'),title('input sequence');grid on;
subplot(412),stem(k,Xm),xlabel('k'),ylabel('|X(k)|'),title('magnitude response');grid on;
subplot(413),stem(k,Xp),xlabel('k'),ylabel('phase of X(k)'),title('phase response');grid on;
subplot(414),stem(n,xr),xlabel('n'),ylabel('xr[n]'),title('recovered signal');grid on;
2
b) MATLAB program to compute N-point DFT of a given sequence x[n]
using Direct method of computation and FFT algorithm
% zero padding
if N > L
x = [x,zeros(1,N-L)];
end
4
b) MATLAB program to compute linear convolution of two given
sequences using circular convolution
% zero-padding
x1=[x1, zeros(1, N-L1)];
x2=[x2, zeros(1, N-L2)];