# API Reference

`AcousticMetrics.AbstractNarrowbandSpectrum`

— Type`AbstractNarrowbandSpectrum{IsEven,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.

`AcousticMetrics.AbstractPressureTimeHistory`

— Type`AbstractPressureTimeHistory{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.AbstractProportionalBands`

— Type`AbstractProportionalBands{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`

: The`struct`

returns the lower edges of each frequency band.`:center`

: The`struct`

returns the center of each frequency band.`:upper`

: The`struct`

returns the upper edges of each frequency band.

`AcousticMetrics.ApproximateOctaveBands`

— Type`ApproximateOctaveBands{LCU,TF} <: AbstractProportionalBands{3,LCU,TF}`

Representation of the approximate octave proportional frequency bands with `eltype`

`TF`

.

The `LCU`

parameter can take one of three values:

`:lower`

: The`struct`

returns the lower edges of each frequency band.`:center`

: The`struct`

returns the center of each frequency band.`:upper`

: The`struct`

returns the upper edges of each frequency band.

`AcousticMetrics.ApproximateOctaveBands`

— Method`ApproximateOctaveBands{LCU,TF}(bstart::Int, bend::Int)`

Construct an `ApproximateOctaveBands`

with `eltype`

`TF`

encomposing band numbers from `bstart`

to `bend`

.

`TF`

defaults to `Float64`

.

`AcousticMetrics.ApproximateOctaveBands`

— Method`ApproximateOctaveBands{LCU}(fstart::TF, fend::TF)`

Construct an `ApproximateOctaveBands`

with `eltype`

`TF`

encomposing the bands needed to completly extend over minimum frequency `fstart`

and maximum frequency `fend`

.

`AcousticMetrics.ApproximateThirdOctaveBands`

— Type`ApproximateThirdOctaveBands{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`

: The`struct`

returns the lower edges of each frequency band.`:center`

: The`struct`

returns the center of each frequency band.`:upper`

: The`struct`

returns the upper edges of each frequency band.

`AcousticMetrics.ApproximateThirdOctaveBands`

— Method`ApproximateThirdOctaveBands{LCU,TF}(bstart::Int, bend::Int)`

Construct an `ApproximateThirdOctaveBands`

with `eltype`

`TF`

encomposing band numbers from `bstart`

to `bend`

.

`TF`

defaults to `Float64`

.

`AcousticMetrics.ApproximateThirdOctaveBands`

— Method`ApproximateThirdOctaveBands{LCU}(fstart::TF, fend::TF)`

Construct an `ApproximateThirdOctaveBands`

with `eltype`

`TF`

encomposing the bands needed to completly extend over minimum frequency `fstart`

and maximum frequency `fend`

.

`AcousticMetrics.ExactOctaveCenterBands`

— Type`ExactOctaveCenterBands{TF}`

Alias for ExactProportionalBands{1,:center,TF}

`AcousticMetrics.ExactOctaveLowerBands`

— Type`ExactOctaveLowerBands{TF}`

Alias for ExactProportionalBands{1,:lower,TF}

`AcousticMetrics.ExactOctaveUpperBands`

— Type`ExactOctaveUpperBands{TF}`

Alias for ExactProportionalBands{1,:upper,TF}

`AcousticMetrics.ExactProportionalBands`

— Type`ExactProportionalBands{NO,LCU}(TF=Float64, bstart::Int, bend::Int)`

Construct an `ExactProportionalBands`

with `eltype`

`TF`

encomposing band numbers from `bstart`

to `bend`

.

`AcousticMetrics.ExactProportionalBands`

— Method`ExactProportionalBands{NO,LCU}(fstart::TF, fend::TF)`

Construct an `ExactProportionalBands`

with `eltype`

`TF`

encomposing the bands needed to completly extend over minimum frequency `fstart`

and maximum frequency `fend`

.

`AcousticMetrics.ExactThirdOctaveCenterBands`

— Type`ExactThirdOctaveCenterBands{TF}`

Alias for ExactProportionalBands{3,:center,TF}

`AcousticMetrics.ExactThirdOctaveLowerBands`

— Type`ExactThirdOctaveLowerBands{TF}`

Alias for ExactProportionalBands{3,:lower,TF}

`AcousticMetrics.ExactThirdOctaveUpperBands`

— Type`ExactThirdOctaveUpperBands{TF}`

Alias for ExactProportionalBands{3,:upper,TF}

`AcousticMetrics.MSPSpectrumAmplitude`

— Type`MSPSpectrumAmplitude(pth::AbstractPressureTimeHistory, hc=similar(pressure(pth)))`

Construct a narrowband spectrum of the mean-squared pressure amplitude from a pressure time history.

The optional argument `hc`

will be used to store the discrete Fourier transform of the pressure time history, and should have length of `inputlength(pth)`

.

`AcousticMetrics.MSPSpectrumAmplitude`

— Type`MSPSpectrumAmplitude(hc, dt, t0=zero(dt))`

Construct a narrowband spectrum of the mean-squared pressure amplitude from the discrete Fourier transform in half-complex format `hc`

, time step size `dt`

, and initial time `t0`

.

`AcousticMetrics.MSPSpectrumAmplitude`

— Type`MSPSpectrumAmplitude{IsEven,Tel} <: AbstractNarrowbandSpectrum{IsEven,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.

`AcousticMetrics.MSPSpectrumAmplitude`

— Method`MSPSpectrumAmplitude(sm::AbstractNarrowbandSpectrum)`

Construct a narrowband spectrum of the mean-squared pressure amplitude from another narrowband spectrum.

`AcousticMetrics.MSPSpectrumPhase`

— Type`MSPSpectrumPhase`

Alias for `PressureSpectrumPhase`

.

`AcousticMetrics.PowerSpectralDensityAmplitude`

— Type`PressureSpectrumAmplitude(pth::AbstractPressureTimeHistory, hc=similar(pressure(pth)))`

Construct a narrowband spectrum of the power spectral density amplitude from a pressure time history.

The optional argument `hc`

will be used to store the discrete Fourier transform of the pressure time history, and should have length of `inputlength(pth)`

.

`AcousticMetrics.PowerSpectralDensityAmplitude`

— Type`PowerSpectralDensityAmplitude(hc, dt, t0=zero(dt))`

Construct a narrowband spectrum of the power spectral density amplitude from the discrete Fourier transform in half-complex format `hc`

, time step size `dt`

, and initial time `t0`

.

`AcousticMetrics.PowerSpectralDensityAmplitude`

— Type`PowerSpectralDensityAmplitude{IsEven,Tel} <: AbstractNarrowbandSpectrum{IsEven,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.

`AcousticMetrics.PowerSpectralDensityAmplitude`

— Method`PressureSpectrumAmplitude(sm::AbstractNarrowbandSpectrum)`

Construct a narrowband spectrum of the power spectral density amplitude from another narrowband spectrum.

`AcousticMetrics.PowerSpectralDensityPhase`

— Type`PowerSpectralDensityPhase`

Alias for `PressureSpectrumPhase`

.

`AcousticMetrics.PressureSpectrumAmplitude`

— Type`PressureSpectrumAmplitude(pth::AbstractPressureTimeHistory, hc=similar(pressure(pth)))`

Construct a narrowband spectrum of the pressure amplitude from a pressure time history.

The optional argument `hc`

will be used to store the discrete Fourier transform of the pressure time history, and should have length of `inputlength(pth)`

.

`AcousticMetrics.PressureSpectrumAmplitude`

— Type`PressureSpectrumAmplitude(hc, dt, t0=zero(dt))`

Construct a narrowband spectrum of the pressure amplitude from the discrete Fourier transform in half-complex format `hc`

, time step size `dt`

, and initial time `t0`

.

`AcousticMetrics.PressureSpectrumAmplitude`

— Type`PressureSpectrumAmplitude{IsEven,Tel} <: AbstractNarrowbandSpectrum{IsEven,Tel}`

Representation of acoustic pressure amplitude as a function of narrowband frequency.

`IsEven`

parameter is a `Bool`

indicating if the length of the spectrum is even or not, affecting how the Nyquist frequency is calculated.

`AcousticMetrics.PressureSpectrumAmplitude`

— Method`PressureSpectrumAmplitude(sm::AbstractNarrowbandSpectrum)`

Construct a narrowband spectrum of the pressure amplitude from another narrowband spectrum.

`AcousticMetrics.PressureSpectrumPhase`

— Type`PressureSpectrumPhase(pth::AbstractPressureTimeHistory, hc=similar(pressure(pth)))`

Construct a narrowband spectrum of the pressure phase from a pressure time history.

`hc`

will be used to store the discrete Fourier transform of the pressure time history, and should have length of `inputlength(pth)`

.

`AcousticMetrics.PressureSpectrumPhase`

— Type`PressureSpectrumPhase(hc, dt, t0=zero(dt))`

Construct a narrowband spectrum of the pressure phase from the discrete Fourier transform in half-complex format `hc`

, time step size `dt`

, and initial time `t0`

.

`AcousticMetrics.PressureSpectrumPhase`

— Type`PressureSpectrumPhase{IsEven,Tel} <: AbstractNarrowbandSpectrum{IsEven,Tel}`

Representation of acoustic pressure phase as a function of narrowband frequency.

`IsEven`

parameter is a `Bool`

indicating if the length of the spectrum is even or not, affecting how the Nyquist frequency is calculated.

`AcousticMetrics.PressureSpectrumPhase`

— Method`PressureSpectrumPhase(sm::AbstractNarrowbandSpectrum)`

Construct a narrowband spectrum of the pressure phase from another narrowband spectrum.

`AcousticMetrics.PressureTimeHistory`

— Type`PressureTimeHistory(p, dt, t0=zero(dt))`

Construct a `PressureTimeHistory`

from a vector of pressures `p`

, time spacing `dt`

, and initial time `t0`

.

`AcousticMetrics.PressureTimeHistory`

— Type`PressureTimeHistory(sm::AbstractNarrowbandSpectrum, p=similar(halfcomplex(sm)))`

Construct a pressure time history from a narrowband spectrum `sm`

.

The optional `p`

argument will be used to store the pressure vector of the pressure time history, and should have length `inputlength(sm)`

.

`AcousticMetrics.PressureTimeHistory`

— Type`PressureTimeHistory{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.ProportionalBandSpectrum`

— Type`ProportionalBandSpectrum{NO,TF,TAmp,TBandsL,TBandsC,TBandsU}`

Representation of a proportional band spectrum with octave fraction `NO`

and `eltype`

`TF`

.

`AcousticMetrics.ProportionalBandSpectrum`

— Method`ProportionalBandSpectrum(TBands::Type{<:AbstractProportionalBands}, sm::AbstractNarrowbandSpectrum)`

Construct a `ProportionalBandSpectrum`

using a proportional band `TBands`

and narrowband spectrum `sm`

.

`AcousticMetrics.OASPL`

— Method`OASPL(ap::AbstractNarrowbandSpectrum)`

Return the overall sound pressure level of a narrowband spectrum.

`AcousticMetrics.OASPL`

— Method`OASPL(ap::AbstractPressureTimeHistory)`

Return the overall sound pressure level of a pressure time history.

`AcousticMetrics.W_A`

— Method`W_A(f::AbstractFloat)`

Calculate the A-weighting factor for a frequency `f`

in Hertz.

Taken from the ANOPP2 Acoustics Analysis API Reference Manual.

`AcousticMetrics.dft_hc2r`

— Method`dft_hc2r(x::AbstractVector)`

Calculate the inverse discrete Fourier transform of a real-input DFT.

This is the inverse of `dft_r2hc`

, except for a factor of `N`

, where `N`

is the length of the input (and output), since FFTW computes an "unnormalized" FFT.

See http://www.fftw.org/fftw3*doc/The-1d-Real*002ddata-DFT.html#The-1d-Real*002ddata-DFT and http://www.fftw.org/fftw3*doc/The-Halfcomplex_002dformat-DFT.html for details.

Only use this for checking the derivatives of the FFT routines (should work fine, just slow).

`AcousticMetrics.dft_r2hc`

— Method`dft_r2hc(x::AbstractVector)`

Calculate the real-input discrete Fourier transform, returning the result in the "half-complex" format.

See http://www.fftw.org/fftw3*doc/The-1d-Real*002ddata-DFT.html#The-1d-Real*002ddata-DFT and http://www.fftw.org/fftw3*doc/The-Halfcomplex_002dformat-DFT.html for details.

Only use this for checking the derivatives of the FFT routines (should work fine, just slow).

`AcousticMetrics.frequency`

— Method`frequency(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.halfcomplex`

— Method`halfcomplex(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.inputlength`

— Method`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.inputlength`

— Method`inputlength(pth::AbstractPressureTimeHistory)`

Return a number of pressure samples associated with a pressure time history.

`AcousticMetrics.irfft!`

— Function```
irfft!(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.
```

`AcousticMetrics.pressure`

— Method`pressure(pth::AbstractPressureTimeHistory)`

Return a vector of pressures associated with a pressure time history.

`AcousticMetrics.rfft!`

— Function```
rfft!(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.samplerate`

— Method`samplerate(sm::AbstractNarrowbandSpectrum)`

Return the sample rate (aka the inverse of the time step size) associated with a narrowband spectrum.

`AcousticMetrics.starttime`

— Method`starttime(sm::AbstractNarrowbandSpectrum)`

Return the initial time `t0`

associated with a pressure time history.

`AcousticMetrics.starttime`

— Method`starttime(pth::AbstractPressureTimeHistory)`

Return the initial time `t0`

associated with a pressure time history.

`AcousticMetrics.time`

— Method`time(pth::AbstractPressureTimeHistory)`

Return a vector of times associated with a pressure time history.

`AcousticMetrics.timestep`

— Method`timestep(sm::AbstractNarrowbandSpectrum)`

Return the time step size `dt`

associated with a narrowband spectrum.

`AcousticMetrics.timestep`

— Method`timestep(pth::AbstractPressureTimeHistory)`

Return the time step size `dt`

associated with a pressure time history.

`Base.getindex`

— Method`Base.getindex(bands::ApproximateOctaveBands{LCU}, i::Int) where {LCU}`

Return the lower, center, or upper frequency (depending on the value of `LCU`

) associated with the `i`

-th proportional band frequency covered by `bands`

.

`Base.getindex`

— Method`Base.getindex(bands::ApproximateThirdOctaveBands{LCU}, i::Int) where {LCU}`

Return the lower, center, or upper frequency (depending on the value of `LCU`

) associated with the `i`

-th proportional band frequency covered by `bands`

.

`Base.getindex`

— Method`Base.getindex(bands::ExactProportionalBands{NO,LCU}, i::Int) where {NO,LCU}`

Return the lower, center, or upper frequency (depending on the value of `LCU`

) associated with the `i`

-th proportional band frequency covered by `bands`

.

`Base.getindex`

— Method`Base.getindex(pbs::ProportionalBandSpectrum, i::Int)`

Return the proportional band spectrum amplitude for the `i`

th non-zero band in `pbs`

.