Skip to content

Commit

Permalink
Merge pull request #54 from dsweber2/fixingMeanFreq
Browse files Browse the repository at this point in the history
mean power (rather than 1-norm) and linear interpolation
  • Loading branch information
dsweber2 authored Jun 3, 2024
2 parents dbb242b + 92a1269 commit 4b92937
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
name = "ContinuousWavelets"
uuid = "96eb917e-2868-4417-9cb6-27e7ff17528f"
authors = ["dsweber2 <david.weber2@protonmail.com> and contributors"]
version = "1.1.4"
version = "1.1.5"

[deps]
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
Expand Down
6 changes: 3 additions & 3 deletions src/createWavelets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function computeWavelets(n1::Integer,
isAve = !(typeof(c.averagingType) <: NoAve)
# I guess matlab did occasionally do something useful

ω = computeOmega(n1, nSpace, n)
ω = computeOmega(n1, n)
daughters = analyticOrNot(c, n, totalWavelets)

# if the nOctaves is small enough there are none not covered by the
Expand Down Expand Up @@ -230,7 +230,7 @@ function computeWavelets(n1::Integer,
# indicates whether we should keep a spot for the father wavelet
isAve = !(typeof(c.averagingType) <: NoAve)

ω = computeOmega(n1, nSpace, n)
ω = computeOmega(n1, n)
daughters = zeros(nSpace, totalWavelets)
φ, ψ, ψLen = getContWaveFromOrtho(c, nSpace)
itpψ = genInterp(ψ)
Expand Down Expand Up @@ -287,7 +287,7 @@ function analyticOrNot(c::CWT{W,T,<:Union{Morlet,Paul,Morse},N},
return daughters
end

function computeOmega(nOriginal, nSpace, nFreq)
function computeOmega(nOriginal, nFreq)
range(0, nOriginal >> 1 + 1, length = nFreq) # max size is the last frequency in the rfft of the original data size
end
# convenience methods
Expand Down
10 changes: 5 additions & 5 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,13 @@ end
"""
getMeanFreq(Ŵ, fsample=2000) -> arrayOfFreqs
Calculate each of the mean frequencies of a collection of analytic or real wavelets `Ŵ`.
Calculate each of the mean frequencies of a collection of analytic or real wavelets `Ŵ`, using the power spectral density.
The default sampling rate `fsample=2kHz`, so the maximum frequency is 1kHz.
"""
function getMeanFreq(Ŵ::Array, fsample = 2000)
eachNorm = [norm(w, 1) for w in eachcol(Ŵ)]
eachNorm = [norm(w, 2)^2 for w in eachcol(Ŵ)]
freqs = range(0, fsample / 2, length = size(Ŵ, 1))
return map(ŵ -> sum(abs.(ŵ) .* freqs), eachcol(Ŵ)) ./ eachNorm
return map(ŵ -> sum(abs2.(ŵ) .* freqs), eachcol(Ŵ)) ./ eachNorm
end

function getMeanFreq(n1, cw::CWT, fsample = 2000)
Expand Down Expand Up @@ -306,8 +306,8 @@ end


# create interpolater for the orthogonal cases
genInterp(ψ) = interpolate(ψ, BSpline(Quadratic(Reflect(OnGrid()))))

#genInterp(ψ) = scale(interpolate(ψ, BSpline(Cubic(Reflect(OnGrid())))), 1:length(ψ))
genInterp(ψ) = linear_interpolation(1:length(ψ),ψ)



Expand Down
2 changes: 1 addition & 1 deletion src/waveletTypes.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct Morlet <: ContWaveClass
σ::Float64 # σ is the time/space trade-off. as σ->0, the spacial resolution increases; below 5, there is a danger of being non-analytic. Default is 5.8
σ::Float64 # σ is the time/space trade-off. as σ->0, the spacial resolution increases; below 5, there is a danger of being non-analytic. Default is
κσ::Float64
::Float64
end
Expand Down

2 comments on commit 4b92937

@dsweber2
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/108117

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.1.5 -m "<description of version>" 4b929374e6f26db1973f9b04cbe10fa93685811e
git push origin v1.1.5

Please sign in to comment.