## How to decide window size for a moving average filter?

### Swanand Kulkarni (view profile)

on 6 Dec 2016
Latest activity Answered by Greg Heath

on 9 Mar 2019

### Image Analyst (view profile)

Hello all, I have some noisy data in the form of x and y variables. I plan to use moving average filer to get satisfactory results, yet as close as possible to the real data. I understand that higher window size means more smooth data, and hence less realistic. Is that correct? Is window size of 5 considered decent enough to establish relationship between the variables in general? Any leads are highly appreciated. Thanks and regards, Swanand.

### Image Analyst (view profile)

on 7 Dec 2016
Edited by Image Analyst

### Image Analyst (view profile)

on 28 Jan 2019

It could be. Who's to say? It's more or less of a judgement call as to what amount of smoothing is best, isn't it. You could determine the sum of absolute differences for different window sizes and plot it. Maybe some pattern will jump out at you, like a knee in the curve.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
numPoints = 5000;
noiseSignal = rand(1, numPoints);
x = linspace(0, 300, numPoints);
period = 100;
cleanSignal = cos(2*pi*x / period);
noisySignal = cleanSignal + noiseSignal;
subplot(2, 1, 1);
plot(x, noisySignal, 'b-', 'LineWidth', 2);
grid on;
xlabel('x', 'FontSize', fontSize);
ylabel('Noisy Signal', 'FontSize', fontSize);
windowSizes = 3 : 3 : 51
for k = 1 : length(windowSizes)
smoothedSignal = movmean(noisySignal, windowSizes(k));
end
subplot(2, 1, 2);
grid on;
xlabel('Window Size', 'FontSize', fontSize);
Pick the smallest window size where the SAD seems to start to flatten out. Going beyond that (to larger window sizes) really doesn't produce much more benefit (smoothing) and will take longer.

Ekaterina Wiktorski

### Ekaterina Wiktorski (view profile)

on 7 Mar 2019
My SAD looks like this, what does it mean?
Image Analyst

### Image Analyst (view profile)

on 7 Mar 2019
You probably have periodic structures in your signal (which you forgot to attach).
Ekaterina Wiktorski

### Ekaterina Wiktorski (view profile)

on 8 Mar 2019
Yes! That's exactly the case!

### Walter Roberson (view profile)

on 7 Dec 2016

A moving average filter is one of the varieties of discrete lowpass filter. You can choose your width according to your attenuation needs. See http://ptolemy.eecs.berkeley.edu/eecs20/week12/freqResponseRA.html

### Siyab Khan (view profile)

on 28 Jan 2019

How can we select a wind size for the selection of DNA sequence like
ATCGGGCTTACGG
window length size 5 to read the sequence please drop the code.

Image Analyst

### Image Analyst (view profile)

on 28 Jan 2019
I don't understand the question. How is a sequence of letters analogous to a noisy numerical signal?
Let's say the window size was 5. What would you expect the output to be for that short sequence you gave? Explain why/how you got that output.
Siyab Khan

### Siyab Khan (view profile)

on 28 Jan 2019
basically i am working on the CLassificaion of DNA sequence using neural networks i have a DNA sequcence like
ATCGTGGCCAATGGTAACCG...... upto 500 0r more Nucleotides
i converted it to binary now i want my network read a stream of five charecters 10 and 15 so how to write code for it'
Image Analyst

### Image Analyst (view profile)

on 28 Jan 2019
I don't know what that means. Do you want to read 5 characters from somewhere? Or 10? Or 15? Where is this stream coming from? A file? If so, have you seen fread()?

### Greg Heath (view profile)

on 9 Mar 2019

I'm very surprised that none of the previous responses mentioned
1. Determine characteristic self correlation lengths using output autocorrelation functions
2.. Determine characteristic cross correlation lengths using
input-output crosscorrelation functions
Hope this helps.
Greg