Skip to content

Commit 4b92937

Browse files
authored
Merge pull request #54 from dsweber2/fixingMeanFreq
mean power (rather than 1-norm) and linear interpolation
2 parents dbb242b + 92a1269 commit 4b92937

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
name = "ContinuousWavelets"
22
uuid = "96eb917e-2868-4417-9cb6-27e7ff17528f"
33
authors = ["dsweber2 <[email protected]> and contributors"]
4-
version = "1.1.4"
4+
version = "1.1.5"
55

66
[deps]
77
AbstractFFTs = "621f4979-c628-5d54-868e-fcf4e3e8185c"
8+
DSP = "717857b8-e6f2-59f4-9121-6e50c889abd2"
89
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
910
FFTW = "7a1cc6ca-52ef-59f5-83cd-3a7055c09341"
1011
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"

src/createWavelets.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ function computeWavelets(n1::Integer,
186186
isAve = !(typeof(c.averagingType) <: NoAve)
187187
# I guess matlab did occasionally do something useful
188188

189-
ω = computeOmega(n1, nSpace, n)
189+
ω = computeOmega(n1, n)
190190
daughters = analyticOrNot(c, n, totalWavelets)
191191

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

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

290-
function computeOmega(nOriginal, nSpace, nFreq)
290+
function computeOmega(nOriginal, nFreq)
291291
range(0, nOriginal >> 1 + 1, length = nFreq) # max size is the last frequency in the rfft of the original data size
292292
end
293293
# convenience methods

src/utils.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,13 @@ end
247247
"""
248248
getMeanFreq(Ŵ, fsample=2000) -> arrayOfFreqs
249249
250-
Calculate each of the mean frequencies of a collection of analytic or real wavelets `Ŵ`.
250+
Calculate each of the mean frequencies of a collection of analytic or real wavelets `Ŵ`, using the power spectral density.
251251
The default sampling rate `fsample=2kHz`, so the maximum frequency is 1kHz.
252252
"""
253253
function getMeanFreq(Ŵ::Array, fsample = 2000)
254-
eachNorm = [norm(w, 1) for w in eachcol(Ŵ)]
254+
eachNorm = [norm(w, 2)^2 for w in eachcol(Ŵ)]
255255
freqs = range(0, fsample / 2, length = size(Ŵ, 1))
256-
return map(ŵ -> sum(abs.(ŵ) .* freqs), eachcol(Ŵ)) ./ eachNorm
256+
return map(ŵ -> sum(abs2.(ŵ) .* freqs), eachcol(Ŵ)) ./ eachNorm
257257
end
258258

259259
function getMeanFreq(n1, cw::CWT, fsample = 2000)
@@ -306,8 +306,8 @@ end
306306

307307

308308
# create interpolater for the orthogonal cases
309-
genInterp(ψ) = interpolate(ψ, BSpline(Quadratic(Reflect(OnGrid()))))
310-
309+
#genInterp(ψ) = scale(interpolate(ψ, BSpline(Cubic(Reflect(OnGrid())))), 1:length(ψ))
310+
genInterp(ψ) = linear_interpolation(1:length(ψ),ψ)
311311

312312

313313

src/waveletTypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
struct Morlet <: ContWaveClass
2-
σ::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
2+
σ::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
33
κσ::Float64
44
::Float64
55
end

0 commit comments

Comments
 (0)