-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extend
lpc
to complex inputs, other fixes (#517)
* try to fix types, reduce allocs * eliminate allocs - use rev_buf to eliminate allocs as much as possible - changed multiple assignment so that `@views` macro can be used on outer loop * also for `LPCLevinson` * reflection_coeffs, `levinson` and `arburg` - taking reference from PR 171 - separate `levinson` and `arburg` from `lpc` and export - reflection coefficients - `p::Integer` * promote_type in arburg - not sure if arburg handles complex arguments, but just in case. * extend `lpc` for complex signals - add test for complex - error for levinson is weirdly high - test errors more often than original, cannot figure out why * scaling for `xcorr` extra keyword argument for scaling in xcorr, fixes large prediction_error in levinson * revert to test `all(<(0.01), ...)` * arburg recursion relation * handle union types * lpc docs * verified against matlab * a -> -a * use `dotu` * don't pop extra * 1.0 compat 1.0 doesn't support `CartesianIndices` with `StepRange`? * insert `muladd`s * forgot `abs` * add tests - error should be close to std of rand function which is 1 - test `dotu` with different eltypes * complex Int for dotu * move `conv` down * xcorr scaling for integer * explicit returns Co-authored-by: Martin Holters <[email protected]> * add tests * comments, cleanup - removed redundant type parameters from drafting - add ! to mark possibly mutating function - note to write an autocorr function --------- Co-authored-by: Martin Holters <[email protected]>
- Loading branch information
1 parent
8a93c2a
commit b26bc60
Showing
5 changed files
with
180 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# `LPC` - Linear Predictive Coding | ||
```@docs | ||
lpc | ||
lpc(::AbstractVector{Number}, ::Int, ::LPCBurg) | ||
lpc(::AbstractVector{Number}, ::Int, ::LPCLevinson) | ||
arburg | ||
levinson | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
# Filter some noise, try to learn the coefficients | ||
@testset "$method" for method in (LPCBurg(), LPCLevinson()) | ||
coeffs = [1, .5, .3, .2] | ||
x = filt([1], coeffs, randn(50000)) | ||
@testset "$T" for T in (Float64, ComplexF64) | ||
coeffs = T <: Complex ? [1, 0.5 + 0.2im, 0.3 - 0.5im, 0.2] : [1, .5, .3, .2] | ||
x = filt(1, coeffs, randn(T, 50000)) | ||
|
||
# Analyze the filtered noise, attempt to reconstruct the coefficients above | ||
ar, e = lpc(x[1000:end], length(coeffs)-1, method) | ||
# Analyze the filtered noise, attempt to reconstruct the coefficients above | ||
ar, e = lpc(x[1000:end], length(coeffs)-1, method) | ||
|
||
@test all(abs.([1; ar] .- coeffs) .<= 1e-2) | ||
@test all(<(0.01), abs.(ar .- coeffs[2:end])) | ||
@test isapprox(e, 1; rtol=0.01) | ||
end | ||
end | ||
|
||
# test dotu, levinson with complex Int coefficients | ||
@test isapprox(levinson(complex(1:10), 3)[1] |> real, -[1.25, 0, 0.25]) | ||
|
||
# test that lpc defaults to Burg | ||
@test let v = rand(1000) | ||
lpc(v, 20) == lpc(v, 20, LPCBurg()) | ||
end |