Skip to content

Commit

Permalink
Finished PBS with time scaler
Browse files Browse the repository at this point in the history
  • Loading branch information
dingraha committed Apr 8, 2024
1 parent 9cbc0ab commit 7fe562b
Show file tree
Hide file tree
Showing 2 changed files with 520 additions and 13 deletions.
31 changes: 19 additions & 12 deletions src/proportional_bands.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,12 +472,13 @@ upper_bands(bands::ApproximateOctaveBands{LCU,TF}, scaler=freq_scaler(bands)) wh
abstract type AbstractProportionalBandSpectrum{NO,TF} <: AbstractVector{TF} end

octave_fraction(::Type{<:AbstractProportionalBandSpectrum{NO}}) where {NO} = NO
@inline lower_bands(pbs::AbstractProportionalBandSpectrum) = pbs.lbands
@inline lower_bands(pbs::AbstractProportionalBandSpectrum) = lower_bands(pbs.cbands)
@inline center_bands(pbs::AbstractProportionalBandSpectrum) = pbs.cbands
@inline upper_bands(pbs::AbstractProportionalBandSpectrum) = pbs.ubands
@inline upper_bands(pbs::AbstractProportionalBandSpectrum) = upper_bands(pbs.cbands)
@inline freq_scaler(pbs::AbstractProportionalBandSpectrum) = freq_scaler(center_bands(pbs))
@inline has_observer_time(pbs::AbstractProportionalBandSpectrum) = false
@inline observer_time(pbs::AbstractProportionalBandSpectrum{NO,TF}) where {NO,TF} = zero(TF)
@inline amplitude(pbs::AbstractProportionalBandSpectrum) = pbs.pbs

"""
time_period(pbs::AbstractArray{<:AbstractProportionalBandSpectrum,N})
Expand All @@ -493,6 +494,16 @@ 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 amplitude(pbs)[i]
end

"""
LazyNBProportionalBandSpectrum{NO,TF,TAmp,TBandsL,TBandsC,TBandsU}
Expand Down Expand Up @@ -524,6 +535,9 @@ struct LazyNBProportionalBandSpectrum{NO,TF,TAmp,TBandsL<:AbstractProportionalBa
end
end

@inline lower_bands(pbs::LazyNBProportionalBandSpectrum) = pbs.lbands
@inline upper_bands(pbs::LazyNBProportionalBandSpectrum) = pbs.ubands

const LazyNBExactOctaveSpectrum{TF,TAmp} = LazyNBProportionalBandSpectrum{1,TF,TAmp,
ExactProportionalBands{1,:lower,TF},
ExactProportionalBands{1,:center,TF},
Expand Down Expand Up @@ -662,6 +676,9 @@ struct ProportionalBandSpectrum{NO,TF,TPBS,TBandsL<:AbstractProportionalBands{NO
end
end

@inline lower_bands(pbs::ProportionalBandSpectrum) = pbs.lbands
@inline upper_bands(pbs::ProportionalBandSpectrum) = pbs.ubands

"""
ProportionalBandSpectrum(TBandsC, cfreq_start, pbs, scaler=1)
Expand All @@ -678,16 +695,6 @@ function ProportionalBandSpectrum(TBandsC::Type{<:AbstractProportionalBands{NO,:
return ProportionalBandSpectrum(cbands, pbs)
end

"""
Base.getindex(pbs::ProportionalBandSpectrum, i::Int)
Return the proportional band spectrum amplitude for the `i`th non-zero band in `pbs`.
"""
@inline function Base.getindex(pbs::ProportionalBandSpectrum, i::Int)
@boundscheck checkbounds(pbs, i)
return pbs.pbs[i]
end

#function project(pbs::AbstractProportionalBandSpectrum, outbands::AbstractProportionalBands)
# # Create the vector that will contain the new PBS.
# TFOut = promote_type(eltype(pbs), eltype(outbands))
Expand Down
Loading

0 comments on commit 7fe562b

Please sign in to comment.