I need to implement moving average digital filter for post processing of some recorded oscilloscope waveforms in Scilab. I have prepared a script with below given code (the recursive implementation with averaging window containing 256 samples)
// number of samples
N = 350000;
// vector of voltage samples
voltage = M(1:N, 2)';
// filtered values
filt_voltage = zeros(1:N);
// window length
L = 256;
// sum of the samples in the averaging window
sum = 0
for i = 1:N_01
// averaging window full?
if i > L
// remove the oldest sample in the averaging window
sum = sum - voltage(i - L);
end
// add the newest sample into the averaging window
sum = sum + voltage(i);
// average of the samples in the averaging window
filt_voltage(i) = sum/L;
end
The script output is following (blue waveform - the recorded data, red waveform - filtered data)
The problem is that I am not sure whether me moving average implementation is correct (I have found a lot of implementations mostly based on convolution). The output seems to be somehow filtered but it would be helpful for me if anybody can confirm to me that it is correct. Thanks in advance.
There is nothing wrong with your implementation. In fact, it is a common implementation of the recursive formulation given on stats.stackexchange.com and on wikipedia: