FreqSpectrum:
Filter:
SignalBox/Classes (extension) | Math

FreqSpectrum
ExtensionExtension

Spectral processing

Description

A FreqSpectrum represents a sampled function in the frequency domain, in a polar form.

Class Methods

.new

Create a new instance with the given magnitude and phase.

Arguments:

magnitude

Frequency domain magnitude. If nil set to 1.

phase

Frequency domain phase. If nil set to 0.

.newComplex

Create a new instance given a spectrum in complex form.

.logShelf

Create a new Array whose slots are filled with linearly spaced magnitudes to create a log shelf filter.1 See also: Signal: *logShelf.

Arguments:

size

The size of the spectrum to return.

freq0

The frequeny, at which to begin transition from gainDC to gainNy, in Hz.

freq1

The frequeny, at which to end transition from gainDC to gainNy, in Hz.

gainDC

The gain at DC, in dB.

gainNy

The gain at Nyquist, in dB.

sampleRate

The sample rate, in Hz.

.powerLaw

Return a power-law spectrum. Magnitude at Nyquist is normalized to 1.

Arguments:

size

The size of the spectrum to return.

beta

Power spectral density.

colorbetadB / octave
brown2-6
pink1-3
white00
blue-1+3
violet-2+6

Instance Methods

.size

FreqSpectrum size.

Frequeny

.freqs

Coefficient frequencies.

.ks

Coefficient numbers.

.averageFreq

Energy weighted average frequency.

.bandwidth

Return bandwidth, in Hz.

Arguments:

fraction

If < 1.0, return fractional power containment bandwidth.

If nil, return equivalent bandwidth.

sampleRate

The sample rate, in Hz.

Magnitude & Energy

.magnitude

Set or return the magnitude.

.peakMagnitude

Return the peak magnitude.

.averageMagnitude

Return energy weighted average magnitude.

Arguments:

mindb

a minimum value in dB to clip amplitude response to. Prevents singularities.

.rho

Synonym for -magnitude

.energyDensity

Return the energy density.

.totalEnergy

Return the total energy.

.rms

Return the RMS.

.scale

Scale the magnitude in place.

.normalize

Normalize the magnitude in place to 1.

.allpass

Reset the magnitude in place to 1.

Phase & Delay

.phase

Set or return the phase.

.theta

Synonym for -phase

.angle

Synonym for -phase

.neg

Add pi to phase.

.invert

Add pi to phase in place.

.rotatePhase

Rotate the phase by a value in radians, in place. See also Signal: -rotatePhase.

.rotateWave

Rotate the time domain waveform by a value in radians, in place. See also Signal: -rotateWave.

.principalPhase

Return a spectrum with phase wrapped, preserving the magnitude, in place. See also -continuousPhase.

.continuousPhase

Return a spectrum with phase unwrapped, preserving the magnitude, in place.2 See also -principalPhase.

Arguments:

groupDelay

group delay analysis, in samples.

.linearPhase

Return a linear phase spectrum, preserving the magnitude, in place. See also Signal: -linearPhase.

Arguments:

sym

a Boolean indicating whether the window is symmetric or periodic. Default is false.

.minimumPhase

Return a minimum phase spectrum, preserving the magnitude, in place.3 See also Signal: -minimumPhase.

Arguments:

mindb

a minimum value in dB to clip amplitude response to. Reduces time aliasing.

.gaussianPhase

Return a gaussian noise phase spectrum, preserving the magnitude, in place. See also Signal: -gaussianPhase.

.phaseDelay

Return phase delay analysis, in samples.

NOTE: Measure at DC is returned as the mean of the delay at k = +/-1.
WARNING: For correct analysis, phase should be continuous.

.groupDelay

Return group delay analysis, in samples.4

Arguments:

mindb

a minimum value in dB to clip amplitude response to. Prevents singularities.

NOTE: If set to -inf, returns group delay via central fininte difference, assuming phase is continuous.5

.phaseOffset

Return phase offset analysis, aka intercept phase, in radians.6

WARNING: For correct analysis, phase should be continuous.

Arguments:

mindb

a minimum value in dB to clip amplitude response to. Prevents singularities.

NOTE: If set to -inf, returns group delay via central fininte difference, assuming phase is continuous. See also -groupDelay
sampleRate

The sample rate, in Hz.

.averagePhaseDelay

Return energy weighted average phase delay analysis, in samples. See also -phaseDelay

WARNING: For correct analysis, phase should be continuous.

.averageGroupDelay

Return energy weighted average group delay analysis, in samples. See also -groupDelay

Arguments:

mindb

a minimum value in dB to clip amplitude response to. Prevents singularities.

NOTE: If set to -inf, returns group delay via central fininte difference, assuming phase is continuous.

.averagePhaseOffset

Return energy weighted average phase offset analysis, aka intercept phase, in radians. See also -phaseOffset

WARNING: For correct analysis, phase should be continuous.

Arguments:

mindb

a minimum value in dB to clip amplitude response to. Prevents singularities.

NOTE: If set to -inf, returns group delay via central fininte difference, assuming phase is continuous. See also -groupDelay
sampleRate

The sample rate, in Hz.

Conversion & Complex

.asPolar

Return Polar.

.asComplex

Return Complex.

.real

Return the real part of the complex spectrum.

.imag

Return the imaginary part of the complex spectrum.

Examples

TBD

[1] - Baird, J; Jackson, B; and D McGrath. “Raised Cosine Equalization Utilizing Log Scale Filter Synthesis.“ 117th Audio Engineering Society Convention, San Francisco, USA. October 2004. Permalink: http://www.aes.org/e-lib/browse.cfm?elib=12914
[2] - Panzer, J; and L Ferekidis. “The Use of Continuous Phase for Interpolation, Smoothing and Forming Mean Values of Complex Frequency Response Curves.” 116th Audio Engineering Society Convention, Berlin, Germany. May 2004. Permalink: http://www.aes.org/e-lib/browse.cfm?elib=12652
[3] - Damera-Venkata, N, and B.L Evans. “Optimal Design of Real and Complex Minimum Phase Digital FIR Filters.” 1999 IEEE International Conference on Acoustics, Speech, and Signal Processing. Proceedings. ICASSP99 (Cat. No.99CH36258), vol. 3, 1999, pp. 1145–1148 vol.3.
[4] - Smith, J.O. "Numerical Computation of Group Delay", in Introduction to Digital Filters with Audio Applications, https://ccrma.stanford.edu/~jos/filters/Numerical_Computation_Group_Delay.html, online book, September 2007 edition, accessed 16 July 2019.
[5] - Boashash, B. “Estimating and Interpreting the Instantaneous Frequency of a Signal. II. Algorithms and Applications.” Proceedings of the IEEE, vol. 80, no. 4, 1992, pp. 540–568.
[6] - Preis, D. "Phase Distortion and Phase Equalization in Audio Signal Processing—A Tutorial Review", Journal Audio Engineering Society, vol. 30, no. 11, 1982, pp. 774-794. Permalink: http://www.aes.org/e-lib/browse.cfm?elib=3810