API Reference
Fourier Transforms
AcousticMetrics.rfft!
— Functionrfft!(y, x, cache=nothing)
Calculate the real-input FFT of `x` and store the result in half-complex format in `y`.
Just a wrapper of `FFTW.r2r!(y, FFTW.R2HC)`. The `cache` argument is
optional and not used, and is included to keep the function signiture the
same as the method that takes `Vector`s of `Dual`s.
AcousticMetrics.irfft!
— Functionirfft!(y, x, cache=nothing)
Calculate the inverse FFT of `x` and store the result in in `y`, where `x` is in the half-complex format.
Just a wrapper of `FFTW.r2r!(y, FFTW.HC2R)`. The `cache` argument is
optional and not used, and is included to keep the function signiture the
same as the method that takes `Vector`s of `Dual`s.
Pressure Time History
AcousticMetrics.AbstractPressureTimeHistory
— TypeAbstractPressureTimeHistory{IsEven}
Supertype for a pressure time history, i.e., pressure as a function of time defined on evenly-spaced time samples.
The IsEven
parameter is a Bool
indicating if the length of the pressure time history is even or not.
AcousticMetrics.PressureTimeHistory
— TypePressureTimeHistory{IsEven} <: AbstractPressureTimeHistory{IsEven}
Pressure as a function of time defined on evenly-spaced time samples.
The IsEven
parameter is a Bool
indicating if the length of the pressure time history is even or not.
AcousticMetrics.pressure
— Functionpressure(pth::AbstractPressureTimeHistory)
Return a vector of pressures associated with a pressure time history.
AcousticMetrics.inputlength
— Functioninputlength(pth::AbstractPressureTimeHistory)
Return a number of pressure samples associated with a pressure time history.
inputlength(sm::AbstractNarrowbandSpectrum)
Return a number of pressure time samples associated with a narrowband spectrum.
This is also the length of the discrete Fourier transform associated with the spectrum in half-complex format.
AcousticMetrics.timestep
— Methodtimestep(pth::AbstractPressureTimeHistory)
Return the time step size dt
associated with a pressure time history.
AcousticMetrics.starttime
— Methodstarttime(pth::AbstractPressureTimeHistory)
Return the initial time t0
associated with a pressure time history.
AcousticMetrics.time
— Functiontime(pth::AbstractPressureTimeHistory)
Return a vector of times associated with a pressure time history.
Narrowband Metrics
AcousticMetrics.AbstractNarrowbandSpectrum
— TypeAbstractNarrowbandSpectrum{IsEven,IsTonal,Tel} <: AbstractVector{Tel}
Supertype for a generic narrowband acoustic metric which will behave as an immutable AbstractVector
of element type Tel
.
The IsEven
parameter is a Bool
indicating if the length of the spectrum is even or not, affecting how the Nyquist frequency is calculated. IsTonal
indicates how the acoustic energy is distributed through the frequency bands:
IsTonal == false
means the acoustic energy is assumed to be evenly distributed thoughout each bandIsTonal == true
means the acoustic energy is assumed to be concentrated at each band center
AcousticMetrics.halfcomplex
— Functionhalfcomplex(sm::AbstractNarrowbandSpectrum)
Return a vector of the discrete Fourier transform of the pressure time history in half-complex format.
See the FFTW docs for the definition of the halfcomplex format.
AcousticMetrics.timestep
— Methodtimestep(sm::AbstractNarrowbandSpectrum)
Return the time step size dt
associated with a narrowband spectrum.
AcousticMetrics.starttime
— Methodstarttime(sm::AbstractNarrowbandSpectrum)
Return the initial time t0
associated with a pressure time history.
AcousticMetrics.samplerate
— Functionsamplerate(sm::AbstractNarrowbandSpectrum)
Return the sample rate (aka the inverse of the time step size) associated with a narrowband spectrum.
AcousticMetrics.frequency
— Functionfrequency(sm::AbstractNarrowbandSpectrum)
Return a vector of frequencies associated with the narrowband spectrum.
The frequencies are calculated using the rfftfreq
function in the FFTW.jl package.
AcousticMetrics.frequencystep
— Functionfrequencystep(sm::AbstractNarrowbandSpectrum)
Return the frequency step size Δf
associated with the narrowband spectrum.
AcousticMetrics.istonal
— Functionistonal(sm::AbstractNarrowbandSpectrum)
Return true
if the spectrum is tonal, false
otherwise.
AcousticMetrics.PressureSpectrumAmplitude
— TypePressureSpectrumAmplitude{IsEven,IsTonal,Tel} <: AbstractNarrowbandSpectrum{IsEven,IsTonal,Tel}
Representation of acoustic pressure amplitude as a function of narrowband frequency.
The IsEven
parameter is a Bool
indicating if the length of the spectrum is even or not, affecting how the Nyquist frequency is calculated. The IsTonal
Bool
parameter, if true
, indicates the pressure spectrum is tonal and thus concentrated at discrete frequencies. If false
, the spectrum is assumed to be constant over each frequency band.
AcousticMetrics.PressureSpectrumPhase
— TypePressureSpectrumPhase{IsEven,IsTonal,Tel} <: AbstractNarrowbandSpectrum{IsEven,IsTonal,Tel}
Representation of acoustic pressure phase as a function of narrowband frequency.
The IsEven
parameter is a Bool
indicating if the length of the spectrum is even or not, affecting how the Nyquist frequency is calculated. The IsTonal
Bool
parameter, if true
, indicates the phase spectrum is tonal and thus concentrated at discrete frequencies. If false
, the spectrum is assumed to be constant over each frequency band.
AcousticMetrics.MSPSpectrumAmplitude
— TypeMSPSpectrumAmplitude{IsEven,IsTonal,Tel} <: AbstractNarrowbandSpectrum{IsEven,IsTonal,Tel}
Representation of mean-squared pressure amplitude as a function of narrowband frequency.
The IsEven
parameter is a Bool
indicating if the length of the spectrum is even or not, affecting how the Nyquist frequency is calculated. The IsTonal
Bool
parameter, if true
, indicates the mean-squared pressure spectrum is tonal and thus concentrated at discrete frequencies. If false
, the pressure spectrum is assumed to be constant over each frequency band.
AcousticMetrics.MSPSpectrumPhase
— TypeMSPSpectrumPhase
Alias for PressureSpectrumPhase
.
AcousticMetrics.PowerSpectralDensityAmplitude
— TypePowerSpectralDensityAmplitude{IsEven,Tel} <: AbstractNarrowbandSpectrum{IsEven,false,Tel}
Representation of acoustic power spectral density amplitude as a function of narrowband frequency.
The IsEven
parameter is a Bool
indicating if the length of the spectrum is even or not, affecting how the Nyquist frequency is calculated. As the power spectral density is not well-defined for tones, the IsTonal
parameter is always false
.
AcousticMetrics.PowerSpectralDensityPhase
— TypePowerSpectralDensityPhase
Alias for PressureSpectrumPhase
.
Proportional Bands and Proportional Band Spectra
AcousticMetrics.AbstractProportionalBands
— TypeAbstractProportionalBands{NO,LCU,TF} <: AbstractVector{TF}
Abstract type representing the exact proportional frequency bands with band fraction NO
and eltype
TF
.
The LCU
parameter can take one of three values:
:lower
: Thestruct
returns the lower edges of each frequency band.:center
: Thestruct
returns the center of each frequency band.:upper
: Thestruct
returns the upper edges of each frequency band.
AcousticMetrics.octave_fraction
— Functionoctave_fraction(bands::AbstractProportionalBands{NO}) where {NO}
Return NO
, the "octave fraction," e.g. 1
for octave bands, 3
for third-octave, 12
for twelfth-octave.
octave_fraction(pbs::AbstractProportionalBandSpectrum{NO}) where {NO}
Return NO
, the "octave fraction," e.g. 1
for octave bands, 3
for third-octave, 12
for twelfth-octave.
AcousticMetrics.lower_center_upper
— Functionlower_center_upper(bands::AbstractProportionalBands{NO,LCU,TF}) where {NO,LCU,TF}
Return LCU
, which can be either :lower
, :center
, :upper
, indicating if bands
represents the lower edges, centers, or upper edges of proportional bands, respectively.
AcousticMetrics.freq_scaler
— Functionfreq_scaler(bands::AbstractProportionalBands)
Return the factor each "standard" frequency band is scaled by.
For example, the approximate octave center bands include 1000 Hz, 2000 Hz, and 4000 Hz. If freq_scaler(bands) == 1.0
, then these frequencies would be unchanged. If freq_scaler(bands) == 1.5
, then bands
would include 1500 Hz, 3000 Hz, and 6000 Hz instead. If freq_scaler(bands) == 0.5
, then bands
would include 500 Hz, 1000 Hz, and 2000 Hz in place of 1000 Hz, 2000 Hz, and 4000 Hz.
freq_scaler(pbs::AbstractProportionalBandSpectrum)
Return the factor each "standard" frequency band associated with the proportional band spectrum pbs
is scaled by.
For example, the approximate octave center bands include 1000 Hz, 2000 Hz, and 4000 Hz. If freq_scaler(pbs) == 1.0
, then these frequencies would be unchanged. If freq_scaler(pbs) == 1.5
, then bands
would include 1500 Hz, 3000 Hz, and 6000 Hz instead. If freq_scaler(pbs) == 0.5
, then bands
would include 500 Hz, 1000 Hz, and 2000 Hz in place of 1000 Hz, 2000 Hz, and 4000 Hz.
AcousticMetrics.band_start
— Functionband_start(bands::AbstractProportionalBands)
Return the standard band index number for the first band in bands
.
For example, it happens that the approximate octave center bands includes 1000 Hz, and that particular band is numbered 10
. So if the first band contained in bands
happens to be 1000 Hz (and freq_scaler(bands) == 1.0
), then band_start(bands) == 10
. Not particularly useful to a user.
AcousticMetrics.band_end
— Functionband_end(bands::AbstractProportionalBands)
Return the standard band index number for the last band in bands
.
For example, it happens that the approximate octave center bands includes 1000 Hz, and that particular band is numbered 10
. So if the last band contained in bands
happens to be 1000 Hz (and freq_scaler(bands) == 1.0
), then band_end(bands) == 10
. Not particularly useful to a user.
AcousticMetrics.lower_bands
— Functionlower_bands(TBands::Type{<:AbstractProportionalBands{NO}}, fstart::TF, fend::TF, scaler=1) where {NO,TF}
Construct and return the lower edges of the proportional bands TBands
, scaled by scaler
, that would fully encompass a frequency range beginning with fstart
and ending with fend
.
lowerbands(bands::ExactProportionalBands{NO,LCU,TF}, scaler=freqscaler(bands)) where {NO,TF}
Construct and return the lower edges of the proportional bands bands
scaled by scaler
.
lowerbands(bands::ApproximateThirdOctaveBands{LCU,TF}, scaler=freqscaler(bands)) where {LCU,TF}
Construct and return the lower edges of the proportional bands bands
scaled by scaler
.
lower_bands(bands::ApproximateOctaveBands{LCU,TF}, scaler=freq_scaler(bands))
Construct and return the lower edges of the proportional bands bands
scaled by scaler
.
lower_bands(pbs::AbstractProportionalBandSpectrum)
Return the lower edges of the proportional bands associated with the proportional band spectrum pbs
.
AcousticMetrics.upper_bands
— Functionupper_bands(TBands::Type{<:AbstractProportionalBands{NO}}, fstart::TF, fend::TF, scaler=1) where {NO,TF}
Construct and return the upper edges of the proportional bands TBands
, scaled by scaler
, that would fully encompass a frequency range beginning with fstart
and ending with fend
.
upperbands(bands::ExactProportionalBands{NO,LCU,TF}, scaler=freqscaler(bands)) where {NO,TF}
Construct and return the upper edges of the proportional bands bands
scaled by scaler
.
upperbands(bands::ApproximateThirdOctaveBands{LCU,TF}, scaler=freqscaler(bands)) where {LCU,TF}
Construct and return the upper edges of the proportional bands bands
scaled by scaler
.
upper_bands(bands::ApproximateOctaveBands{LCU,TF}, scaler=freq_scaler(bands))
Construct and return the upper edges of the proportional bands bands
scaled by scaler
.
upper_bands(pbs::AbstractProportionalBandSpectrum)
Return the upper edges of the proportional bands associated with the proportional band spectrum pbs
.
AcousticMetrics.center_bands
— Functioncenter_bands(TBands::Type{<:AbstractProportionalBands{NO}}, fstart::TF, fend::TF, scaler=1) where {NO,TF}
Construct and return the centers of the proportional bands TBands
, scaled by scaler
, that would fully encompass a frequency range beginning with fstart
and ending with fend
.
centerbands(bands::ExactProportionalBands{NO,LCU,TF}, scaler=freqscaler(bands)) where {NO,TF}
Construct and return the centers of the proportional bands bands
scaled by scaler
.
centerbands(bands::ApproximateThirdOctaveBands{LCU,TF}, scaler=freqscaler(bands)) where {LCU,TF}
Construct and return the centers of the proportional bands bands
scaled by scaler
.
center_bands(bands::ApproximateOctaveBands{LCU,TF}, scaler=freq_scaler(bands))
Construct and return the centers of the proportional bands bands
scaled by scaler
.
center_bands(pbs::AbstractProportionalBandSpectrum)
Return the centers of the proportional bands associated with the proportional band spectrum pbs
.
AcousticMetrics.cband_number
— Functioncband_number(bands::AbstractProportionalBands, fc)
Return the standard band index number of the band with center frequency fc
for proportional bands bands
.
For example, if bands
is a subtype of ApproximateOctaveBands
and freq_scaler(bands) == 1.0
, then cband_number(bands, 1000.0) == 10
.
AcousticMetrics.ExactProportionalBands
— TypeExactProportionalBands{NO,LCU,TF} <: AbstractProportionalBands{NO,LCU,TF}
Representation of the exact proportional frequency bands with band fraction NO
and eltype
TF
.
The LCU
parameter can take one of three values:
:lower
: Thestruct
returns the lower edges of each frequency band.:center
: Thestruct
returns the center of each frequency band.:upper
: Thestruct
returns the upper edges of each frequency band.
AcousticMetrics.ExactOctaveCenterBands
— TypeExactOctaveCenterBands{TF}
Alias for ExactProportionalBands{1,:center,TF}
AcousticMetrics.ExactOctaveLowerBands
— TypeExactOctaveLowerBands{TF}
Alias for ExactProportionalBands{1,:lower,TF}
AcousticMetrics.ExactOctaveUpperBands
— TypeExactOctaveUpperBands{TF}
Alias for ExactProportionalBands{1,:upper,TF}
AcousticMetrics.ExactThirdOctaveCenterBands
— TypeExactThirdOctaveCenterBands{TF}
Alias for ExactProportionalBands{3,:center,TF}
AcousticMetrics.ExactThirdOctaveLowerBands
— TypeExactThirdOctaveLowerBands{TF}
Alias for ExactProportionalBands{3,:lower,TF}
AcousticMetrics.ExactThirdOctaveUpperBands
— TypeExactThirdOctaveUpperBands{TF}
Alias for ExactProportionalBands{3,:upper,TF}
AcousticMetrics.ApproximateThirdOctaveBands
— TypeApproximateThirdOctaveBands{LCU,TF} <: AbstractProportionalBands{3,LCU,TF}
Representation of the approximate third-octave proportional frequency bands with eltype
TF
.
The LCU
parameter can take one of three values:
:lower
: Thestruct
returns the lower edges of each frequency band.:center
: Thestruct
returns the center of each frequency band.:upper
: Thestruct
returns the upper edges of each frequency band.
AcousticMetrics.ApproximateThirdOctaveCenterBands
— TypeApproximateThirdOctaveCenterBands{TF}
Alias for ApproximateThirdOctaveBands{:center,TF}
AcousticMetrics.ApproximateThirdOctaveLowerBands
— TypeApproximateThirdOctaveLowerBands{TF}
Alias for ApproximateThirdOctaveBands{:lower,TF}
AcousticMetrics.ApproximateThirdOctaveUpperBands
— TypeApproximateThirdOctaveUpperBands{TF}
Alias for ApproximateThirdOctaveBands{:upper,TF}
AcousticMetrics.ApproximateOctaveBands
— TypeApproximateOctaveBands{LCU,TF} <: AbstractProportionalBands{1,LCU,TF}
Representation of the approximate octave proportional frequency bands with eltype
TF
.
The LCU
parameter can take one of three values:
:lower
: Thestruct
returns the lower edges of each frequency band.:center
: Thestruct
returns the center of each frequency band.:upper
: Thestruct
returns the upper edges of each frequency band.
AcousticMetrics.ApproximateOctaveCenterBands
— TypeApproximateOctaveCenterBands{TF}
Alias for ApproximateOctaveBands{:center,TF}
AcousticMetrics.ApproximateOctaveLowerBands
— TypeApproximateOctaveLowerBands{TF}
Alias for ApproximateOctaveBands{:lower,TF}
AcousticMetrics.ApproximateOctaveUpperBands
— TypeApproximateOctaveUpperBands{TF}
Alias for ApproximateOctaveBands{:upper,TF}
AcousticMetrics.AbstractProportionalBandSpectrum
— TypeAbstractProportionalBandSpectrum{NO,TF} <: AbstractVector{TF}
Abstract type representing a proportional band spectrum with band fraction NO
and eltype
TF
.
AcousticMetrics.has_observer_time
— Functionhas_observer_time(pbs::AbstractProportionalBandSpectrum)
Return true
if the proportional band spectrum is defined to exist over a limited time, false
otherwise.
AcousticMetrics.observer_time
— Functionobserver_time(pbs::AbstractProportionalBandSpectrum)
Return the observer time at which the proportional band spectrum is defined to exist.
AcousticMetrics.timestep
— Methodtimestep(pbs::AbstractProportionalBandSpectrum)
Return the time range over which the proportional band spectrum is defined to exist.
AcousticMetrics.amplitude
— Functionamplitude(pbs::AbstractProportionalBandSpectrum)
Return the underlying Vector
containing the proportional band spectrum amplitudes contained in pbs
.
AcousticMetrics.time_period
— Functiontime_period(pbs::AbstractArray{<:AbstractProportionalBandSpectrum})
Find the period of time over which the collection of proportional band spectrum pbs
exists.
AcousticMetrics.time_scaler
— Functiontime_scaler(pbs::AbstractProportionalBandSpectrum{NO,TF}, period)
Find the scaling factor appropriate to multiply the proportional band spectrum pbs
by that accounts for the duration of time the spectrum exists.
This is used when combining multiple proportional band spectra with the combine function.
AcousticMetrics.LazyNBProportionalBandSpectrum
— TypeLazyNBProportionalBandSpectrum{NO,IsTonal,TF,TAmp,TBandsC}
Lazy representation of a proportional band spectrum with octave fraction NO
and eltype
TF
constructed from a narrowband (NB
) spectrum.
IsTonal
indicates how the acoustic energy is distributed through the narrow frequency bands:
IsTonal == false
means the acoustic energy is assumed to be evenly distributed thoughout each bandIsTonal == true
means the acoustic energy is assumed to be concentrated at each band center
AcousticMetrics.frequency_nb
— Functionfrequency_nb(pbs::LazyNBProportionalBandSpectrum)
Return the narrowband frequencies associated with the underlying narrowband spectrum contained in pbs
.
AcousticMetrics.lazy_pbs
— Functionlazy_pbs(pbs, cbands::AbstractProportionalBands{NO,:center})
Construct a lazy proportional band spectrum on proportional center bands cbands
using the proportional band spectrum pbs
.
AcousticMetrics.ProportionalBandSpectrum
— TypeProportionalBandSpectrum{NO,TF,TPBS,TBandsL,TBandsC,TBandsU}
Representation of a proportional band spectrum with octave fraction NO
and eltype
TF
.
AcousticMetrics.LazyPBSProportionalBandSpectrum
— TypeLazyPBSProportionalBandSpectrum{NO,TF} <: AbstractProportionalBandSpectrum{NO,TF}
Lazy representation of a proportional band spectrum with octave fraction NO
and eltype
TF
constructed from a different proportional band spectrum.
AcousticMetrics.ProportionalBandSpectrumWithTime
— TypeProportionalBandSpectrumWithTime{NO,TF,TPBS,TBandsC,TTime,TDTime}
Representation of a proportional band spectrum with octave fraction NO
and eltype
TF
, but with an observer time.
AcousticMetrics.combine
— Functioncombine(pbs::AbstractArray{<:AbstractProportionalBandSpectrum}, outcbands::AbstractProportionalBands{NO,:center}, time_axis=1) where {NO}
Combine each input proportional band spectrum of pbs
into one output proportional band spectrum using the proportional center bands indicated by outcbands
.
time_axis
is an integer indicating the axis of the pbs
array along which time varies. For example, if time_axis == 1
and pbs
is a three-dimensional array, then apth[:, i, j]
would be proportional band spectrum of source i
, j
for all time. But if time_axis == 3
, then pbs[i, j, :]
would be the proportional band spectrum of source i
, j
for all time.
Weighting
AcousticMetrics.W_A
— FunctionW_A(f::AbstractFloat)
Calculate the A-weighting factor for a frequency f
in Hertz.
Taken from the ANOPP2 Acoustics Analysis API Reference Manual.
Integrated Metrics
AcousticMetrics.OASPL
— FunctionOASPL(ap::AbstractPressureTimeHistory)
Return the overall sound pressure level of a pressure time history.
OASPL(ap::AbstractNarrowbandSpectrum)
Return the overall sound pressure level of a narrowband spectrum.