forked from JuliaDSP/DSP.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'unwrap' of https://github.com/platawiec/DSP.jl into unwrap
- Loading branch information
Showing
9 changed files
with
71 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# `Estimation` - parametric estimation functions | ||
|
||
```@docs | ||
esprit | ||
``` |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Estimation | ||
import Base: * | ||
|
||
export esprit | ||
|
||
""" | ||
esprit(x::AbstractArray, M::Integer, p::Integer, Fs::Real=1.0) | ||
ESPRIT [^Roy1986] algorithm for frequency estimation. | ||
Estimation of Signal Parameters via Rotational Invariance Techniques | ||
Given length N signal "x" that is the sum of p sinusoids of unknown frequencies, | ||
estimate and return an array of the p frequencies. | ||
# Arguments | ||
- `x::AbstractArray`: complex length N signal array | ||
- `M::Integer`: size of correlation matrix, must be <= N. | ||
The signal subspace is computed from the SVD of an M x (N-M+1) signal matrix | ||
formed from N-M+1 length-M shifts of the signal x in its columns. | ||
For best performance for 1 sinusoid, use M = (N+1)/3 (according to van der Veen and Leus). | ||
For faster execution (due to smaller SVD), use small M or small N-M | ||
- `p::Integer`: number of sinusoids to estimate. | ||
- `Fs::Float64`: sampling frequency, in Hz. | ||
# Returns | ||
length p real array of frequencies in units of Hz. | ||
[^Roy1986]: R Roy, A Paulraj and T Kailath, ESPRIT - A subspace approach to estimation of parameters of cisoids in noise, IEEE Trans. Acoustics, Speech, Signal Process., 34, 1340-1342 (1986). [url](http://ieeexplore.ieee.org/abstract/document/1164935/). | ||
""" | ||
function esprit(x::AbstractArray, M::Integer, p::Integer, Fs::Real=1.0) | ||
count(v->v != 1, size(x)) <= 1 || error("`x` must be a 1D signal") | ||
N = length(x) | ||
X = x[ (1:M) .+ (0:N-M)' ] | ||
U,s,V = svd(X) | ||
D,_ = eig( U[1:end-1,1:p] \ U[2:end,1:p] ) | ||
angle.(D)*Fs/2π | ||
end | ||
|
||
end # end module definition |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using DSP, Compat, Compat.Test | ||
|
||
@testset "esprit" begin | ||
# create a sum of sinusoids in noise, and estimate their frequencies | ||
Fs = 10000.0 # sampling frequency in Hz | ||
duration = 1 # length of signal, in seconds | ||
n = Int(Fs * duration) # number of samples | ||
t = collect((1:n)/Fs) # time vector | ||
frequencies = [1000.0 1250.0] | ||
amplitudes = [2.0 1.5] | ||
phases = [0.7 -1.0] | ||
x = exp.( 1im*2*π*t*frequencies .+ phases) * amplitudes' | ||
noise = randn(n, 2)*[1;1im] | ||
sigma = 0.1 | ||
noise *= sigma | ||
x += noise | ||
M = 300 | ||
p = 2 # number of sinusoids to estimate | ||
frequencies_estimated = esprit(x, M, p, Fs) | ||
@test isapprox(frequencies', frequencies_estimated; atol = 1e-2) | ||
end | ||
|
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