1
$\begingroup$

I want to estimate the rolling average of a time series B using a Gaussian window. The equation to do this would correspond to

$$\tilde{B_{s}}(t_{n}) = \frac{1}{A_{s}} \sum_{t_{m}= t_{n}-3s}^{t_{n}+3s}B(t_{m})e^{-\frac{(t_{m} -t_{n})^{2}}{2s^{2}}}$$

where $$ A_{s} = \sum_{t_{m}= t_{n}-3s}^{t_{n}+3s}e^{-\frac{(t_{m} -t_{n})^{2}}{2s^{2}}}$$

I am aware that pandas has a an option for a gaussian window.

For example see https://stackoverflow.com/questions/27099555/gaussian-kernel-density-smoothing-for-pandas-dataframe-resample

However, I am not sure if it is equivalent to the version of Gaussian averaging that I am interested in using.

So my questions are:

In

hrly = pd.Series(hourly[0][344:468]) 
smooth = hrly.rolling(window=5, win_type='gaussian', center=True).mean(std=0.5)
  1. Is the win_type='gaussian' going to give me the desired result?
  2. What is the role of std=0.5?
  3. If I wanted to do this using .apply() and use a manual function, how should the function be like?
$\endgroup$

2 Answers 2

3
$\begingroup$
  1. Don't you really just want to convolve? Then I'd propose you do that.
  2. std means standard deviation; that's the $\sigma$ ou usually see in the definition of the Gaussian. Its "width". In your formula, it looks like the $s$, but I'm not 100% sure your $A_s$ actually is the same as the usual Gaussian pre-factor. Check against the usual definition of the Gaussian!
  3. that I don't know, but it's really not a signal processing, but a Pandas/Python programming "craft" question -> asking (searching, first) on Stackoverflow "How do I .apply a function manually" is probably a good idea.
$\endgroup$
1
  • $\begingroup$ Thanks for the reply! Is the operation I am looking for equivalent to a convolution? $\endgroup$
    – Jokerp
    Sep 8, 2022 at 6:29
0
$\begingroup$
  1. Yes it does (See SciPy's Gaussian Window). Yet it won't filter the edges.
  2. This is the $\sigma$ parameter in your equation.
  3. It is better to use the built in tool in this case. It will be much faster. Just remember to handle the edges.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.