Module: Praat::FormantMethods

Included in:
Item, Root
Defined in:
lib/praat_formant.rb

Instance Method Summary collapse

Instance Method Details

#least_squares_formant(logarithmic = true) ⇒ Object

Returns the least squares fit of the formants log2 must be taken before least squares is calculated, or the negative slopes will be out of the domain of log2

logarithmic - if true, then the base-2 logarithm is taken before least

squares is calculated. Default: true.

Raises:

  • (NotImplementedError)


39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/praat_formant.rb', line 39

def least_squares_formant logarithmic = true
  raise NotImplementedError, "#least_squares_formant requries NMatrix" unless HAS_NMATRIX
  frames = map_formant_frequencies.flatten.to_nm([num_frames, num_formants]).each_column.map { |c|
    c = c.log2 if logarithmic
    if block_given? 
      c = yield c
    end
    x = NMatrix.ones(c.shape).hconcat(NMatrix.seq(c.shape))
    ((x.transpose.dot x).invert.dot(x.transpose)).dot(c)
  }.map(&:transpose)
  [self.frames.size, frames[0].vconcat(*frames[1..-1])]
end

#map_formant_frequenciesObject



19
20
21
# File 'lib/praat_formant.rb', line 19

def map_formant_frequencies
  map_frequencies :frames, :formants
end

#map_frequencies(frame_symbol, data_symbol) ⇒ Object

Method mapping some sort of data frequency to a frame frequency



13
14
15
16
17
# File 'lib/praat_formant.rb', line 13

def map_frequencies frame_symbol, data_symbol
  self.send(frame_symbol).map do |frame| 
    frame.send(data_symbol).map(&:frequency)
  end
end

#num_formantsObject



23
24
25
# File 'lib/praat_formant.rb', line 23

def num_formants
  self.maxnformants
end

#num_framesObject



27
28
29
# File 'lib/praat_formant.rb', line 27

def num_frames
  self.frames.size
end