ex_fft v0.2.0 ExFft

ExFft is module for FFT (Fast Fourier Transform)

Link to this section Summary

Functions

Calculate exp(j*n) for input x and x is a number type

Calculate FFT for input list

Calculate IFFT for input list

Link to this section Functions

Link to this function

complex_jexp(x)

Calculate exp(j*n) for input x and x is a number type.

Examples

iex> ExFft.complex_jexp(Math.pi())
ComplexNum.new(Math.cos(Math.pi()), Math.sin(Math.pi()))
iex> ExFft.complex_jexp(0)
ComplexNum.new(1.0, 0.0)
Link to this function

fft(list, norm \\ :none)
fft([number() | ComplexNum], :none | :ortho) :: [ComplexNum]

Calculate FFT for input list

List member's type must be number or ComplexNum

The length of list must be a power of 2

if norm is :ortho, transform will be scaled by 1/Math.sqrt(length(list))

Examples

iex> ExFft.fft([2,1])
[ComplexNum.new(3), ComplexNum.new(1)]
iex> ExFft.fft([ComplexNum.new(2),ComplexNum.new(1)])
[ComplexNum.new(3), ComplexNum.new(1)]

iex> ExFft.fft([2,1], :ortho)
[ComplexNum.new(2.1213203435596424, 0.0), ComplexNum.new(0.7071067811865475, 0.0)]

iex> list = 0..15 |> Enum.map(fn x -> Math.sin(x * 2*Math.pi()/16) |> Float.round(3) end)
iex> list_fft_ifft =
...> list
...> |> ExFft.fft() |> ExFft.ifft()
...> |> Enum.map(fn x -> ComplexNum.Cartesian.real(x) |> Float.round(3) end)
iex> Keyword.equal?(list, list_fft_ifft)
true
Link to this function

ifft(list, norm \\ :none)
ifft([number() | ComplexNum], :none | :ortho) :: [ComplexNum]

Calculate IFFT for input list

if norm is :ortho, transform will be scaled by 1/Math.sqrt(length(list)), else 1/length(list)

Examples

iex> ExFft.ifft([2,1])
[ComplexNum.new(1.5,0.0), ComplexNum.new(0.5,0.0)]
iex> ExFft.ifft([ComplexNum.new(2), ComplexNum.new(1)])
[ComplexNum.new(1.5,0.0), ComplexNum.new(0.5,0.0)]

iex> ExFft.ifft([2,1], :ortho)
[ComplexNum.new(2.1213203435596424,0.0), ComplexNum.new(0.7071067811865475,0.0)]