-
Notifications
You must be signed in to change notification settings - Fork 11
/
lpc2c.jl
33 lines (29 loc) · 864 Bytes
/
lpc2c.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function lpc2c!(c::AbstractVector, a::AbstractVector, loggain::Bool=false)
@assert length(a) == length(c)
m = length(a) - 1
fill!(c, zero(eltype(c)))
if loggain
c[1] = a[1]
else
c[1] = log(a[1])
end
c[2] = -a[2]
for k=3:m+1
d = 0.0
upperlimit = (k >= m+1) ? m+1 : k
for i=2:upperlimit
d += (i-1) * c[i] * a[k-i+1]
end
c[k] = -d / (k-1) - a[k]
end
c
end
lpc2c(a::AbstractVector, loggain::Bool=false) = lpc2c!(similar(a), a, loggain)
function lpc2c(state::SpectralParamState{LinearPredictionCoef})
assert_not_ready_to_filt(state)
def = paramdef(state)
newdef = LinearCepstrum(param_order(def))
data = rawdata(state)
SpectralParamState(newdef, lpc2c(data, has_loggain(state)),
true, gain_normalized(state))
end