Advertisement
STANAANDREY

fourier apd

Nov 1st, 2023
1,478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.92 KB | None | 0 0
  1. function x = inverseDFT(X)
  2.     % Compute the length of the input DFT
  3.     N = length(X);
  4.    
  5.     % Compute the IDFT using the formula
  6.     x = zeros(1, N);
  7.     for n = 1:N
  8.         for k = 1:N
  9.             x(n) = x(n) + X(k) * exp(1i * 2 * pi * (k - 1) * (n - 1) / N);
  10.         end
  11.         x(n) = x(n) / N;
  12.     end
  13. end
  14. % Generate a random input signal
  15. signal = rand(1, 8);
  16.  
  17. % Compute the DFT of the input signal
  18. X = fft(signal);
  19.  
  20. % Compute the IDFT of the DFT result
  21. reconstructed_signal = inverseDFT(X);
  22.  
  23. % Check if the input signal and the reconstructed signal are the same
  24. disp('Original Signal:');
  25. disp(signal);
  26. disp('Reconstructed Signal:');
  27. disp(real(reconstructed_signal));
  28.  
  29. % Compare the original signal and the reconstructed signal
  30. if isequal(signal, real(reconstructed_signal))
  31.     disp('DFT and IDFT are inverses of each other.');
  32. else
  33.     disp('DFT and IDFT are NOT inverses of each other.');
  34. end
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement