# window size of a median filter

#### kokkie_d

Joined Jan 12, 2009
72
Hi,

I am using a median filter in Matlab on data I have collected and was wondering if there are any rules to setting the window size? Is there - for example - a rule that calculates the optimal window size based on number of available data points per second?

cheers,

#### MrChips

Joined Oct 2, 2009
30,802
A median filter is a simple way to smooth out high frequency noise. It is a low-pass filter. You can determine the effect by considering the sampling frequency or period. If your sampling frequency is 1ksps, the period is 1ms. Hence if your window is 4 points, you are averaging over 4ms, i.e. attenuating signals above 250Hz. (This is only an approximate analysis).

#### kokkie_d

Joined Jan 12, 2009
72
Thanks MrChips,

Guess I was being a Loosewire behind my keyboard. lol been staring me blind on a problem and stopped looking at the basics.

The problem I have is that I have data of a signal, which has very large outliers over a fairly large range (time wise) and I would like to smooth it out. Any suggestions?

#### MrChips

Joined Oct 2, 2009
30,802
What is an outlier?

#### kokkie_d

Joined Jan 12, 2009
72
(maybe I am not using the correct word) outlier = value of data that clearly are far of the average.

Basically, I measure a signal which is crosses the zero line like a sinewave. I analyse when the signal crosses the zero line and establish its period / frequency. but because of jitter on the signal I now and then measure extremely high frequencies; the base frequency is around 35 hz but outliers can be anything above that; up to 8000 hz.

#### MrChips

Joined Oct 2, 2009
30,802
Ok, we have to make sure we apply the same meaning when we use technical terms, even when it appears to be jargon.

I would have guessed that an outlier is a single data point that does not fit the current trend. I would not use a median filter to reject or suppress such point.

"Jitter" in signal processing refers to something else than what you describe. Jitter is the variation in the sampling period which produces an uncertainty in the precise time at which the sample is recorded. At low frequencies, jitter has low effect. At high frequencies or signals with large slew rates, jitter results in errors in the digitized amplitude.

What I read is that you are performing zero-crossing analysis to determine your frequency content. You appear to have significant high frequency noise.

As a first step, I would perform an FFT to determine the power spectrum to identify the frequency composition of your data.

#### kokkie_d

Joined Jan 12, 2009
72
FFT transform: 2 major peaks;
1. 15hz - 50 hz
2. around 2700hz

I am measuring the phase of an inverter. The latter is the switching frequency of the inverter which I am not interested in. The former is the frequency of the final phase which is what I am interested in.

#### MrChips

Joined Oct 2, 2009
30,802
You can extract the frequency and phase information directly from the FFT.

What are you trying to achieve?