09-05-2018 01:07 PM
Simple program for moving average. It extend border of array and apply filter (square with chosen length mean at each point). Then it come back to initial size.
Solved! Go to Solution.
09-05-2018 01:32 PM
There is a place for example programs.
Looking at the code for a nanosecond:
09-05-2018 01:57 PM - edited 09-05-2018 02:15 PM
1. That would provide different result.
2. Do not got that point.(generally that is sub-VI, I do no care about front panel). That was for testing.
3. Agree, replace would work faster.
3. Moving average is the convolution with squire or circle with constant matrix. I though that my code would work faster. At that case. But I like using convolution, it could make any type of filter from my code. Thanks!
Any array would work for me.
That is an actual example.
Thank you for your comments!
P.S. I planned to exchange http://www.ni.com/example/26681/en/ with repeating border padding.
09-05-2018 02:29 PM - edited 09-05-2018 02:30 PM
@BrainBurn wrote:
1. That would provide different result.
2. Do not got that point.(generally that is sub-VI, I do no care about front panel). That was for testing.
3. Agree, replace would work faster.
3. Moving average is the convolution with squire or circle with constant matrix. I though that my code would work faster. At that case. But I like using convolution, it could make any type of filter from my code. Thanks!
A convolution based approach gives the same result*, here's a quick example. But test for yourself! (The length here is manipulated to give the same result as with your "length" definition.
*Note that there are differences near the edges of the result, because the convolution truncates while you bunch the outside values into the boundary values. Not sure what is more desirable.
(Even if you do it explicitly, you don't need the padding if done correctly.)
What does the attached csv file have to do with the question? Is that in input? result? Something else?
09-05-2018 03:48 PM
@altenbach wrote:(Even if you do it explicitly, you don't need the padding if done correctly.)
Just for fun, Here is a direct comparison of the stock convolution and an explicit mimic that gives the same result. This is useful if you only have "LabVIEW base" where the convolution tools are not included.
As I said, no padding needed because indexing outside an array just returns zero (you cannot use that method for "array subset", of course).
The code could be significantly optimized for inplaceness and the outer loop could even be parallelized. This is just a very rough draft. There are many other (even better) ways to do it, of course.