Moving Average Filter not working

8 views (last 30 days)
Mania Mamakon
Mania Mamakon on 7 Apr 2022
Edited: Jan on 7 Apr 2022
Hey!
So i have this moving average filter that works completely when I'm inserting it directly as code but somehow will return a unfiltered signal when made into a function and calling up into code.
The function
function vectordata = filter_outlier_dwars(vectordata);
M_dwarsversnelling = 100;
for n = 1:M_dwarsversnelling-1
outlierloos_dwars(n) = vectordata(n);
end
for n = M_dwarsversnelling:length(vectordata)
TemporaryVariable = 0;
for m = 1:M_dwarsversnelling
TemporaryVariable = TemporaryVariable + vectordata(n-m+1);
end
outlierloos_dwars(n) = TemporaryVariable/M_dwarsversnelling;
end
The call up
outlierloos_dwars = filter_outlier_dwars(offsetloos_dwarsversnelling);
Thanks in advance!

Answers (1)

Jan
Jan on 7 Apr 2022
Edited: Jan on 7 Apr 2022
Replace the output variable in the first line:
function vectordata = filter_outlier_dwars(vectordata)
% ==>
function outlierloos_dwars = filter_outlier_dwars(vectordata)
With your code you apply the filter but reply the input data.
BY the way, movavg() and filter() are much faster ways.

Tags

Community Treasure Hunt

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

Start Hunting!