savitzky-golay | Savitzky–Golay filter | Widget library
kandi X-RAY | savitzky-golay Summary
kandi X-RAY | savitzky-golay Summary
Savitzky–Golay filter
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of savitzky-golay
savitzky-golay Key Features
savitzky-golay Examples and Code Snippets
Community Discussions
Trending Discussions on savitzky-golay
QUESTION
I try to write a loop for my Savitzky-Golay filter code, I have ten columns, and try to repeat them on each column with same process.
Sample dataset:
...ANSWER
Answered 2021-Dec-09 at 14:40library(tidyverse)
library(signal)
#>
#> Attaching package: 'signal'
#> The following object is masked from 'package:dplyr':
#>
#> filter
#> The following objects are masked from 'package:stats':
#>
#> filter, poly
PLOT1500 <- structure(list(
system = c(
"1-Jan-16", "2-Jan-16", "3-Jan-16",
"4-Jan-16"
), evi1500 = c(0.437, 0.3891771, 0.493, 0.261), evi21500 = c(
0.467436348,
0.186, 0.446531, 0.386620096
), kndvi1500 = c(
0.686, 0.413083514,
0.452461736, 0.508
), ndvi1500 = c(0.482, 0.57, 0.461, 0.198),
nirv1500 = c(0.453765489, 0.624, 0.694, 0.457), evi2500 = c(
0.439085339,
0.415, 0.447462363, 0.683
), evi22500 = c(
0.391, 0.715, 0.394061226,
0.382846651
), kndvi2500 = c(
0.452913701, 0.414950345, 0.420522988,
0.475
), ndvi2500 = c(0.32139863, 0.515688255, 0.427, 0.427274026), nirv2500 = c(0.491, 0.173, 0.444, 0.471)
), row.names = c(
NA,
4L
), class = "data.frame")
# need more rows for filter
PLOT1500 <- PLOT1500 %>%
list() %>%
rep(10) %>%
bind_rows()
sg <- sgolay(p = 7, n = 11, m = 0)
PLOT1500 %>%
mutate(across(matches("1500|2500"), ~ signal::filter(sg, .x)))
#> system evi1500 evi21500 kndvi1500 ndvi1500 nirv1500 evi2500
#> 1 1-Jan-16 0.4317215 0.4655495 0.6840037 0.4747651 0.4510836 0.4454103
#> 2 2-Jan-16 0.4231690 0.1996236 0.4273279 0.6157175 0.6402125 0.3747353
#> 3 3-Jan-16 0.4056273 0.4036501 0.4091449 0.3485501 0.6573740 0.5481791
#> 4 4-Jan-16 0.3696906 0.4656374 0.5812905 0.3199554 0.4881796 0.5678016
#> 5 1-Jan-16 0.3757619 0.3668323 0.6085295 0.4559650 0.4623747 0.4794025
#> 6 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 7 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 8 4-Jan-16 0.3391415 0.4079327 0.5283815 0.3073739 0.5039268 0.5884699
#> 9 1-Jan-16 0.3970425 0.4001966 0.5975225 0.4453961 0.4912674 0.4797898
#> 10 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 11 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 12 4-Jan-16 0.3391415 0.4079327 0.5283815 0.3073739 0.5039268 0.5884699
#> 13 1-Jan-16 0.3970425 0.4001966 0.5975225 0.4453961 0.4912674 0.4797898
#> 14 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 15 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 16 4-Jan-16 0.3391415 0.4079327 0.5283815 0.3073739 0.5039268 0.5884699
#> 17 1-Jan-16 0.3970425 0.4001966 0.5975225 0.4453961 0.4912674 0.4797898
#> 18 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 19 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 20 4-Jan-16 0.3391415 0.4079327 0.5283815 0.3073739 0.5039268 0.5884699
#> 21 1-Jan-16 0.3970425 0.4001966 0.5975225 0.4453961 0.4912674 0.4797898
#> 22 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 23 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 24 4-Jan-16 0.3391415 0.4079327 0.5283815 0.3073739 0.5039268 0.5884699
#> 25 1-Jan-16 0.3970425 0.4001966 0.5975225 0.4453961 0.4912674 0.4797898
#> 26 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 27 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 28 4-Jan-16 0.3391415 0.4079327 0.5283815 0.3073739 0.5039268 0.5884699
#> 29 1-Jan-16 0.3970425 0.4001966 0.5975225 0.4453961 0.4912674 0.4797898
#> 30 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 31 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 32 4-Jan-16 0.3391415 0.4079327 0.5283815 0.3073739 0.5039268 0.5884699
#> 33 1-Jan-16 0.3970425 0.4001966 0.5975225 0.4453961 0.4912674 0.4797898
#> 34 2-Jan-16 0.4141707 0.2904986 0.4728216 0.5251263 0.6016812 0.4315946
#> 35 3-Jan-16 0.4298224 0.3879595 0.4608195 0.4331037 0.6318901 0.4846934
#> 36 4-Jan-16 0.3451485 0.4596679 0.5446130 0.2676971 0.4990481 0.6103875
#> 37 1-Jan-16 0.3450376 0.3682986 0.5828770 0.3919248 0.4595737 0.5307030
#> 38 2-Jan-16 0.4498211 0.2610299 0.5040675 0.6315108 0.6015259 0.3519612
#> 39 3-Jan-16 0.4715542 0.4178171 0.4158430 0.4391927 0.7055284 0.4700416
#> 40 4-Jan-16 0.2641572 0.3910584 0.5137794 0.2011921 0.4549914 0.6796653
#> evi22500 kndvi2500 ndvi2500 nirv2500
#> 1 0.3907501 0.4538682 0.3229697 0.4910148
#> 2 0.7147841 0.4090610 0.5045815 0.1746777
#> 3 0.4045248 0.4343358 0.4605200 0.4302151
#> 4 0.3368979 0.4619705 0.3704317 0.5191066
#> 5 0.4902738 0.4516159 0.3837821 0.3961985
#> 6 0.5884952 0.4243567 0.4615026 0.2884093
#> 7 0.4510686 0.4302815 0.4409619 0.4001168
#> 8 0.3940673 0.4595071 0.4097488 0.4628453
#> 9 0.4492767 0.4492416 0.3791475 0.4276285
#> 10 0.5884952 0.4243567 0.4615026 0.2884093
#> 11 0.4510686 0.4302815 0.4409619 0.4001168
#> 12 0.3940673 0.4595071 0.4097488 0.4628453
#> 13 0.4492767 0.4492416 0.3791475 0.4276285
#> 14 0.5884952 0.4243567 0.4615026 0.2884093
#> 15 0.4510686 0.4302815 0.4409619 0.4001168
#> 16 0.3940673 0.4595071 0.4097488 0.4628453
#> 17 0.4492767 0.4492416 0.3791475 0.4276285
#> 18 0.5884952 0.4243567 0.4615026 0.2884093
#> 19 0.4510686 0.4302815 0.4409619 0.4001168
#> 20 0.3940673 0.4595071 0.4097488 0.4628453
#> 21 0.4492767 0.4492416 0.3791475 0.4276285
#> 22 0.5884952 0.4243567 0.4615026 0.2884093
#> 23 0.4510686 0.4302815 0.4409619 0.4001168
#> 24 0.3940673 0.4595071 0.4097488 0.4628453
#> 25 0.4492767 0.4492416 0.3791475 0.4276285
#> 26 0.5884952 0.4243567 0.4615026 0.2884093
#> 27 0.4510686 0.4302815 0.4409619 0.4001168
#> 28 0.3940673 0.4595071 0.4097488 0.4628453
#> 29 0.4492767 0.4492416 0.3791475 0.4276285
#> 30 0.5884952 0.4243567 0.4615026 0.2884093
#> 31 0.4510686 0.4302815 0.4409619 0.4001168
#> 32 0.3940673 0.4595071 0.4097488 0.4628453
#> 33 0.4492767 0.4492416 0.3791475 0.4276285
#> 34 0.5884952 0.4243567 0.4615026 0.2884093
#> 35 0.4510686 0.4302815 0.4409619 0.4001168
#> 36 0.3252712 0.4647988 0.3890248 0.5228858
#> 37 0.4673952 0.4575471 0.3958628 0.4115581
#> 38 0.6558883 0.4145530 0.4540116 0.2368532
#> 39 0.4171119 0.4201153 0.4513231 0.4188209
#> 40 0.3792356 0.4751102 0.4234683 0.4749589
QUESTION
I wrote a function to apply a savitzky golay filter to each row in a data.table. The first column having measurement values is given as an argument and all later columns contain measurements values to be filtered too. The processed rows are updated in-place.
My function works, but is slow.
How could the function be changed in order to work more efficient and more data.table like?
MWE:
...ANSWER
Answered 2021-Jun-03 at 19:46Try:
QUESTION
I'm currently trying to render the same results in R
as in Python
but think I must be misunderstanding the Savitzky-Golay filter. I have the below Python
code:
ANSWER
Answered 2021-May-28 at 12:14The SciPy function savgol_filter
has several options for handling the ends of the input array; see the mode
parameter in the docstring.
It looks like the behavior of the R function savgol
corresponds to mode='constant'
in SciPy's savgol_filter
. Except for the first value (which is effectively 0 in both cases), this output of savgol_filter
matches the output of savgol
in R:
QUESTION
I have the following time series data set:
...ANSWER
Answered 2020-Oct-07 at 13:16This actually worked:
QUESTION
I would like to apply a Savitzky-Golay filter (prospectr package) to a dataset. However, all the examples available run the filter for only one sample (curve with a determined number of wavelengths). Is there anyway I can filter the data of more samples (70 samples) at once?
...ANSWER
Answered 2020-Aug-10 at 22:50Usually spectral data matrices are organized with observations (samples) in rows and (spectral) variables in columns. The savitzkyGolay function does work for multiple observations. A proper way to call the function for your data is:
QUESTION
I need to optimise a method for finding the number of data peaks in a 1D array. The data is a time-series of the amplitude of a wav file.
I have the code implemented already:
...ANSWER
Answered 2020-Jun-06 at 15:12Look at 0d persistent homology to find a good strategy, where the parameter you can optimize for is peak persistence. A nice blog post here explains the basics.
But in short the idea is to imagine your graph being filled by water, and then slowly draining the water. Every time a piece of the graph comes above water a new island is born. When two islands are next to each other they merge, which causes the younger island (with the lower peak) to die.
Then each data point has a birth time and a death time. The most significant peaks are those with the longest persistence, which is death - birth
.
If the water level drops at a continuous rate, then the persistence is defined in terms of peak height. Another possibility is by dropping the water instantaneously from point to point as time goes from step t
to step t+1
, in wich case the persistence is defined in peak width in terms of signal samples.
For you it seems that using the original definition in terms of peak height > 70 finds all peaks you are interested in, albeit possibly too many, clustered together. You can limit this by choosing the first peak in each cluster or the highest peak in each cluster or by doing both approaches and only choosing peaks that have both great height persistence as well as width persistence.
QUESTION
I'm computing the first and second derivatives of a signal and then plot. I chose the Savitzky-Golay filter as implemented in SciPy (signal module). I'm wondering if the output needs to be scaled - in the Matlab implementation of the same filter, it is specified that scaling is needed on the output of the filter:
savitzkyGolayFilt(X,N,DN,F) filters the signal X using a Savitzky-Golay (polynomial) filter. The polynomial order, N, must be less than the frame size, F, and F must be odd. DN specifies the differentiation order (DN=0 is smoothing). For a DN higher than zero, you'll have to scale the output by 1/T^DN to acquire the DNth smoothed derivative of input X, where T is the sampling interval.
However, I didn't find anything similar in SciPy's documentation. Has anybody tried and knows if the output in Python is correct and needs no further scaling? The line of code I'm running for the first derivative is this one: first_deriv = signal.savgol_filter(spectra_signal,sigma=7,2, deriv=1, delta=3.1966)
The spectra_signal is my "y" variable and delta is the variation of "x" variable.
Also, I tried to compute the first derivative without using the savgol_filter, but using np.diff
on the smoothed signal instead (based on the formula derivative = dy/dx).first_deriv_alternative = np.diff(signal.savgol_filter(spectra_signal, sigma=7,2))/3.1966
. And the results are not the same.
Working code example:
...ANSWER
Answered 2020-May-06 at 12:18Under the hood signal.savgol_filter
uses signal.savgol_coeffs
if you look a the source code it says that "The coefficient assigned to y[deriv] scales the result to take into account the order of the derivative and the sample spacing". The results are hance scaled before performing the fitting and the convolve1d
. So by default, it seems that the results are already scaled taking into account the order of derivatives.
I think that performing the derivative after computing Savitzky-Golay filter won't give you the same results because in this case, you are computing the derivative on the spectrum already filtered, while in the first case you are performing the derivative before performing the fitting and the scaling.
QUESTION
I need to reduce my noise like behavior in my data. I tried one of the method called Savitzky-Golay Filter . On the other hand, I need to find fastest method, because the filtering algorithm will be in the most running script in my code.
I am not familiar with the signal processing methods. Can you suggest faster methods and usage of them briefly?
I do not need complex structure like low-pass, high-pass etc (I know there are thousands of them). As fast as possible smoothening method is what I want to use.
Here my test script:
...ANSWER
Answered 2020-Feb-06 at 12:19Unless you really need polynomial-based smoothing, Savitzky-Golay does not have any particular advantages. It's basically a bad lowpass filter. For more details, see https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=5888646
Using a basic Butterworth lowpass filter instead:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install savitzky-golay
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page