Function Repository Resource:

HartleyMatrix

Source Notebook

Generate a Hartley matrix

Contributed by: Jan Mangaldan

ResourceFunction["HartleyMatrix"][n]

returns an n×n Hartley matrix.

Details and Options

Each entry Hrs of the Hartley matrix is defined as .
Rows or columns of the Hartley matrix are basis sequences of the discrete Hartley transform.
The Hartley matrix is symmetric and orthogonal, which means the Hartley matrix is involutory (i.e., its own inverse).
ResourceFunction["HartleyMatrix"][,WorkingPrecisionp] gives a matrix with entries of precision p.

Examples

Basic Examples (2) 

A 4×4 Hartley matrix:

In[1]:=
ResourceFunction["HartleyMatrix"][4] // MatrixForm
Out[1]=

Visualize the basis sequences of the Hartley transform:

In[2]:=
MatrixPlot[ResourceFunction["HartleyMatrix"][128]]
Out[3]=

Options (3) 

WorkingPrecision (3) 

By default, an exact matrix is computed:

In[4]:=
ResourceFunction["HartleyMatrix"][3] // Simplify // MatrixForm
Out[4]=

Use machine precision:

In[5]:=
ResourceFunction["HartleyMatrix"][3, WorkingPrecision -> MachinePrecision] // MatrixForm
Out[5]=

Use arbitrary precision:

In[6]:=
ResourceFunction["HartleyMatrix"][3, WorkingPrecision -> 20] // MatrixForm
Out[6]=

Properties and Relations (2) 

The Hartley matrix is symmetric and orthogonal:

In[7]:=
hm = ResourceFunction["HartleyMatrix"][5]
Out[7]=
In[8]:=
{SymmetricMatrixQ[hm], OrthogonalMatrixQ[hm]}
Out[8]=

The Hartley matrix is thus its own inverse:

In[9]:=
hm . hm == IdentityMatrix[5] // Simplify
Out[9]=

Compute the discrete Hartley transform of a vector by multiplying it with the Hartley matrix:

In[10]:=
u = N[{1, 2, 3, 4, 5, 6, 7}];
n = Length[u];
In[11]:=
AbsoluteTiming[v1 = ResourceFunction["HartleyMatrix"][n] . u]
Out[11]=

It is faster to use the resource function DiscreteHartleyTransform:

In[12]:=
AbsoluteTiming[v2 = ResourceFunction["DiscreteHartleyTransform"][u]]
Out[12]=
In[13]:=
Chop[v1 - v2]
Out[13]=

Version History

  • 1.0.0 – 13 February 2023

Source Metadata

Related Resources

License Information