Skip to content

Commit

Permalink
Better docs!
Browse files Browse the repository at this point in the history
  • Loading branch information
dingraha committed Jul 1, 2024
1 parent 5957b9e commit 77d135c
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 71 deletions.
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module AMDocs
using Documenter, AcousticMetrics
using AcousticMetrics: AcousticMetrics

function doit()
IN_CI = get(ENV, "CI", nothing)=="true"
Expand Down
89 changes: 86 additions & 3 deletions docs/src/api.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,92 @@
```@meta
CurrentModule = AMDocs
```

# API Reference

```@autodocs
Modules = [AcousticMetrics]
## Fourier Transforms
```@docs
AcousticMetrics.rfft!
AcousticMetrics.irfft!
```

## Pressure Time History
```@docs
AbstractPressureTimeHistory
PressureTimeHistory
AcousticMetrics.pressure
AcousticMetrics.inputlength
AcousticMetrics.timestep(pth::AbstractPressureTimeHistory)
AcousticMetrics.starttime(pth::AbstractPressureTimeHistory)
AcousticMetrics.time
```

## Narrowband Metrics
```@docs
AbstractNarrowbandSpectrum
AcousticMetrics.halfcomplex
AcousticMetrics.timestep(sm::AbstractNarrowbandSpectrum)
AcousticMetrics.starttime(sm::AbstractNarrowbandSpectrum)
AcousticMetrics.samplerate
AcousticMetrics.frequency
AcousticMetrics.frequencystep
AcousticMetrics.istonal
PressureSpectrumAmplitude
PressureSpectrumPhase
MSPSpectrumAmplitude
MSPSpectrumPhase
PowerSpectralDensityAmplitude
PowerSpectralDensityPhase
```

### Proportional Bands and Proportional Band Spectra
```@docs
AbstractProportionalBands
AcousticMetrics.octave_fraction
AcousticMetrics.lower_center_upper
AcousticMetrics.freq_scaler
AcousticMetrics.band_start
AcousticMetrics.band_end
AcousticMetrics.lower_bands
AcousticMetrics.upper_bands
AcousticMetrics.center_bands
AcousticMetrics.cband_number
ExactProportionalBands
ExactOctaveCenterBands
ExactOctaveLowerBands
ExactOctaveUpperBands
ExactThirdOctaveCenterBands
ExactThirdOctaveLowerBands
ExactThirdOctaveUpperBands
ApproximateThirdOctaveBands
ApproximateThirdOctaveCenterBands
ApproximateThirdOctaveLowerBands
ApproximateThirdOctaveUpperBands
ApproximateOctaveBands
ApproximateOctaveCenterBands
ApproximateOctaveLowerBands
ApproximateOctaveUpperBands
AbstractProportionalBandSpectrum
AcousticMetrics.has_observer_time
AcousticMetrics.observer_time
AcousticMetrics.timestep(pbs::AbstractProportionalBandSpectrum)
AcousticMetrics.amplitude
AcousticMetrics.time_period
AcousticMetrics.time_scaler
LazyNBProportionalBandSpectrum
AcousticMetrics.frequency_nb
AcousticMetrics.lazy_pbs
ProportionalBandSpectrum
LazyPBSProportionalBandSpectrum
ProportionalBandSpectrumWithTime
AcousticMetrics.combine
```

## Weighting
```@docs
W_A
```

## Integrated Metrics
```@docs
OASPL
```
4 changes: 2 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Currently implemented metrics include:
* Proportional band spectra

* Approximate octave and third-octave spectra
* Exact proportional spectra of any octave fraction > 0.
* Lazy representations of proportional band spectra constructed from either other narrowband or proportional band spectra
* Exact proportional spectra of any octave fraction integer > 0.
* Lazy representations of proportional band spectra constructed from either narrowband or proportional band spectra

* Integrated metrics

Expand Down
4 changes: 4 additions & 0 deletions src/AcousticMetrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export AbstractPressureTimeHistory, PressureTimeHistory
export AbstractNarrowbandSpectrum
export PressureSpectrumAmplitude, PressureSpectrumPhase, MSPSpectrumAmplitude, MSPSpectrumPhase, PowerSpectralDensityAmplitude, PowerSpectralDensityPhase

include("integrated.jl")
export OASPL

include("proportional_bands.jl")
export AbstractProportionalBands
export ExactProportionalBands
Expand All @@ -25,5 +28,6 @@ export ApproximateThirdOctaveBands, ApproximateThirdOctaveCenterBands, Approxima
export AbstractProportionalBandSpectrum, LazyNBProportionalBandSpectrum, ProportionalBandSpectrum, ProportionalBandSpectrumWithTime, LazyPBSProportionalBandSpectrum

include("weighting.jl")
export W_A

end # module
23 changes: 23 additions & 0 deletions src/integrated.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
OASPL(ap::AbstractPressureTimeHistory)
Return the overall sound pressure level of a pressure time history.
"""
function OASPL(ap::AbstractPressureTimeHistory)
p = pressure(ap)
n = inputlength(ap)
p_mean = sum(p)/n
msp = sum((p .- p_mean).^2)/n
return 10*log10(msp/p_ref^2)
end

"""
OASPL(ap::AbstractNarrowbandSpectrum)
Return the overall sound pressure level of a narrowband spectrum.
"""
function OASPL(sp::AbstractNarrowbandSpectrum)
amp = MSPSpectrumAmplitude(sp)
msp = sum(@view amp[begin+1:end])
return 10*log10(msp/p_ref^2)
end
24 changes: 0 additions & 24 deletions src/narrowband.jl
Original file line number Diff line number Diff line change
Expand Up @@ -534,27 +534,3 @@ end
Alias for `PressureSpectrumPhase`.
"""
const PowerSpectralDensityPhase = PressureSpectrumPhase

"""
OASPL(ap::AbstractPressureTimeHistory)
Return the overall sound pressure level of a pressure time history.
"""
function OASPL(ap::AbstractPressureTimeHistory)
p = pressure(ap)
n = inputlength(ap)
p_mean = sum(p)/n
msp = sum((p .- p_mean).^2)/n
return 10*log10(msp/p_ref^2)
end

"""
OASPL(ap::AbstractNarrowbandSpectrum)
Return the overall sound pressure level of a narrowband spectrum.
"""
function OASPL(sp::AbstractNarrowbandSpectrum)
amp = MSPSpectrumAmplitude(sp)
msp = sum(@view amp[begin+1:end])
return 10*log10(msp/p_ref^2)
end
43 changes: 1 addition & 42 deletions src/proportional_bands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ Construct an `ExactProportionalBands` with `eltype` `TF`, scaled by `scaler`, en
ExactProportionalBands{NO,LCU}(fstart::TF, fend::TF, scaler=1) where {NO,LCU,TF} = ExactProportionalBands{NO,LCU,TF}(fstart, fend, scaler)
ExactProportionalBands{NO,LCU,TF}(fstart::TF, fend::TF, scaler=1) where {NO,LCU,TF} = ExactProportionalBands{NO,LCU,TF}(band_exact_lower_limit(NO, fstart, scaler), band_exact_upper_limit(NO, fend, scaler), scaler)

"""
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(bands::ExactProportionalBands, i::Int)

@inline function Base.getindex(bands::ExactProportionalBands{NO,:center}, i::Int) where {NO}
@boundscheck checkbounds(bands, i)
# Now, how do I get the band?
Expand Down Expand Up @@ -324,13 +317,6 @@ function ApproximateThirdOctaveBands{LCU}(bstart::Int, bend::Int, scaler=1) wher
return ApproximateThirdOctaveBands{LCU}(Float64, bstart, bend, scaler)
end

"""
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(bands::ApproximateThirdOctaveBands, i::Int)

@inline function Base.getindex(bands::ApproximateThirdOctaveBands{:center,TF}, i::Int) where {TF}
@boundscheck checkbounds(bands, i)
j = bands.bstart + i - 1
Expand Down Expand Up @@ -493,13 +479,6 @@ function ApproximateOctaveBands{LCU}(bstart::Int, bend::Int, scaler=1) where {LC
return ApproximateOctaveBands{LCU}(Float64, bstart, bend, scaler)
end

"""
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(bands::ApproximateOctaveBands, i::Int)

@inline function Base.getindex(bands::ApproximateOctaveBands{:center,TF}, i::Int) where {TF}
@boundscheck checkbounds(bands, i)
j = bands.bstart + i - 1
Expand Down Expand Up @@ -685,7 +664,7 @@ Return the observer time at which the proportional band spectrum is defined to e
Return the time range over which the proportional band spectrum is defined to exist.
"""
@inline timestep(pbs::AbstractProportionalBandSpectrum{NO,TF}) where {NO,TF} = Inf*one(TF)
@inline timestep(pbs::AbstractProportionalBandSpectrum) = Inf*one(eltype(pbs))

"""
amplitude(pbs::AbstractProportionalBandSpectrum)
Expand Down Expand Up @@ -715,11 +694,6 @@ time_scaler(pbs::AbstractProportionalBandSpectrum{NO,TF}, period) where {NO,TF}

@inline Base.size(pbs::AbstractProportionalBandSpectrum) = size(center_bands(pbs))

"""
Base.getindex(pbs::AbstractProportionalBandSpectrum, i::Int)
Return the proportional band spectrum amplitude for the `i`th non-zero band in `pbs`.
"""
@inline function Base.getindex(pbs::AbstractProportionalBandSpectrum, i::Int)
@boundscheck checkbounds(pbs, i)
return @inbounds amplitude(pbs)[i]
Expand Down Expand Up @@ -887,11 +861,6 @@ function lazy_pbs(pbs::LazyNBProportionalBandSpectrum{NOIn,IsTonal}, cbands::Abs
return LazyNBProportionalBandSpectrum{NO,IsTonal}(pbs.f1_nb, pbs.df_nb, pbs.msp_amp, cbands)
end

"""
Base.getindex(pbs::LazyNBProportionalBandSpectrum{NO,false}, i::Int)
Return the proportional band spectrum amplitude for the `i`th non-zero band in `pbs` from a non-tonal narrowband.
"""
@inline function Base.getindex(pbs::LazyNBProportionalBandSpectrum{NO,false}, i::Int) where {NO}
@boundscheck checkbounds(pbs, i)
# This is where the fun begins.
Expand Down Expand Up @@ -958,11 +927,6 @@ Return the proportional band spectrum amplitude for the `i`th non-zero band in `
return res_first_band + sum(msp_amp_v2) + res_last_band
end

