> For the complete documentation index, see [llms.txt](https://yams.yassrobotics.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yams.yassrobotics.com/api-reference/c++-reference/math/derivative-time-filter.md).

# DerivativeTimeFilter

**Namespace:** `yams::math`\
**Header:** `#include <yams/math/DerivativeTimeFilter.hpp>`\
**Java equivalent:** [Java DerivativeTimeFilter](https://yams.yassrobotics.com/api-reference/java-reference/math/derivative-time-filter.md)\
**Doxygen:** [`DerivativeTimeFilter`](https://doxygen.yassrobotics.com/yams/classyams_1_1math_1_1DerivativeTimeFilter.html)

`DerivativeTimeFilter` computes a numerical derivative of a signal and applies a debounce filter to suppress transient spikes.

***

## Constructors

```cpp
DerivativeTimeFilter(double initial, wpi::units::second_t debouncerPeriod)
explicit DerivativeTimeFilter(wpi::units::second_t debouncerPeriod)  // initial = 0.0
```

| Parameter         | Description                                                           |
| ----------------- | --------------------------------------------------------------------- |
| `initial`         | Initial value of the signal. Defaults to `0.0` if omitted.            |
| `debouncerPeriod` | Duration the debounce filter holds a spike before passing it through. |

***

## Methods

```cpp
double Derivative(double current, wpi::units::second_t dt)
double Derivative(double current)
```

| Overload                  | Description                                                                                                                                                                                                        |
| ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `Derivative(current, dt)` | Computes derivative using an explicit time step `dt`.                                                                                                                                                              |
| `Derivative(current)`     | Computes derivative using the robot timestamp (`wpi::RobotController::GetTime()`); `dt` is measured since the last update. Only recomputes once the debounce period has elapsed, otherwise returns the last value. |

Returns the filtered derivative value.

***

## Example

```cpp
yams::math::DerivativeTimeFilter filter{20_ms};

// In periodic (called every 20 ms):
double velocity = filter.Derivative(encoder.GetPosition());
```

{% hint style="info" %}
Use the explicit `dt` overload in simulation or when calling at non-uniform intervals. Use the single-argument overload in robot periodic methods where the robot timestamp is authoritative.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://yams.yassrobotics.com/api-reference/c++-reference/math/derivative-time-filter.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
