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:
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:
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 algorithm without sinus
And with the addition theorem
We can write
Or a bit simplified
And as
We get
With this the formulation for the Hartley transformation becomes:
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:
Into the first 15 harmonics of the spectrum
Whereas the discrete Fourier transformation yields:
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:
that can be seen even better:
For this signal the Hartley spectrum is
And the Fourier spectrum:
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
The sample project consists of one main window.
C# Demo Project Hartley transformation