File: complexFFT.rb

package info (click to toggle)
ruby-fftw3 0.4-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 120 kB
  • sloc: ansic: 223; ruby: 64; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 1,306 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require "test/unit"
require "narray"
require "numru/fftw3"
include NumRu

class ComplexTest < Test::Unit::TestCase

  def setup
    @na_double = NArray.float(8,4).fill(1.0)
    @na_single = NArray.sfloat(8,4).indgen!
    @na_complex = NArray.float(4,3,8,3)
    @na_complex[1,1,1,0] = 1.0
    @sfloat_delta = 5.0e-5
    @float_delta = 1.0e-13
  end

  define_method("test_double_float") do
    fc_double = FFTW3.fft(@na_double, -1)/@na_double.length
    assert_in_delta @na_double, FFTW3.fft(fc_double, 1).real, @float_delta
  end

  define_method("test_single_float") do
    fc_single = FFTW3.fft(@na_single, -1)/@na_single.length
    assert_in_delta @na_single, FFTW3.fft(fc_single, 1).real, @sfloat_delta
  end

  define_method("test_dimenssion_selection") do
    fc_double = FFTW3.fft(@na_double, -1, 0)/@na_double.shape[0]
    assert_in_delta @na_double, FFTW3.fft(fc_double, 1, 0).real, @float_delta
    fc_single = FFTW3.fft(@na_single, -1, 0)/@na_single.shape[0]
    assert_in_delta @na_single, FFTW3.fft(fc_single, 1, 0).real, @sfloat_delta
  end

  define_method("test_complex") do
    fc_complex = FFTW3.fft(@na_complex, -1, 0, 1, 2)/(@na_complex.shape[0]*@na_complex.shape[1]*@na_complex.shape[2])
    assert_in_delta @na_complex, FFTW3.fft(fc_complex, 1, 0, 1, 2).real, @float_delta
  end

end