Discrete Hartley transformation

Basic DHT algorithm

It is said that the Fourier transformation must be computed with complex numbers and that would be a disadvantage. That’s not fully true. To compute the discrete Fourier transformation there are no complex numbers required (see Fourier transformation ). Only the fast Fourier transformation must be computed completely with complex numbers. But o.k. the Hartley transformation (by Ralph Hartley, 1888 – 1970) is another approach to compute the frequency spectrum of a digitized signal. It is not that far away from the discrete Fourier transformation. It’s basic function is to transform a digitized signal that consists of the sequence of points x0, … , xN-1 into the spectrum H0, … , HN-1

In the literature the formulation for this is:

DHT


I add a multiplication by 2 / N to get the spectrum comparable to the one of the Fourier transformation. I don’t understand why the most descriptions in the net do not have this. In the above formulation the magnitudes of the spectrum are depending on N, the number of data points and I regard this as wrong :-)

So my formulation looks like:

DHT

With

DHT


For the inverse transformation from frequency spectrum back to the function in the time domain in some descriptions they say.


DHT


Using the same cas function as is used for the transformation into the frequency domain. Which (I would say :-) ) is not really correct.

In the Fourier transformation there is a real parameter that represents the even part of the transformed function and an imaginary parameter that represents the odd part of the transformed function and for the inverse transformation both of these two parts are used. The same is valid for the Hartley transformation. There is an even part

DHT


And an odd part

DHT


And the inverse transformation is:

DHT




DHT algorithm without sinus

The cosine function is shifted by 90° against the sinus function. That means:


DHT



And with the addition theorem


DHT



We can write


DHT



Or a bit simplified

DHT



And as

DHT



We get

DHT



With this the formulation for the Hartley transformation becomes:

DHT



With this a function for the Hartley transformation becomes:


public void CalcDHT()
{
     int k, n;
     if (N > 0)
     {
         for (k = 0; k < N; k++)
         {
              hk[k] = 0;
              for (n = 0; n < N; n++)
              {
                   hk[k] += y[n] * Math.Cos((double)(2 * Math.PI * n * k / N - Math.PI / 4));
              }
              hk[k] *= 2.0 * Math.Sqrt(2.0)/N;
         }
     }
}



It uses the array of y as input signal and puts the Hk values into the array of hk.


The inverse Hartley transformation is


public void InvDHT()
{
     int t, n;
     for (n = 0; n <= N; n++)
     {
         xw[n] = 0;
         for (t = 0; t < 30; t++)    // we only take the first 30 harmonics
         {
              xw[n] = xw[n] + (hk[t] + hk[N - t]) / 2 * Math.Cos(2.0 * Math.PI * t * n / N) +   //even part
              (hk[t] - hk[N - t]) / 2 * Math.Sin(2.0 * Math.PI * t * n / N);  // odd part
         }
     }
}



It rebuilds the signal in the array of xw for interpolation.


With these functions the Hartley transformation transforms a rectangle signal like:


DHT


Into the first 15 harmonics of the spectrum

DHT


Whereas the discrete Fourier transformation yields:

DHT


In the spectrum of the Fourier transformation the even and odd part are separated whereas in the Hartley spectrum they are in one value. Therefore the values of the Hartley spectrum are a little bigger.

In the spectrum of a cut sinus like:

DHT


that can be seen even better:


For this signal the Hartley spectrum is

DHT


And the Fourier spectrum:

DHT


There is one big difference: The first value of the Hartley spectrum is doubled as big as the same one of the Fourier spectrum. The reason for that is that this first value is a special case in the Fourier transformation and is multiplied by 2 in the inverse transformation :-)



Sample project

The sample project consists of one main window.

DHT


C# Demo Project Hartley transformation
  • Hartley.zip