Harmonic Spectrum Data

The Harmonic Spectrum Data object allows for processing of a vector representing the audio in the frequency domain after peak picking. This gives a sparse spectrum view.

Constructor

The HarmonicSpectrumData() has the following two constructors:

// Some Globals
var N = 1024;
var sample_rate = 44100.0;

// Creates a harmonicSpectrumData with no sample_rate defined
// Automatically defines a data size of 1024 elements
var harmonicSpectrumData = new HarmonicSpectrumData(N);

// Creates a harmonicSpectrumData with a sample_rate defined
// Automatically defines a data size of 1024 elements
var harmonicSpectrumData2 = new HarmonicSpectrumData(N,sample_rate);

Variables

Variable Name Method Get Set
Sample Rate this.sample_rate Returns sample rate Set the sample rate if sample_rate is undefined
Fundamental Frequency this.f0 Returns the f0 Set the f0
Length this.length Return the length of the vector Read only

Methods

General Methods

clearResult()

Clear the result object to an empty object

SpectrumData().clearResult();

Returns: Nothing

getData

Get the data store view (including both magnitudes and frequency arrays);

SpectrumData().getData();

Returns: Float64Array

zeroData

Fill the maginitude array with zeros.

SpectrumData().zeroData();

Returns: Nothing

copyDataFrom

Copy the data from a source array into the Object. src must be a defined array with at least one element. number defines the number of elements to copy from source, will be set to number=Math.min(number,Math.min(src.length, SpectrumData().length));. offset defines the starting point in the destination array. See Using the Object Oriented calls for more details.

SpectrumData().copyDataFrom(src);
SpectrumData().copyDataFrom(src, number);
SpectrumData().copyDataFrom(src, number, offset);

Returns: Nothing

duplicate

Duplicate the object with another SpectrumData object with the data elements copied. Does not copy the current results node.

SpectrumData().duplicate();

Returns: SpectrumData();

Features

The HarmonicSpectrumData() object includes all the features of the SpectrumData object and the PeakSpectrumData object.

All these functions return their computed features and store them in the results. Any intermediary results which are calculated are also stored.

Odd-Even ratio

Calculate the energy spread between the odd harmonics and even harmonics

value = HarmonicSpectrumData().odd_even_ratio();
HarmonicSpectrumData().result.odd_even_ratio = Number();

Noisiness

Calculate the relationship between the harmonic and inharmonic peaks. This function can only work if the HarmonicSpectrumData node was created by PeakSpectrumData::harmonic_spectrum().

Number() = HarmonicSpectrumData().noisiness();
HarmonicSpectrumData().result.odd_even_ratio = Number();
HarmonicSpectrumData().result.nonzero_count = Number();
// The parent node :
PeakSpectrumData().result.nonzero_count = Number();