Skip to content

Commit

Permalink
fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
wheeheee committed Feb 10, 2024
1 parent 188ad8e commit 5c54327
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/multitaper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
##### Multitapered periodogram
#####

struct MTConfig{T,R1,F,P,T1,T2,W,R2} <: AbstractPGramConfig
struct MTConfig{T,R1,F,P,T1,T2,W,R2}
n_samples::Int
fs::R1
nfft::Int
Expand Down
36 changes: 11 additions & 25 deletions src/periodograms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,20 +363,7 @@ forward_plan(X::AbstractArray{T}, Y::AbstractArray{Complex{T}}) where {T<:Union{
forward_plan(X::AbstractArray{T}, Y::AbstractArray{T}) where {T<:Union{ComplexF32, ComplexF64}} =
plan_fft(X)

"""
AbstractPGramConfig
Abstract type representing a configuration object used for computing a periodogram.
# See Also
- [`MTConfig`](@ref)
- [`WelchConfig`](@ref)
"""
abstract type AbstractPGramConfig end

struct WelchConfig{F,Fr,W,P,T1,T2,R} <: AbstractPGramConfig
struct WelchConfig{F,Fr,W,P,T1,T2,R}
nsamples::Int
noverlap::Int
onesided::Bool
Expand Down Expand Up @@ -413,14 +400,14 @@ returns a Periodogram object. For a Bartlett periodogram, set `noverlap=0`. See
"""
function WelchConfig(nsamples, ::Type{T}; n::Int=nsamples >> 3, noverlap::Int=n >> 1,
onesided::Bool=T<:Real, nfft::Int=nextfastfft(n),
onesided::Bool=T <: Real, nfft::Int=nextfastfft(n),
fs::Real=1, window::Union{Function,AbstractVector,Nothing}=nothing) where T

onesided && T <: Complex && error("cannot compute one-sided FFT of a complex signal")
nfft >= n || error("nfft must be >= n")
onesided && T <: Complex && throw(ArgumentError("cannot compute one-sided FFT of a complex signal"))
nfft >= n || throw(DomainError((; nfft, n), "nfft must be >= n"))

win, norm2 = compute_window(window, n)
r = fs*norm2
r = fs * norm2
inbuf = zeros(float(T), nfft)
outbuf = Vector{fftouttype(T)}(undef, T<:Real ? (nfft >> 1)+1 : nfft)
plan = forward_plan(inbuf, outbuf)
Expand Down Expand Up @@ -465,7 +452,7 @@ description of optional keyword arguments.
"""
function welch_pgram!(output::AbstractVector, s::AbstractVector, n::Int=length(s)>>3, noverlap::Int=n>>1;

Check warning on line 453 in src/periodograms.jl

View check run for this annotation

Codecov / codecov/patch

src/periodograms.jl#L453

Added line #L453 was not covered by tests
kwargs...)
welch_pgram!(output, s, WelchConfig(s; n, overlap, kwargs...))
welch_pgram!(output, s, WelchConfig(s; n, noverlap, kwargs...))

Check warning on line 455 in src/periodograms.jl

View check run for this annotation

Codecov / codecov/patch

src/periodograms.jl#L455

Added line #L455 was not covered by tests
end

"""
Expand All @@ -486,12 +473,11 @@ Computes the Welch periodogram of the given signal, storing the result in `out`,
predefined config object [WelchConfig](@ref).
"""
function welch_pgram!(out::AbstractVector, in::AbstractVector{T}, config::WelchConfig{T}) where T<:Number
if length(output) != length(config.freq)
if length(out) != length(config.freq)
throw(DimensionMismatch("""Expected `output` to be of length `length(config.freq)`;

Check warning on line 477 in src/periodograms.jl

View check run for this annotation

Codecov / codecov/patch

src/periodograms.jl#L475-L477

Added lines #L475 - L477 were not covered by tests
got `length(output) = $(length(output)) and `length(config.freq)` = $(length(config.freq))"""))
end
if eltype(out) == fftabs2type(T)
throw(ArgumentError("Eltype of output ($eltype(out)) doesn't matched the expected "*
got `length(output)` = $(length(out)) and `length(config.freq)` = $(length(config.freq))"""))
elseif eltype(out) != fftabs2type(T)
throw(ArgumentError("Eltype of output ($(eltype(out))) doesn't match the expected "*

Check warning on line 480 in src/periodograms.jl

View check run for this annotation

Codecov / codecov/patch

src/periodograms.jl#L479-L480

Added lines #L479 - L480 were not covered by tests
"type: $(fftabs2type(T))."))
end
welch_pgram_helper!(out, in, config)

Check warning on line 483 in src/periodograms.jl

View check run for this annotation

Codecov / codecov/patch

src/periodograms.jl#L483

Added line #L483 was not covered by tests
Expand All @@ -501,7 +487,7 @@ function welch_pgram_helper!(out, in, config)
sig_split = arraysplit(in, config.nsamples, config.noverlap, config.nfft, config.window;
buffer=config.inbuf)

r = length(sig_split)*config.r
r = length(sig_split) * config.r

for sig in sig_split
mul!(config.outbuf, config.plan, sig)
Expand Down

0 comments on commit 5c54327

Please sign in to comment.