What is the “dt” in the complementary filter equation and how do i find out the “dt”?

Thread Starter

ckkkk

Joined Apr 17, 2019
15
I am going to implement the Complementary filter into my system but i do not quite understand what is the "dt" means and how should i find out the "dt" in the Complementary filter equation. This is where I found out the complementary filter equation https://www.pieter-jan.com/node/11 and this is the equation angle = 0.98 * (agnle + gyrData * dt) + 0.02 * (accData).

Code:
while n!= 10:

data = bus.read_i2c_block_data(0x68, 0x3B, 6)

xAccl = data[0] * 256 + data[1]
if xAccl > 32767 :
        xAccl -= 65536

yAccl = data[2] * 256 + data[3]
if yAccl > 32767 :
        yAccl -= 65536

zAccl = data[4] * 256 + data[5]
if zAccl > 32767 :
        zAccl -= 65536

data = bus.read_i2c_block_data(0x68, 0x43, 6)

xGyro = data[0] * 256 + data[1]
if xGyro > 32767 :
        xGyro -= 65536

yGyro = data[2] * 256 + data[3]
if yGyro > 32767 :
        yGyro -= 65536

zGyro = data[4] * 256 + data[5]
if zGyro > 32767 :
        zGyro -= 65536

totZdata += zAccl
totXdata += xAccl
totYdata += yAccl
totGyroXdata += xGyro
totGyroYdata += yGyro
totGyroZdata += zGyro
zAcclG = (zAccl - AcclzOff) / Accl_scale
xAcclG = (xAccl - AcclxOff) / Accl_scale
yAcclG = (yAccl - AcclyOff) / Accl_scale
xGyroDPS = (xGyro - GyroxOff) / Gyro_scale
yGyroDPS = (yGyro - GyroyOff) / Gyro_scale
zGyroDPS = (zGyro - GyrozOff) / Gyro_scale   


print ("Acceleration in X-Axis : %.2f G" %xAcclG)
print ("Acceleration in Y-Axis : %.2f G" %yAcclG)
print ("Acceleration in Z-Axis : %.2f G" %zAcclG)
print (" X rotation : %f" % (get_x_rotation(xAcclG, yAcclG, zAcclG)))
print (" Y rotation : %f" % (get_y_rotation(xAcclG, yAcclG, zAcclG)))
print ("X-Axis of Rotation : %.2f" %xGyroDPS)
print ("Y-Axis of Rotation : %.2f" %yGyroDPS)
print ("Z-Axis of Rotation : %.2f" %zGyroDPS)
n += 1
These are the code i am using now and how can i determined the "dt" from the Complementary filter equation?
 

wayneh

Joined Sep 9, 2010
16,399
Did you read the part about integrating the equation? I don’t know the details of what you’re doing but it looks like you evaluate that equation over as many small intervals as is practical and this accomplishes the integration numerically.
 

Papabravo

Joined Feb 24, 2006
14,460
Have you studied the differential calculus?
Δt is a finite incrementof time. As we let Δt get smaller and smaller it approaches, in the limit, an infinitesimally small value dt. In programming a relationship it is possible to carelessly assign a finite value to dt. I think that might be what is going on here since the greek "Δ" is not an available character in the LATIN alphabet.
 

MrAl

Joined Jun 17, 2014
7,815
I am going to implement the Complementary filter into my system but i do not quite understand what is the "dt" means and how should i find out the "dt" in the Complementary filter equation. This is where I found out the complementary filter equation https://www.pieter-jan.com/node/11 and this is the equation angle = 0.98 * (agnle + gyrData * dt) + 0.02 * (accData).

Code:
while n!= 10:

data = bus.read_i2c_block_data(0x68, 0x3B, 6)

xAccl = data[0] * 256 + data[1]
if xAccl > 32767 :
        xAccl -= 65536

yAccl = data[2] * 256 + data[3]
if yAccl > 32767 :
        yAccl -= 65536

zAccl = data[4] * 256 + data[5]
if zAccl > 32767 :
        zAccl -= 65536

data = bus.read_i2c_block_data(0x68, 0x43, 6)

xGyro = data[0] * 256 + data[1]
if xGyro > 32767 :
        xGyro -= 65536

yGyro = data[2] * 256 + data[3]
if yGyro > 32767 :
        yGyro -= 65536

zGyro = data[4] * 256 + data[5]
if zGyro > 32767 :
        zGyro -= 65536

totZdata += zAccl
totXdata += xAccl
totYdata += yAccl
totGyroXdata += xGyro
totGyroYdata += yGyro
totGyroZdata += zGyro
zAcclG = (zAccl - AcclzOff) / Accl_scale
xAcclG = (xAccl - AcclxOff) / Accl_scale
yAcclG = (yAccl - AcclyOff) / Accl_scale
xGyroDPS = (xGyro - GyroxOff) / Gyro_scale
yGyroDPS = (yGyro - GyroyOff) / Gyro_scale
zGyroDPS = (zGyro - GyrozOff) / Gyro_scale 


print ("Acceleration in X-Axis : %.2f G" %xAcclG)
print ("Acceleration in Y-Axis : %.2f G" %yAcclG)
print ("Acceleration in Z-Axis : %.2f G" %zAcclG)
print (" X rotation : %f" % (get_x_rotation(xAcclG, yAcclG, zAcclG)))
print (" Y rotation : %f" % (get_y_rotation(xAcclG, yAcclG, zAcclG)))
print ("X-Axis of Rotation : %.2f" %xGyroDPS)
print ("Y-Axis of Rotation : %.2f" %yGyroDPS)
print ("Z-Axis of Rotation : %.2f" %zGyroDPS)
n += 1
These are the code i am using now and how can i determined the "dt" from the Complementary filter equation?
Hello there,

'dt' is different in different contexts.
For the operation of approximate integration by summation, dt is considered to be a small unit of time. For the operation of actual integration dt is considered to be that small unit of time used in the summation but theoretically allowed to go to an infinitesimally small time and in that limit the most accurate value of the integration is found.
So we have two cases:
1. Integration by summation where dt might be some small value like 0.001 or alternately the smallest step of time in the system.
2. Integration by a true integration, which is the same as above except in theory the dt time value goes to an infinitesimally small time length and so the result is the accurate integration.

Since we deal with digital systems a lot these days, we often see the first one above being used. In that case the time interval dt is usually the smallest time step used in the system. This is determined by the clock speed or some multiple of the clock speed.
For example, say we take several readings each spaced 1 second apart. We can then integrate that numerically and here dt would be 1 second. If we take faster readings, like once every 1/10 second, then dt becomes 0.1 second.
The smaller we make dt the better the approximation of the integration comes out, but we dont always have total control over that because the system can only take so many readings per second and that interval determines dt.
In your equation, part of it gets integrated and part of it is just linear. You would apply these ideas to the part you integrate (the part with dt in it) and then add the rest.

An example of an exact integration would look like this:
integrate(x^2,x,0,2)
which means integrate the function x^2 for x from x=0 to x=2..
Written out in math it would look like:
Integrate x^2 dt
only the word "integrate" would be replaced by the symbol for integration and the limits would be 0 on the bottom and 2 on the top.
 

Thread Starter

ckkkk

Joined Apr 17, 2019
15
Okay i think i know what dt means now, but i am not entirely sure how can i set the dt. I know that the sensor have a 100Hz output data rate which means it can output 100 data per second am i right?
 
Top