Class: DSP::SpectralMoments

Inherits:
Data
  • Object
show all
Defined in:
lib/dsprb/spectral_moments.rb,
sig/dsprb.rbs

Constant Summary collapse

ENERGY_FLOOR =

Below this the band carries no measurable energy and the moments are undefined.

Returns:

  • (::Float)
1e-12
VARIANCE_FLOOR =

Returns:

  • (::Float)
1e-12
DEFAULT_LOW_HZ =

Fricative energy sits well above the voiced band, so the default window starts high.

Returns:

  • (::Float)
500.0
HIGH_MARGIN_HZ =

Keeps the anti-aliasing roll-off out of the measured band.

Returns:

  • (::Float)
200.0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#centroidObject (readonly)

Returns the value of attribute centroid

Returns:

  • (Object)

    the current value of centroid



4
5
6
# File 'lib/dsprb/spectral_moments.rb', line 4

def centroid
  @centroid
end

#kurtosisObject (readonly)

Returns the value of attribute kurtosis

Returns:

  • (Object)

    the current value of kurtosis



4
5
6
# File 'lib/dsprb/spectral_moments.rb', line 4

def kurtosis
  @kurtosis
end

#skewnessObject (readonly)

Returns the value of attribute skewness

Returns:

  • (Object)

    the current value of skewness



4
5
6
# File 'lib/dsprb/spectral_moments.rb', line 4

def skewness
  @skewness
end

#spreadObject (readonly)

Returns the value of attribute spread

Returns:

  • (Object)

    the current value of spread



4
5
6
# File 'lib/dsprb/spectral_moments.rb', line 4

def spread
  @spread
end

Class Method Details

.newSpectralMoments

Parameters:

  • centroid: (::Float)
  • spread: (::Float)
  • skewness: (::Float)
  • kurtosis: (::Float)

Returns:



338
# File 'sig/dsprb.rbs', line 338

def self.new: (centroid: ::Float, spread: ::Float, skewness: ::Float, kurtosis: ::Float) -> SpectralMoments

.of(power, sample_rate:, size:, low: DEFAULT_LOW_HZ, high: nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/dsprb/spectral_moments.rb', line 17

def self.of(power, sample_rate:, size:, low: DEFAULT_LOW_HZ, high: nil)
  ceiling = high || ((sample_rate / 2.0) - HIGH_MARGIN_HZ)
  frequencies, weights, total = collect(power, sample_rate, size, low, ceiling)
  return zero if total <= ENERGY_FLOOR

  centroid = frequencies.each_with_index.sum { |frequency, index| frequency * weights[index] } / total
  from_central_moments(centroid, central_moments(frequencies, weights, centroid, total))
end

.zeroSpectralMoments

Returns:



15
# File 'lib/dsprb/spectral_moments.rb', line 15

def self.zero = new(centroid: 0.0, spread: 0.0, skewness: 0.0, kurtosis: 0.0)

Instance Method Details

#to_h::Hash[::Symbol, ::Float]

Returns:

  • (::Hash[::Symbol, ::Float])


349
# File 'sig/dsprb.rbs', line 349

def to_h: () -> ::Hash[::Symbol, ::Float]