Operate a switch with hysteresis (python)



Python
library
pip

MeCab

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding


Release date:2024/12/9         

In Japanese


■Description
Operates a switch with hysteresis.



■Example
Below is the hysteresis switch.

flag = 0

if    a > 0.5                     : flag = 1
elif flag==1 and a > -0.5 : flag = 1
else                                : flag = 0


I added a program section to check the operation.

import numpy as np
import matplotlib.pyplot as plt
import math

flag = 0
sin_value = []
flag_value = []

for n in np.arange(0,7,0.01):
    a = math.sin(n)

    if    a > 0.5                     : flag = 1
    elif flag==1 and a > -0.5 : flag = 1
    else                                : flag = 0

    sin_value.append(a) #Graph drawing data storage
    flag_value.append(flag) #Graph drawing data storage

#Graph drawing
fig = plt.figure()

plt.subplot(2,1,1)
plt.plot(np.arange(0,7,0.01) , sin_value)

plt.subplot(2,1,2)
plt.plot(np.arange(0,7,0.01) , flag_value)

plt.show()


The results are as follows.









List of related articles



Python
library
pip

MeCab

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding