DSP.jl
DSP.jl copied to clipboard
Moving average function
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.
Isn't this just convolution with a "boxcar" window?
What about repeated moving averages?
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.
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.