Skip to content

Instantly share code, notes, and snippets.

@bencholmes
Created August 30, 2018 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bencholmes/a5b85f75dd903d033463a1ba8a1dfdad to your computer and use it in GitHub Desktop.
Save bencholmes/a5b85f75dd903d033463a1ba8a1dfdad to your computer and use it in GitHub Desktop.
A MATLAB function to force symmetry on an FFT, thus producing a real signal after an IFFT.
function X = forceFFTSymmetry(X)
% forceFFTSymmetry A function to force conjugate symmetry on an FFT such that when an
% IFFT is performed the result is a real signal.
% The function has been written to replace MATLAB's ifft(X,'symmetric'), as this function
% is not compatible with MATLAB Coder.
% Licensed under Creative Commons Zero (CC0) so use freely.
XStartFlipped = fliplr(X(2:floor(end/2)));
X(ceil(end/2)+2:end) = real(XStartFlipped) - sqrt(complex(-1))*imag(XStartFlipped);
% Or
% X(ceil(end/2)+2:end) = conj(XStartFlipped);
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment