Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function x = inverseDFT(X)
- % Compute the length of the input DFT
- N = length(X);
- % Compute the IDFT using the formula
- x = zeros(1, N);
- for n = 1:N
- for k = 1:N
- x(n) = x(n) + X(k) * exp(1i * 2 * pi * (k - 1) * (n - 1) / N);
- end
- x(n) = x(n) / N;
- end
- end
- % Generate a random input signal
- signal = rand(1, 8);
- % Compute the DFT of the input signal
- X = fft(signal);
- % Compute the IDFT of the DFT result
- reconstructed_signal = inverseDFT(X);
- % Check if the input signal and the reconstructed signal are the same
- disp('Original Signal:');
- disp(signal);
- disp('Reconstructed Signal:');
- disp(real(reconstructed_signal));
- % Compare the original signal and the reconstructed signal
- if isequal(signal, real(reconstructed_signal))
- disp('DFT and IDFT are inverses of each other.');
- else
- disp('DFT and IDFT are NOT inverses of each other.');
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement