rfft and irfft for Octave / Matlab

rfft:
One-dimensional Discrete Fourier Transform (DFT) for real input.

function rfft = rfft(a)
ffta = fft(a);
rfft = ffta(1:(floor(length(ffta)/2)+1));
end

irfft:
Inverse of the Discrete Fourier Transform (DFT) for real input.

function irfft = irfft(x,even=true)
n = 0; % the output length
s = 0; % the variable that will hold the index of the highest
% frequency below N/2, s = floor((n+1)/2)
if (even)
n = 2 * (length(x) – 1 );
s = length(x) – 1;
else
n = 2 * (length(x) – 1 )+1;
s = length(x);
endif
xn = zeros(1,n);
xn(1:length(x)) = x;
xn(length(x)+1:n) = conj(x(s:-1:2));
irfft = ifft(xn);
end

Source

Leave a Reply

Your email address will not be published. Required fields are marked *