FourierMatrix

From QETLAB
Jump to: navigation, search
FourierMatrix
Generates the unitary matrix that implements the quantum Fourier transform

Other toolboxes required none
Function category Special states, vectors, and operators

FourierMatrix is a function that returns the unitary matrix that implements the quantum Fourier transform. That is, it returns the $d \times d$ matrix \[\frac{1}{\sqrt{d}}\begin{bmatrix}1 & 1 & 1 & \cdots & 1 \\ 1 & \omega & \omega^2 & \cdots & \omega^{d-1} \\ 1 & \omega^2 & \omega^4 & \cdots & \omega^{2(d-1)} \\ \vdots & \vdots & \vdots & \ddots & \vdots \\ 1 & \omega^{d-1} & \omega^{2(d-1)} & \cdots & \omega^{(d-1)(d-1)} \end{bmatrix},\] where $\omega := \exp(2\pi i/d)$ is a primitive d-th root of unity.

Syntax

  • F = FourierMatrix(DIM)

Argument descriptions

  • DIM: The dimension of the system. In other words, F will be a DIM-by-DIM matrix.

Examples

The qubit Fourier matrix

The qubit Fourier matrix is simply the usual Hadamard gate:

>> FourierMatrix(2)
 
ans =
 
   0.7071             0.7071          
   0.7071            -0.7071 + 0.0000i

The three-qubit Fourier matrix

The following line of code generates the three-qubit (i.e., DIM = 8) Fourier matrix, which can be seen here. The multiplication by sqrt(8) is just there to make the output easier to read.

>> FourierMatrix(8)*sqrt(8)
 
ans =
 
   1.0000             1.0000             1.0000             1.0000             1.0000             1.0000             1.0000             1.0000          
   1.0000             0.7071 + 0.7071i   0.0000 + 1.0000i  -0.7071 + 0.7071i  -1.0000 + 0.0000i  -0.7071 - 0.7071i  -0.0000 - 1.0000i   0.7071 - 0.7071i
   1.0000             0.0000 + 1.0000i  -1.0000 + 0.0000i  -0.0000 - 1.0000i   1.0000 - 0.0000i   0.0000 + 1.0000i  -1.0000 + 0.0000i  -0.0000 - 1.0000i
   1.0000            -0.7071 + 0.7071i  -0.0000 - 1.0000i   0.7071 + 0.7071i  -1.0000 + 0.0000i   0.7071 - 0.7071i   0.0000 + 1.0000i  -0.7071 - 0.7071i
   1.0000            -1.0000 + 0.0000i   1.0000 - 0.0000i  -1.0000 + 0.0000i   1.0000 - 0.0000i  -1.0000 + 0.0000i   1.0000 - 0.0000i  -1.0000 + 0.0000i
   1.0000            -0.7071 - 0.7071i   0.0000 + 1.0000i   0.7071 - 0.7071i  -1.0000 + 0.0000i   0.7071 + 0.7071i  -0.0000 - 1.0000i  -0.7071 + 0.7071i
   1.0000            -0.0000 - 1.0000i  -1.0000 + 0.0000i   0.0000 + 1.0000i   1.0000 - 0.0000i  -0.0000 - 1.0000i  -1.0000 + 0.0000i   0.0000 + 1.0000i
   1.0000             0.7071 - 0.7071i  -0.0000 - 1.0000i  -0.7071 - 0.7071i  -1.0000 + 0.0000i  -0.7071 + 0.7071i   0.0000 + 1.0000i   0.7071 + 0.7071i

Source code

Click on "expand" to the right to view the MATLAB source code for this function.

  1. %%  FOURIERMATRIX  Generates the unitary matrix that implements the quantum Fourier transform
  2. %   This function has one required argument:
  3. %     DIM: the size of the Fourier matrix
  4. %
  5. %   F = FourierMatrix(DIM) is the DIM-by-DIM unitary matrix that implements
  6. %   the quantum Fourier transform.
  7. %
  8. %   URL: http://www.qetlab.com/FourierMatrix
  9.  
  10. %   requires: nothing
  11. %   author: Nathaniel Johnston (nathaniel@njohnston.ca)
  12. %   package: QETLAB
  13. %   last updated: November 30, 2012
  14.  
  15. function F = FourierMatrix(dim)
  16.  
  17. w = exp(2i*pi/dim); % primitive root of unity
  18. F = (w.^((0:dim-1).'*(0:dim-1)))/sqrt(dim);