Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Savitzky Golay filter #22

Open
lnacquaroli opened this issue Nov 26, 2019 · 2 comments
Open

Savitzky Golay filter #22

lnacquaroli opened this issue Nov 26, 2019 · 2 comments

Comments

@lnacquaroli
Copy link

Hi there,

Please see here. Apparently the implementation of the SG filter from Qlab is not fully correct. I check with yours here and I got the following:

julia> x = [1,2,3,4,5,6,7,8,9,10]
julia> SavitzkyGolay(x, 0, 1, 5)
1×10 LinearAlgebra.Adjoint{Float64,Array{Float64,1}}:
 1.2  2.0  3.0  4.0  5.0  6.0  7.0  8.0  6.8  5.4

It seems that the SG should produce the same input x for this case. I checked with Matlab sgolayfilt and it does give [1,2,3,4,5,6,7,8,9,10]. Looks like the edges are distorted. In the Qlab implementation we have the same problem:

savitzkyGolay2(x,5,1)
10-element Array{Float64,1}:
 1.6000000000000003
 2.200000000000001 
 3.0               
 4.0               
 5.000000000000001 
 6.000000000000001 
 7.0               
 8.0               
 8.8               
 9.400000000000002 
@caseykneale
Copy link
Owner

Not sure what QLab is?

I've been having a bugger of a time with Sgolay, using DSP.jl broke my package a few weeks ago, and I had to write my own Conv1D function etc.

Yes the edges do appear distorted relative to Matlabs implementation. The tricky part is this, savitsky golay loses information at the edges by doing the convolution, it's inevitable. Basically it's an FIR filter if I recall correctly. So some implementations, I think, enforce different boundary conditions, IE: mirror, repeating, set to 0, etc. I haven't looked at your example yet - but I can try to make it match more closely to matlab if you want.

Thank you again for the heads up!

@lnacquaroli
Copy link
Author

Hi thanks for the reply.

Yeah, it was someone who actually posted that the data filter did not match that one from Matlab's. But, in any case, are just the edges, as you said. I actually found another SG implementation a bit old, using generated functions, that has the same issue.

The DSP.jl seems to work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants