3

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?

Royi
  • 19,608
  • 4
  • 197
  • 238
noxid
  • 31
  • 1
  • 2
  • 4
    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 07 '17 at 23:32
  • Note: Today there is no reason to expect the Hartley transform to be faster than a real-to-complex FFT. A long time ago it might have been faster, but that is no longer the case. See for example this warning in the FFTW docs. – Cris Luengo Sep 25 '23 at 20:16

2 Answers2

4

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.

MBaz
  • 15,314
  • 9
  • 30
  • 44
Maximilian Matthé
  • 6,218
  • 2
  • 12
  • 19
3

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:

Laurent Duval
  • 31,850
  • 3
  • 33
  • 101