Peak Spectrum Data

The Peak 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.


The PeakSpectrumData() has the following two constructors:

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

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

// Creates a peakSpectrumData with a sample_rate defined
// Automatically defines a data size of 1024 elements
var peakSpectrumData2 = new PeakSpectrumData(N,sample_rate);


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


General Methods


Clear the result object to an empty object


Returns: Nothing


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


Returns: Float64Array


Fill the maginitude array with zeros.


Returns: Nothing


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, number);
SpectrumData().copyDataFrom(src, number, offset);

Returns: Nothing


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


Returns: SpectrumData();


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

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

Spectral Inharmonicity

Calculate the balance of the spectrum between peaks related to the fundamental and those not related. The fundamental frequency must have been set before calling this function.

value = PeakSpectrumData().spectral_inharmonicity();
PeakSpectrumData().result.spectral_inharmonicity = Number();

Harmonic Spectrum

Return a HarmonicSpectrum() object containing the peaks only related to the fundamental frequency. If threshold is undefined then an error is thrown. If the f0 fundamental has not been set then an error is thrown.

value = PeakSpectrumData().harmonic_spectrum(threshold);
PeakSpectrumData().result.harmonic_spectrum = HarmonicSpectrum();