# window size of a median filter

Discussion in 'Math' started by kokkie_d, Jan 10, 2012.

1. ### kokkie_d Thread Starter Active Member

Jan 12, 2009
72
0
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,

2. ### MrChips Moderator

Oct 2, 2009
12,625
3,451
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).

3. ### kokkie_d Thread Starter Active Member

Jan 12, 2009
72
0
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?

4. ### MrChips Moderator

Oct 2, 2009
12,625
3,451
What is an outlier?

5. ### kokkie_d Thread Starter Active Member

Jan 12, 2009
72
0
(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.

6. ### MrChips Moderator

Oct 2, 2009
12,625
3,451
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.

7. ### kokkie_d Thread Starter Active Member

Jan 12, 2009
72
0
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.

8. ### MrChips Moderator

Oct 2, 2009
12,625
3,451
You can extract the frequency and phase information directly from the FFT.

What are you trying to achieve?

9. ### kokkie_d Thread Starter Active Member

Jan 12, 2009
72
0
I have an electric motor setup connected to a dynamometer to which I apply change in speed (say from from 0 to 10mph in equivalent rpm). The controller varies the phase frequency to match the speed requested. Using this data I want to have a look at the slip during the change process and compared it in time to the current drawn from the battery.