Is this code for doing a moving average correct?
I want to filter my speech signal with moving average filter in code. I think that I can use convolution for this.
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It only takes a minute to sign up.Sign up to join this community
Presuming you are using Matlab or GNU Octave, then yes, that should be OK. Compare with this tutorial on doing a moving average with convolution.
You've done the division on your kernel, but it makes no mathematical difference whether you do it there or after the convolution. Practically, it takes less time if you do it your way (scaling the kernel.)
You may find that a moving average is not adequate for audio processing. You will then need to look into creating filters with the appropriate methods in Matlab. Some keywords to search for together with Matlab: filter, butter.
Good suggestion from @jojek. The smooth does a moving average by convolution, but has other options as well. It can also make use of a GPU to speed things up if you have a truly massive amount of data to be filtered.
Yes, this code is correct for implementing a moving average filter.
Nevertheless I do recommend to use the in-built smooth function in MATLAB.
y = smooth(x, 100, 'moving')