Skip to content

Commit dd4d79a

Browse files
author
dsweber2
committed
unused file and better notation
1 parent 086686d commit dd4d79a

File tree

2 files changed

+59
-60
lines changed

2 files changed

+59
-60
lines changed

src/apply.jl

Lines changed: 59 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
assumption is that the sampling rate is 2kHz.
2020
2121
"""
22-
function cwt(Y::AbstractArray{T,N}, cWav::CWT, daughters, fftPlans = 1) where {N, T}
23-
@assert typeof(N)<:Integer
22+
function cwt(Y::AbstractArray{T,N}, cWav::CWT, daughters, fftPlans = 1) where {N,T}
23+
@assert typeof(N) <: Integer
2424
# vectors behave a bit strangely, so we reshape them
25-
if N==1
26-
Y= reshape(Y,(length(Y), 1))
25+
if N == 1
26+
Y = reshape(Y, (length(Y), 1))
2727
end
2828
n1 = size(Y, 1)
2929

@@ -35,8 +35,8 @@ function cwt(Y::AbstractArray{T,N}, cWav::CWT, daughters, fftPlans = 1) where {N
3535
x̂, fromPlan = prepSignalAndPlans(x, cWav, fftPlans)
3636
# If the vector isn't long enough to actually have any other scales, just
3737
# return the averaging
38-
if nScales <= 0 || size(daughters,2) == 1
39-
daughters = daughters[:,1:1]
38+
if nScales <= 0 || size(daughters, 2) == 1
39+
daughters = daughters[:, 1:1]
4040
nScales = 1
4141
end
4242

@@ -61,8 +61,8 @@ function cwt(Y::AbstractArray{T,N}, cWav::CWT, daughters, fftPlans = 1) where {N
6161
wave = permutedims(wave, [1, ndims(wave), (2:(ndims(wave)-1))...])
6262
ax = axes(wave)
6363
wave = wave[1:n1, ax[2:end]...]
64-
if N==1
65-
wave = dropdims(wave, dims=3)
64+
if N == 1
65+
wave = dropdims(wave, dims = 3)
6666
end
6767

6868
return wave
@@ -82,98 +82,98 @@ end
8282
# yes | both | fft
8383
# no | rfft | fft
8484
# Analytic on Real input
85-
function prepSignalAndPlans(x::AbstractArray{T}, cWav::CWT{W,S,WaTy, N, true}, fftPlans) where {T <: Real, W,S,WaTy,N}
85+
function prepSignalAndPlans(x::AbstractArray{T}, cWav::CWT{W,S,WaTy,N,true}, fftPlans) where {T<:Real,W,S,WaTy,N}
8686
# analytic wavelets that are being applied on real inputs
87-
if fftPlans isa Tuple{<:AbstractFFTs.Plan{<:Real}, <:AbstractFFTs.Plan{<:Complex}}
87+
if fftPlans isa Tuple{<:AbstractFFTs.Plan{<:Real},<:AbstractFFTs.Plan{<:Complex}}
8888
# they handed us the right kind of thing, so no need to make new ones
8989
= fftPlans[1] * x
9090
fromPlan = fftPlans[2]
9191
else
92-
toPlan = plan_rfft(x,1)
92+
toPlan = plan_rfft(x, 1)
9393
= toPlan * x
94-
fromPlan = plan_fft(x,1)
94+
fromPlan = plan_fft(x, 1)
9595
end
9696
return x̂, fromPlan
9797
end
9898

9999
# Non-analytic on Real input
100-
function prepSignalAndPlans(x::AbstractArray{T}, cWav::CWT{W,S,WaTy, N, false}, fftPlans) where {T <: Real, W,S,WaTy,N}
100+
function prepSignalAndPlans(x::AbstractArray{T}, cWav::CWT{W,S,WaTy,N,false}, fftPlans) where {T<:Real,W,S,WaTy,N}
101101
# real wavelets that are being applied on real inputs
102102
if fftPlans isa AbstractFFTs.Plan{<:Real}
103103
# they handed us the right kind of thing, so no need to make new ones
104104
= fftPlans * x
105105
fromPlan = fftPlans
106106
else
107-
fromPlan = plan_rfft(x,1)
107+
fromPlan = plan_rfft(x, 1)
108108
= fromPlan * x
109109
end
110110
return x̂, fromPlan
111111
end
112112
# complex input
113-
function prepSignalAndPlans(x::AbstractArray{T}, cWav, fftPlans) where {T <: Complex, W,S,WaTy,N}
113+
function prepSignalAndPlans(x::AbstractArray{T}, cWav, fftPlans) where {T<:Complex}
114114
# real wavelets that are being applied on real inputs
115115
if fftPlans isa AbstractFFTs.Plan{<:Complex}
116116
# they handed us the right kind of thing, so no need to make new ones
117117
= fftPlans * x
118118
fromPlan = fftPlans
119119
else
120-
fromPlan = plan_fft(x,1)
120+
fromPlan = plan_fft(x, 1)
121121
= fromPlan * x
122122
end
123123
return x̂, fromPlan
124124
end
125125

126126
# analytic on real data with an averaging function
127-
function analyticTransformReal!(wave, daughters, x̂, fftPlan, averagingType::Union{Father, Dirac})
127+
function analyticTransformReal!(wave, daughters, x̂, fftPlan, ::Union{Father,Dirac})
128128
outer = axes(x̂)[2:end]
129129
n1 = size(x̂, 1)
130-
isSourceEven = mod(size(wave,1)+1,2)
130+
isSourceEven = mod(size(wave, 1) + 1, 2)
131131
# the averaging function isn't analytic, so we need to do both positive and
132132
# negative frequencies
133-
@views tmpWave =.* daughters[:,1]
134-
@views wave[(n1+1):end, outer..., 1] = reverse(conj.(tmpWave[2:end-isSourceEven, outer...]), dims=1)
133+
@views tmpWave =.* daughters[:, 1]
134+
@views wave[(n1+1):end, outer..., 1] = reverse(conj.(tmpWave[2:end-isSourceEven, outer...]), dims = 1)
135135
@views wave[1:n1, outer..., 1] = tmpWave
136136
@views wave[:, outer..., 1] = fftPlan \ (wave[:, outer..., 1]) # averaging
137-
for j in 2:size(daughters,2)
138-
@views wave[1:n1, outer..., j] =.* daughters[:,j]
137+
for j = 2:size(daughters, 2)
138+
@views wave[1:n1, outer..., j] =.* daughters[:, j]
139139
wave[:, outer..., j] = fftPlan \ (wave[:, outer..., j]) # wavelet transform
140140
end
141141
end
142142

143143
# analytic on complex data with an averaging function
144-
function analyticTransformComplex!(wave, daughters, x̂, fftPlan, averagingType::Union{Father, Dirac})
144+
function analyticTransformComplex!(wave, daughters, x̂, fftPlan, ::Union{Father,Dirac})
145145
outer = axes(x̂)[2:end]
146146
n1 = size(daughters, 1)
147-
isSourceEven = mod(size(wave,1)+1,2)
147+
isSourceEven = mod(size(wave, 1) + 1, 2)
148148
# the averaging function isn't analytic, so we need to do both positive and
149149
# negative frequencies
150-
@views positiveFreqs = x̂[1:n1, outer...] .* daughters[:,1]
151-
@views negativeFreqs = x̂[(n1-isSourceEven+1):end, outer...] .* reverse(conj.(daughters[2:end,1]))
150+
@views positiveFreqs = x̂[1:n1, outer...] .* daughters[:, 1]
151+
@views negativeFreqs = x̂[(n1-isSourceEven+1):end, outer...] .* reverse(conj.(daughters[2:end, 1]))
152152
@views wave[(n1-isSourceEven+1):end, outer..., 1] = negativeFreqs
153153
@views wave[1:n1, outer..., 1] = positiveFreqs
154154
@views wave[:, outer..., 1] = fftPlan \ (wave[:, outer..., 1]) # averaging
155-
for j in 2:size(daughters,2)
156-
@views wave[1:n1, outer..., j] = x̂[1:n1, outer...] .* daughters[:,j]
155+
for j = 2:size(daughters, 2)
156+
@views wave[1:n1, outer..., j] = x̂[1:n1, outer...] .* daughters[:, j]
157157
@views wave[:, outer..., j] = fftPlan \ (wave[:, outer..., j]) # wavelet transform
158158
end
159159
end
160160

161161
function analyticTransformComplex!(wave, daughters, x̂, fftPlan, averagingType)
162162
outer = axes(x̂)[2:end]
163163
n1 = size(x̂, 1)
164-
for j in 1:size(daughters,2)
165-
@views wave[1:n1, outer..., j] = x̂[1:n1, outer...] .* daughters[:,j]
164+
for j = 1:size(daughters, 2)
165+
@views wave[1:n1, outer..., j] = x̂[1:n1, outer...] .* daughters[:, j]
166166
@views wave[:, outer..., j] = fftPlan \ (wave[:, outer..., j]) # wavelet transform
167167
end
168168
end
169169

170170
# analytic on real data without an averaging function
171-
function analyticTransformReal!(wave, daughters, x̂, fftPlan, averagingType::NoAve)
171+
function analyticTransformReal!(wave, daughters, x̂, fftPlan, ::NoAve)
172172
outer = axes(x̂)[2:end]
173173
n1 = size(x̂, 1)
174174
# the no averaging version
175-
for j in 1:size(daughters,2)
176-
wave[1:n1, outer..., j] =.* daughters[:,j]
175+
for j = 1:size(daughters, 2)
176+
wave[1:n1, outer..., j] =.* daughters[:, j]
177177
wave[:, outer..., j] = fftPlan \ (wave[:, outer..., j]) # wavelet transform
178178
end
179179
end
@@ -183,8 +183,8 @@ function otherwiseTransform!(wave::AbstractArray{<:Real}, daughters, x̂, fromPl
183183
# real wavelets on real data: that just makes sense
184184
outer = axes(x̂)[2:end]
185185
n1 = size(x̂, 1)
186-
for j in 1:size(daughters, 2)
187-
@views tmp =.* daughters[:,j]
186+
for j = 1:size(daughters, 2)
187+
@views tmp =.* daughters[:, j]
188188
@views wave[:, outer..., j] = fromPlan \ tmp # wavelet transform
189189
end
190190
end
@@ -195,35 +195,34 @@ function otherwiseTransform!(wave::AbstractArray{<:Complex}, daughters, x̂, fro
195195
outer = axes(x̂)[2:end]
196196
n1 = size(daughters, 1)
197197
isSourceEven = mod(size(fromPlan, 1) + 1, 2)
198-
for j in 1:size(daughters, 2)
199-
@views wave[1:n1, outer..., j] = @views x̂[1:n1,outer...] .* daughters[:,j]
200-
@views wave[n1-isSourceEven+1:end, outer..., j] = x̂[n1-isSourceEven+1:end,outer...] .* reverse(conj.(daughters[2:end,j]))
198+
for j = 1:size(daughters, 2)
199+
@views wave[1:n1, outer..., j] = @views x̂[1:n1, outer...] .* daughters[:, j]
200+
@views wave[n1-isSourceEven+1:end, outer..., j] = x̂[n1-isSourceEven+1:end, outer...] .* reverse(conj.(daughters[2:end, j]))
201201
@views wave[:, outer..., j] = fromPlan \ (wave[:, outer..., j]) # wavelet transform
202202
end
203203
end
204204

205205
function reflect(Y, bt)
206206
n1 = size(Y, 1)
207207
if typeof(bt) <: ZPBoundary
208-
base2 = ceil(Int, log2(n1)); # power of 2 nearest to N
209-
x = cat(Y, zeros(2^(base2)-n1, size(Y)[2:end]...), dims=1)
208+
base2 = ceil(Int, log2(n1)) # power of 2 nearest to N
209+
x = cat(Y, zeros(2^(base2) - n1, size(Y)[2:end]...), dims = 1)
210210
elseif typeof(bt) <: SymBoundary
211-
x = cat(Y, reverse(Y,dims = 1), dims = 1)
211+
x = cat(Y, reverse(Y, dims = 1), dims = 1)
212212
else
213213
x = Y
214214
end
215215
return x
216216
end
217217

218218

219-
function cwt(Y::AbstractArray{T}, c::CWT{W}; varArgs...) where {T<:Number, S<:Real, V<: Real,
220-
W<:WaveletBoundary}
221-
daughters,ω = computeWavelets(size(Y, 1), c; varArgs...)
219+
function cwt(Y::AbstractArray{T}, c::CWT{W}; varArgs...) where {T<:Number,W<:WaveletBoundary}
220+
daughters, ω = computeWavelets(size(Y, 1), c; varArgs...)
222221
return cwt(Y, c, daughters)
223222
end
224223

225-
cwt(Y::AbstractArray{T}, w::ContWaveClass; varargs...) where {T<:Number, S<:Real, V<:Real} = cwt(Y,CWT(w); varargs...)
226-
cwt(Y::AbstractArray{T}) where T<:Real = cwt(Y,Morlet())
224+
cwt(Y::AbstractArray{T}, w::ContWaveClass; varargs...) where {T<:Number} = cwt(Y, CWT(w); varargs...)
225+
cwt(Y::AbstractArray{T}) where {T<:Real} = cwt(Y, Morlet())
227226

228227
abstract type InverseType end
229228
struct DualFrames <: InverseType end
@@ -244,35 +243,35 @@ Return the inverse continuous wavelet transform, computed using the simple dual
244243
Return the inverse continuous wavelet transform, computed using the canonical dual frame ``\\tilde{\\widehat{ψ}} = \\frac{ψ̂_n(ω)}{∑_n\\|ψ̂_n(ω)\\|^2}``. The algorithm is to compute the cwt again, but using the canonical dual frame; consiquentially, it is the most computationally intensive of the three algorithms, and typically the best behaved. Will be numerically unstable if the high frequencies of all of the wavelets are too small however, and tends to fail spectacularly in this case.
245244
246245
"""
247-
function icwt(res::AbstractArray, cWav::CWT, inverseStyle::PenroseDelta)
248-
= computeWavelets(size(res,1), cWav)[1]
246+
function icwt(res::AbstractArray, cWav::CWT, ::PenroseDelta)
247+
= computeWavelets(size(res, 1), cWav)[1]
249248
β = computeDualWeights(Ŵ, cWav)
250249
testDualCoverage(β, Ŵ)
251-
compXRecon = sum(res .* β, dims=2)
252-
imagXRecon = irfft(im*rfft(imag.(compXRecon),1), size(compXRecon,1)) # turns out the dual frame for the imaginary part is rather gross in the time domain
250+
compXRecon = sum(res .* β, dims = 2)
251+
imagXRecon = irfft(im * rfft(imag.(compXRecon), 1), size(compXRecon, 1)) # turns out the dual frame for the imaginary part is rather gross in the time domain
253252
return imagXRecon + real.(compXRecon)
254253
end
255254

