Clear Filters
Clear Filters

Moving average with reducing sampling

3 views (last 30 days)
Omar Aljanaideh
Omar Aljanaideh on 30 Nov 2017
Edited: Omar Aljanaideh on 30 Nov 2017
The following is a moving average filter that uses an average of 50 samples of input signal using embedded matlab function. Beside this, How can i reduce the number of samples of output. i.e: after i get the averaged output y, how i get only one averaged value from each 100 averaged samples of y, Such that if i will reduce the sampling of the signal will be changed, if the sampling at input is 1 ms, at output will be 100 ms the output port.
function y = my_average(u) %# codegen
persistent i buf bufSum;
if isempty(buf)
buf = zeros(1,50);
bufSum = 0;
i = 1;
end
bufSum = bufSum - buf(i);
buf(i) = u;
bufSum = bufSum + u;
i = i + 1;
if i > numel(buf)
i = 1;
end
y = bufSum / numel(buf);

Answers (0)

Categories

Find more on Statistics and Linear Algebra in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!