Class: Vizcore::Analysis::FFTProcessor::FFTWBackend Private

Inherits:
Object
  • Object
show all
Defined in:
lib/vizcore/analysis/fft_processor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

FFTW3-backed transform backend.

Instance Method Summary collapse

Constructor Details

#initialize(fft_size) ⇒ FFTWBackend

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of FFTWBackend.

Parameters:

  • fft_size (Integer)


199
200
201
# File 'lib/vizcore/analysis/fft_processor.rb', line 199

def initialize(fft_size)
  @fft_size = fft_size
end

Instance Method Details

#transform(values) ⇒ Array<Complex>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • values (Array<Float>)

Returns:

  • (Array<Complex>)


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/vizcore/analysis/fft_processor.rb', line 205

def transform(values)
  input = FFI::MemoryPointer.new(:double, @fft_size)
  bins = (@fft_size / 2) + 1
  output = FFI::MemoryPointer.new(:double, bins * 2)
  input.write_array_of_double(values)

  plan = FFTWFFI.fftw_plan_dft_r2c_1d(@fft_size, input, output, FFTWFFI::ESTIMATE)
  raise RuntimeError, "fftw failed to create transform plan" if plan.null?

  FFTWFFI.fftw_execute(plan)
  output.read_array_of_double(bins * 2).each_slice(2).map do |real, imag|
    Complex(real, imag)
  end
ensure
  FFTWFFI.fftw_destroy_plan(plan) if plan && !plan.null?
end