256-
function icwt(res::AbstractArray, cWav::CWT, inverseStyle::NaiveDelta)
257-
= computeWavelets(size(res,1), cWav)[1]
258-
β = computeNaiveDualWeights(Ŵ, cWav, size(res,1))
255+
function icwt(res::AbstractArray, cWav::CWT, ::NaiveDelta)
256+
= computeWavelets(size(res, 1), cWav)[1]
257+
β = computeNaiveDualWeights(Ŵ, cWav, size(res, 1))
259258
testDualCoverage(β, Ŵ)
260-
compXRecon = sum(res .* β, dims=2)
261-
imagXRecon = irfft(im*rfft(imag.(compXRecon),1), size(compXRecon,1)) # turns out the dual frame for the imaginary part is rather gross in the time domain
259+
compXRecon = sum(res .* β, dims = 2)
260+
imagXRecon = irfft(im * rfft(imag.(compXRecon), 1), size(compXRecon, 1)) # turns out the dual frame for the imaginary part is rather gross in the time domain
262261
return imagXRecon + real.(compXRecon)
263262
end
264263

265-
function icwt(res::AbstractArray, cWav::CWT, inverseStyle::DualFrames)
266-
= computeWavelets(size(res,1), cWav)[1]
264+
function icwt(res::AbstractArray, cWav::CWT, ::DualFrames)
265+
= computeWavelets(size(res, 1), cWav)[1]
267266
canonDualFrames = explicitConstruction(Ŵ)
268267
testDualCoverage(canonDualFrames)
269268
convolved = cwt(res, cWav, canonDualFrames)
270269
ax = axes(convolved)
271-
@views xRecon = sum(convolved[:,i,i,ax[4:end]...] for i=1:size(Ŵ,2))
270+
@views xRecon = sum(convolved[:, i, i, ax[4:end]...] for i = 1:size(Ŵ, 2))
272271
return xRecon
273272
end
274273

275-
icwt(Y::AbstractArray, w::ContWaveClass; varargs...) where {S<:Real, T<:Real, V<:Real} = icwt(Y,CWT(w), PenroseDelta(); varargs...)
276-
icwt(Y::AbstractArray; varargs...) = icwt(Y,Morlet(), PenroseDelta(); varargs...)
274+
icwt(Y::AbstractArray, w::ContWaveClass; varargs...) = icwt(Y, CWT(w), PenroseDelta(); varargs...)
275+
icwt(Y::AbstractArray; varargs...) = icwt(Y, Morlet(), PenroseDelta(); varargs...)
277276

278277
# CWT (continuous wavelet transform directly) TODO: direct if sufficiently small

src/averagingTypes.jl

Whitespace-only changes.

0 commit comments

Comments
 (0)