# Fast Hartley Transform Implementation in MATLAB

I want to implement Fast Hartley Transform (Specifically Discrete Hartley Transform) in a script file in MATLAB. Does anyone know have a reference implementation of this in MATLAB or another language so that a complete novice can understand it?

• if you ask me, that makes little to no sense. The fact that you can save quite a few operation with the FHT will be immensely outweighed by the fact that you're doing this within matlab's interpreter – which is notoriously slow. Things like the FFT are implemented in highly-optimized native code, not in matlab scripts. Any matlab-script FFT would be much, much slower than just doing the DFT naively by multiplying with a DFT matrix (because matrix multiplication is, again, implemented natively). takeaway:matlab itself is very slow.If you need fast,implement natively and call from within matlab. – Marcus Müller Jan 7 '17 at 23:32

You can resort to the properties of the DHT with the DFT, given in the wikipedia article. For a real-valued function $f$, its DHT in terms of the DFT is given by

$$\mathcal{H}f = \Re\{\mathcal{F}f\}-\Im\{\mathcal{F}f\}.$$

So, a function for fast Hartley transform can be given by

function Hf = fht(f)
F = fft(f);
Hf = real(F) - imag(F);
end


Though, you need to take care of the normalization factors, and tdhis is up to you and how you define the scale factors of the DHT.

• Make the answer complete by adding the inverse transform. Good answer! – Royi Nov 18 at 14:39

For the standard algorithmic version, you can get information in An Algorithm for the Fast Hartley transform, R. F. Ulmann (with Fortran versions). A Matlab version of the FHT is provided by Lars Gregersen, exactly as given by @MaximilianMatthé, except that it checks for a real signal input. C++ and C# versions can also be found in ALGLIB: Fast Hartley transform.

For improved versions, that can provide speed-up beyond algorithmic optimization, one can consider other factors, such as memory tricks, hardware optimization, use of binary inputs/outputs, higher-dimension extensions. You can check for instance: