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

Moving average function #381

Open
Luapulu opened this issue Oct 21, 2020 · 4 comments
Open

Moving average function #381

Luapulu opened this issue Oct 21, 2020 · 4 comments

Comments

@Luapulu
Copy link

Luapulu commented Oct 21, 2020

So, while I know it's not difficult to write a moving average function, I find I often need to calculate moving averages, and since moving averages are often used as and act like low pass filters, I feel like they ought to belong in a package like DSP.

If there's interest, I'd like to make a pull request for an implementation of a moving average function, a moving average function that repeatedly averages over a signal n times as well as mutating/non-mutating versions as appropriate. It may also be worth it to use conv / filter at some length / number of repeated averages, especially since multiple moving averages can probably be expressed as a convolution, requiring only one pass over a signal.

@galenlynch
Copy link
Member

Isn't this just convolution with a "boxcar" window?

@Luapulu
Copy link
Author

Luapulu commented Apr 27, 2021

What about repeated moving averages?

@galenlynch
Copy link
Member

My understanding is that a repeated moving average can be accomplished by convolving the rectangular window with itself however many times the average is repeated, and then convolve the resulting filter with the data to be averaged over.

Anyways if you're interested in putting together a PR to make this process easier, I think that might be useful.

@justinbroce
Copy link

I wrote a moving average filter for some dsp purposes, I and am somewhat unsure of how to submit a pull request, or if it is appropriate.

function moving_average(x::AbstractArray,M::Integer)
    
    M > 1 || error("window size must be larger that 1")
    conv(x,rect(M)/M)[M ÷ 2 + 1 : length(x) + M÷2]

end

The output is the same as a python implementation I saw.

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

No branches or pull requests

3 participants