"""
Base.getindex(pbs::LazyNBProportionalBandSpectrum{NO,true}, i::Int)
Return the proportional band spectrum amplitude for the `i`th non-zero band in `pbs` from a tonal narrowband.
"""
@inline function Base.getindex(pbs::LazyNBProportionalBandSpectrum{NO,true}, i::Int) where {NO}
@boundscheck checkbounds(pbs, i)
# This is where the fun begins.
Expand Down Expand Up @@ -1258,11 +1222,6 @@ function combine(pbs::AbstractArray{<:AbstractProportionalBandSpectrum}, outcban
return ProportionalBandSpectrum(pbs_out, outcbands)
end

"""
_combine!(pbs_out::AbstractVector, pbs::AbstractVector{<:AbstractProportionalBandSpectrum}, outcbands::AbstractProportionalBands{NO,:center}) where {N}
Combine each input proportional band spectrum of `pbs` into one output Vector using the proportional center bands indicated by `outcbands`.
"""
function _combine!(pbs_out::AbstractVector, pbs::AbstractVector{<:AbstractProportionalBandSpectrum}, outcbands::AbstractProportionalBands{NO,:center}) where {NO}

# Get the time period for this collection of PBSs.
Expand Down

0 comments on commit 77d135c

Please sign in to comment.