0
\$\begingroup\$

How is hysteresis used for DSP?

\$\endgroup\$

closed as too broad by The Photon, PeterJ, uint128_t, Andy aka, Asmyldof Apr 6 '16 at 8:43

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

1
\$\begingroup\$

To keep the heater example of Ecnerwal, the code below turns on and off a heater. It keeps room temperature at 25ºC, with a hysteresis of 2 degrees. The objective of such a code is to reduce the number of calls to startupHeater() and shutdownHeater(), which would harm the heater if executed too often:

#define TEMPERATURE_LIMIT 25
#define TEMPERATURE_HYSTERESIS 2

void turnHeaterOnIfNeeded(int temperature) {
    static boolean currentlyOn = false;

    if (currentlyOn) {
        if (temperature > TEMPERATURE_LIMIT + TEMPERATURE_HYSTERESIS) {
            shutdownHeater();
            currentlyOn = false;
        }
    } else {
        if (temperature < TEMPERATURE_LIMIT - TEMPERATURE_HYSTERESIS) {
            startupHeater();
            currentlyOn = true;
        }
    }
}

void main() {
    int temperature;
    // ... 
    // ...

    // Monitors the temperature:
    temperature = measureTemperature();
    turnHeaterOnIfNeeded(temperature);

    // ...
    // ...
}

Hysteresis is useful when you need to control a on/off process with an analog signal, if the turn on and turn off procedures have a cost. In particular if the analog signal has any kind of interference upon it.

Temperature drives on/off

\$\endgroup\$
5
\$\begingroup\$

Let's consider your thermostat in your house.

Lacking hysteresis, it flips the furnace on for a few seconds, flips it off for a few seconds, flips it on for a few seconds, burns out the motor from starting it too frequently, and leaves you freezing in the middle of the night (it's always the middle of the night, or when you are on vacation far away and don't have anyone checking the house and it's cold enough to freeze the plumbing...)

With hysteresis, it turns on the furnace for a while, and then shuts it off after the temperature has risen a little. It waits to turn the furnace back on until the temperature has fallen a little. It will still die at an inconvenient time, but it will do so many years later than in the no-hysteresis scenario, since there are many fewer motor starts in the with-hysteresis scenario.

Code? Not rocket science. A bimetallic strip and a mercury bulb switch handled it for decades, though there is more than meets the "eww, murcury evil, must have wifi thermostat" eye going on in those to make the mechanical hysteresis happen.

If temp lower than setpoint AND furnace off, turn furnace on. If temp higher than setpoint + hysteresis amount AND furnace on, turn furnace off.

(you don't need the case for if temp in between, leave state alone, but you can write it if it makes you happy.)

\$\endgroup\$
  • \$\begingroup\$ Another concern is noise: e.g. an electric motor which reacts to small deviations from a given desired position and changes its direction a few times a second leading to hum (and wasted energy). Code would be something like "if abs(difference)<hysteresis do nothing else act on difference normally". \$\endgroup\$ – 0x6d64 Apr 6 '16 at 10:10

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