Skip to content

Commit c32a561

Browse files
Merge pull request #76 from JaredW40/master
Updated Morse wavelet function and test functions
2 parents 2924625 + 720e8c1 commit c32a561

9 files changed

Lines changed: 120 additions & 113 deletions

File tree

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
pull_request: # run when pull requests are made
1111
paths:
1212
- src/*
13-
- test/runtests.jl
13+
- test/*
1414
- Manifest.toml
1515
- Project.toml
1616
jobs:
@@ -22,7 +22,7 @@ jobs:
2222
matrix:
2323
version:
2424
- "1.11"
25-
- "1.10"
25+
- "1.12"
2626
os:
2727
- ubuntu-latest
2828
- macOS-latest

docs/allInOne.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ gr();
123123
Plots.reset_defaults()
124124
global_logger(Logging.SimpleLogger(stderr, Logging.Error))
125125
n = 2047;
126-
function mapTo(waveType, isReal = true, window = 1:2047; d = 1, γ = 4.0, β = 2.0, cf = 1.0, kwargs...)
126+
function mapTo(waveType, isReal = true, window = 1:2047; d = 1, γ = 2.0, β = 4.0, cf = 1.0, kwargs...)
127127
if waveType == Morse
128128
morse_wav = Morse(float(γ), float(β), float(cf))
129129
c = wavelet(morse_wav; kwargs...)
@@ -150,18 +150,18 @@ p2 = plot([real.(tmp) imag.(tmp)],
150150
labels = ["real" "imaginary"],
151151
ticks = nothing,
152152
linewidth = 5)
153-
tmpMorse1 = mapTo(Morse, false; β=3, γ=10.0, cf=1.0, averagingLength=-1)[:, 2]
153+
tmpMorse1 = mapTo(Morse, false; γ=2.0, β=11.0, cf=1.0, averagingLength=-1)[:, 2]
154154
p3 = plot([real.(tmpMorse1) imag.(tmpMorse1)],
155-
title = "Morse (β=3, γ=10)",
155+
title = "Morse (γ=2, β=11)",
156156
labels = ["real" "imaginary"],
157157
ticks = nothing,
158-
linewidth = 4)
159-
tmpMorse2 = mapTo(Morse, false; β=1, γ=3.0, cf=1.0, averagingLength=-2)[:, 2]
158+
linewidth = 5)
159+
tmpMorse2 = mapTo(Morse, false; γ=1, β=2, cf=1.0, averagingLength=-2)[:, 2]
160160
p4 = plot([real.(tmpMorse2) imag.(tmpMorse2)],
161-
title = "Morse (β=1, γ=3)",
161+
title = "Morse (γ=1, β=2)",
162162
labels = ["real" "imaginary"],
163163
ticks = nothing,
164-
linewidth = 4)
164+
linewidth = 5)
165165
p5 = plot(mapTo(dog2; averagingLength = -1.5)[:, 2],
166166
title = "derivative of gaussians (dog2)",
167167
legend = false,

docs/mothers.svg

Lines changed: 83 additions & 83 deletions
Loading

docs/src/coreType.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ using ContinuousWavelets, Plots, Wavelets, FFTW, Logging
1010
using Plots; gr()
1111
Plots.reset_defaults()
1212
n= 2047;
13-
function mapTo(waveType, isReal = true, window = 1:2047; d = 1, γ = 4.0, β = 2.0, cf = 1.0, kwargs...)
13+
function mapTo(waveType, isReal = true, window = 1:2047; d = 1, γ = 2.0, β = 4.0, cf = 1.0, kwargs...)
1414
if waveType == Morse
1515
morse_wav = Morse(float(γ), float(β), float(cf))
1616
c = wavelet(morse_wav; kwargs...)
@@ -29,10 +29,10 @@ tmp = mapTo(Morlet(π), false; averagingLength = -0.2)[:, 2]
2929
p1 = plot([real.(tmp) imag.(tmp)], title = "Morlet", labels = ["real" "imaginary"], ticks = nothing, linewidth = 5)
3030
tmp = mapTo(paul2, false, averagingLength = -0.5)[:, 2]
3131
p2 = plot([real.(tmp) imag.(tmp)], title = "Paul 2", labels = ["real" "imaginary"], ticks = nothing, linewidth = 5)
32-
tmpMorse1 = mapTo(Morse, false; β=3, γ=10.0, cf=1.0, averagingLength=-1)[:, 2]
33-
p3 = plot([real.(tmpMorse1) imag.(tmpMorse1)], title = "Morse (β=3, γ=10)", labels = ["real" "imaginary"], ticks = nothing, linewidth = 4)
34-
tmpMorse2 = mapTo(Morse, false; β=1, γ=3.0, cf=1.0, averagingLength=-2)[:, 2]
35-
p4 = plot([real.(tmpMorse2) imag.(tmpMorse2)], title = "Morse (β=1, γ=3)", labels = ["real" "imaginary"], ticks = nothing, linewidth = 4)
32+
tmpMorse1 = mapTo(Morse, false; γ=2.0, β=11.0, cf=1.0, averagingLength=-1)[:, 2]
33+
p3 = plot([real.(tmpMorse1) imag.(tmpMorse1)], title = "Morse (γ=2, β=11)", labels = ["real" "imaginary"], ticks = nothing, linewidth = 4)
34+
tmpMorse2 = mapTo(Morse, false; γ=1.0, β=2.0, cf=1.0, averagingLength=-2)[:, 2]
35+
p4 = plot([real.(tmpMorse2) imag.(tmpMorse2)], title = "Morse (γ=1, β=2)", labels = ["real" "imaginary"], ticks = nothing, linewidth = 4)
3636
p5 = plot(mapTo(dog2; averagingLength = -1.5)[:, 2], title = "derivative of gaussians (dog2)", legend = false, ticks = nothing, linewidth = 5)
3737
p6 = plot(mapTo(cHaar, true; averagingLength = 1)[:, 2], title = "Haar", legend = false, ticks = nothing, linewidth = 5)
3838
p7 = plot(mapTo(cBeyl, true; d = 1, averagingLength = -0)[:, 2], title = "Beylkyin", legend = false, ticks = nothing, linewidth = 5)
@@ -46,5 +46,5 @@ plot(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, layout = (3, 4), size =
4646
savefig("mothers.svg")#hide
4747
```
4848
![](mothers.svg)
49-
Above are examples of every mother wavelet family defined in this package; the only analytic and/or complex wavelets are the `Morlet` and the `Paul` wavelet families.
49+
Above are examples of every mother wavelet family defined in this package; the only analytic and/or complex wavelets are the `Morlet`, `Paul` and `Morse` wavelet families.
5050
Once you have chosen a type of wavelet, this is used to construct the more specific CWT, which specifies more details of the transform, such as frequency spacing, whether to include an averaging filter or not, a frame upper bound, etc.

src/ContinuousWavelets.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ are:
6969
compactness parameter, and `cf` is a parameter that determines the
7070
frequency at which the magnitude of the wavelet is maximized.
7171
72-
``\\psi\\hat(\\omega) \\propto \\chi_{\\omega \\geq 0}(\\omega) \\omega^\\textrm{be}\\textrm{e}^{-(2\\pi\\omega)^{\\textrm{ga}}}\\textrm{, } be, ga \\geq 0``
72+
``\\psi\\hat(\\omega) \\propto \\chi_{\\omega \\geq 0}(\\omega) \\omega^\\textrm{be}\\textrm{e}^{-\\omega^{\\textrm{ga}}}\\textrm{, } ga, be \\geq 0``
7373
7474
- `Dog{N}`: Derivative of a Gaussian, where N is the number of
7575
derivatives. `dogn` for `n` in `0:6`. The Sombrero/mexican hat/Marr wavelet

src/createWavelets.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,27 +48,29 @@ function mother(this::CWT{W,T,Morse,N},
4848

4949
ga = this.waveType.ga
5050
be = this.waveType.be
51-
cf = this.waveType.cf
51+
# cf = this.waveType.cf
5252
p = this.p
5353

5454
fo = morsefreq(this)
55-
fact = cf / fo
55+
# fact = cf / fo
5656

5757
# ω = LinRange(0,1-(1/len),len)
5858
# om = 2 * pi * ω./ fact / max(1, s)
59-
#om = 2 * pi * (ω / s)./ fact
59+
# om = 2 * pi * (ω / s)./ fact
6060
# om = (ω / s) / cf
6161
# om = (ω / s) / fact
6262

6363
om = ω / s
64+
om_safe = max.(om, eps())
6465

6566
if be == 0
6667
daughter = @. 2 * exp(-om^ga)
6768
else
68-
daughter = @. 2 * exp(-be * log(fo) + fo^ga + be * log(om) - om^ga)
69+
daughter = @. 2 * (om_safe / fo)^be * exp(-(om^ga - fo^ga))
6970
end
70-
71-
daughter[1] = 1 / 2 * daughter[1] # Due to unit step function
71+
daughter[1] = 0
72+
73+
# daughter[1] = 1 / 2 * daughter[1] # Due to unit step function
7274
# Ensure nice lowpass filters for beta=0;
7375
# Otherwise, doesn't matter since wavelets vanishes at zero frequency
7476

src/utils.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ getMinScaling(c::CWT{W,T,M,N}) where {W,T,N,M} = 0 # by default all scales are a
8181
getMinScaling(c::CWT{W,T,<:Morlet,N}) where {W,T,N} = 1 / (c.β)^0.8 # morlet is slightly too large at the boundaries by default
8282
getMinScaling(c::CWT{W,T,<:Paul,N}) where {W,T,N} = 2 / (2c.α + 1) # Paul presents some difficulties, as the decay changes quickly (like 1/t^(α+1))
8383
getMinScaling(c::CWT{W,T,<:Dog,N}) where {W,T,N} = 2 # like morlet, the decay for Dog is exponential and consistent across derivatives
84-
# getMinScaling(c::CWT{W,T,<:Morse,N}) where {W,T,N,M} = log2(2 * morsefreq(c))
85-
getMinScaling(c::CWT{W,T,<:Morse,N}) where {W,T,N} = 5 * morsefreq(c)
84+
getMinScaling(c::CWT{W,T,<:Morse,N}) where {W,T,N} = log2(2 * morsefreq(c))
8685

8786
function varianceAdjust(this::CWT{W,T,M,N}, totalWavelets, nOct) where {W,T,N,M}
8887
# increases the width of the wavelets by σ[i] = (1+a(total-i)ᴾ)σₛ

src/waveletTypes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function Morse_convert(ga::Real, be::Real, cf::Real)
3737
Morse(ga, be, cf)
3838
end
3939

40-
Morse() = Morse_convert(4, 2, 1)
40+
Morse() = Morse_convert(2, 4, 1)
4141
class(::Morse) = "Morse";
4242
name(::Morse) = "morse";
4343
vanishingmoments(::Morse) = 0;

test/defaultProperties.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,25 @@
3838
end-floor(Int, n / 2):end],
3939
:]
4040
# make sure the wavelets don't have significant support out into the mirrored signal
41-
if !(bc isa PerBoundary) && !(wave isa Paul) && size(, 2) > 1
41+
if !(bc isa PerBoundary) && !(wave isa Paul) && !(wave isa Morse) && size(Ŵ, 2) > 1
4242
@test max([norm(nonSupported[:, i], Inf) / norm(supported[:, i], Inf) for
4343
i = 2:size(spaceWaves, 2)]...) 1e-2
44-
elseif wave isa Paul && size(Ŵ, 2) > 1 # the Paul wavelet decay is just too slow to avoid bleedover, so best to ignore the averaging size
44+
elseif !(bc isa PerBoundary) && (wave isa Paul || wave isa Morse) &&
45+
size(Ŵ, 2) > 1 && ave > 0
4546
@test max([norm(nonSupported[:, i], Inf) / norm(supported[:, i], Inf) for
4647
i = 2:size(spaceWaves, 2)]...) 1e-1
4748
end
4849
# if the averaging length is 0 and its only averaging at the sizes given, something is wrong
4950
@test size(Ŵ, 2) > 1 || ave > 0
51+
5052
# make sure that the highest frequency support is small relative to the space domain
51-
# Guaranteed in a very different way for ContOrtho, no guarantees made for just averaging, and the averaging length needs to leave 6.5 octaves
52-
if !(wave isa ContOrtho) && size(Ŵ, 2) > 1 && log2(n) - ave > 6.5
53-
@test max(abs.(Ŵ[end, :])...) / norm(supported, Inf) 1e-1
53+
# Guaranteed in a very different way for ContOrtho, no guarantees made for just averaging,
54+
# and the averaging length needs to leave 6.5 octaves.
55+
# The Morse wavelet with γ < 3 has sub-Gaussian spectral decay and cannot be guaranteed
56+
# to vanish at Nyquist, similar to the Paul wavelet.
57+
if !(wave isa ContOrtho) && size(Ŵ, 2) > 1 && log2(n) - ave > 6.5 &&
58+
!(wave isa Paul) && !(wave isa Morse && wave.ga < 3)
59+
@test max(abs.(Ŵ[end, :])...) / norm(supported, Inf) 1e-1
5460
end
5561

5662
# check that the father wavelet is actually positive

0 commit comments

Comments
 (0)