1
$\begingroup$

I have position of objects from recording sampled at 30 fps. I wish to remove high frequencies from position with the help of low-pass filter.

I am confused as to how to choose the filter parameters in this respect->

[b,a] = butter(n,Wn) 

that is , n and Wn in this case.

Data:

K>> [xcor_i,ycor_i ]

ans =

 -101.7000  -77.4040
 -102.4200  -77.4040
 -103.6600  -77.4040
 -103.9300  -76.6720
 -103.9900  -76.5130
 -104.0000  -76.4780
 -105.0800  -76.4710
 -106.0400  -77.5660
 -106.2500  -77.8050
 -106.2900  -77.8570
 -106.3000  -77.8680
 -106.3000  -77.8710
 -107.7500  -78.9680
 -108.0600  -79.2070
 -108.1200  -79.2590
 -109.9500  -80.3680
 -111.4200  -80.6090
 -112.8200  -81.7590
 -113.8500  -82.3750
 -115.1500  -83.2410
 -116.1500  -83.4290
 -116.3700  -83.8360
 -117.5000  -84.2910
 -117.7400  -84.3890
 -118.8800  -84.7770
 -119.8400  -85.2270
 -121.1400  -85.3250
 -123.2200  -84.9800
 -125.4700  -85.2710
 -127.0400  -85.7000
 -128.8200  -85.7930
 -130.6500  -85.8130
 -132.4900  -85.8180
 -134.3300  -86.5500
 -136.1700  -87.0760
 -137.6500  -86.0920
 -138.6900  -86.9760
 -140.3600  -87.9000
 -142.1600  -88.4660
 -144.7200  -89.3210

Code:

[b,a] = butter(6,0.6,'low');
dataOut_x = filter(b,a,xcor_i);
dataOut_y = filter(b,a,ycor_i);

K>> plot(xcor_i,ycor_i,'Linewidth',2 );
K>> hold on
K>> plot(dataOut_x,dataOut_y,'Linewidth',2)

enter image description here

Clearly, my parameters aren't correct.

Moe info: I have tried a simple moving average, doesn't work that well. I am recording people from an overheard camera. I have tracks of each's head using some software. I want to periodicity from tracks due to head wobbling.

Link to same question on stackoverflow: https://stackoverflow.com/questions/34616131/choosing-low-pass-filter-parameters?noredirect=1#comment56979276_34616131

$\endgroup$

1 Answer 1

2
$\begingroup$

The main issue is that the filters start with an initial position of (0,0). Then when you filter your actual data, the filter output has to ramp up to the actual position. In doing so, you can also observe some overshoot since your filter has a very short time response.

It would help if you were to start with a better estimate of the initial position by using for example the first position with:

dataOut_x = xcor_i(1)+filter(b,a,xcor_i-xcor_i(1));
dataOut_y = ycor_i(1)+filter(b,a,ycor_i-ycor_i(1));

The resulting plot would then look like:

enter image description here

$\endgroup$
8
  • $\begingroup$ Thanks for the answer! What parameters a and b did you choose? I am confused over parameters -I have sampling rate of 30fps and human can change direction every 0.5 secs. What could be the cut-off frequency and order. $\endgroup$ Jan 5, 2016 at 18:32
  • $\begingroup$ I used the same parameter for a & b as you used for this plot. For smoother results you could go down to a cutoff of about 2Hz (related to your 0.5 secs update), which would mean Wn = 2/(0.5*30fps) ~ 0.13. $\endgroup$
    – SleuthEye
    Jan 5, 2016 at 18:36
  • $\begingroup$ Thanks again! Can you provide more details as how you calculated that cut-off frequency and also how I could decide a good estimate for the order parameter. $\endgroup$ Jan 5, 2016 at 18:43
  • $\begingroup$ The parameter Wn is a normalized frequency in terms of the Nyquist frequency, which is half of your 30fps sampling rate (ie. 15fps). So if you want to keep 2 updates per second content, a good starting starting value of Wn is 2/15. As for the order parameter, it should generally be the smallest order which satisfies your requirements (which you haven't specified). $\endgroup$
    – SleuthEye
    Jan 5, 2016 at 18:53
  • $\begingroup$ By requirements you mean. Can you provide an example please if possible. $\endgroup$ Jan 5, 2016 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.