0
% Define the sequences x[n] and h[n]
n = 0:3;
x = cos(pi*n);
h = 2*n;

% Compute the four-point DFT of x[n]
X = fft(x);

% Compute the four-point DFT of h[n]
H = fft(h);

% Compute y[n] = x[n] * h[n] using linear convolution
y_linear = conv(x, h);

% Compute y[n] = x[n] * h[n] using DFT
Y = X .* H;
y_fft = ifft(Y);

% Display the results
disp('Four-point DFT of x[n]:')
disp(X)
disp('Four-point DFT of h[n]:')
disp(H)
disp('y[n] using linear convolution:')
disp(y_linear)
disp('y[n] using DFT:')
disp(y_fft)

I tried to prove that direct and convolution and ifft code give the same results but there need some modification to correct it.

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • 1
    You know the FFT imposes a periodic boundary condition, right? The convolution you compute there is cyclic, not linear like `conv`. You’ll have to pad with zeros to get a result comparable to `conv`. There are many questions on here about matching the two convolution computations, I suggest you do a search! – Cris Luengo Apr 15 '23 at 16:29

0 Answers0