class SPCore::DFT
Perform DFT
transforms, forward and inverse. @author James Tunnell
Public Class Methods
forward(input)
click to toggle source
@param [Array] input array of real values, representing the time domain
signal to be passed into the forward DFT.
# File lib/spcore/transforms/dft.rb, line 7 def self.forward input input_size = input.size raise ArgumentError, "input.size is not even" unless (input_size % 2 == 0) output_size = input_size output = Array.new(output_size) output.each_index do |k| sum = Complex(0.0) input.each_index do |n| a = TWO_PI * n * k / input_size sum += Complex(input[n] * Math::cos(a), -input[n] * Math::sin(a)) end output[k] = sum end return output end
inverse(input)
click to toggle source
@param [Array] input array of complex values, representing the frequency domain
signal obtained from the forward DFT.
# File lib/spcore/transforms/dft.rb, line 28 def self.inverse input input_size = input.size raise ArgumentError, "input.size is not even" unless (input_size % 2 == 0) output = Array.new(input_size) output_size = output.size output.each_index do |k| sum = Complex(0.0) input.each_index do |n| a = TWO_PI * n * k / input_size sum += Complex(input[n] * Math::cos(a), input[n] * Math::sin(a)) end output[k] = sum / output_size end return output end