Existem duas maneiras de implementar isso que eu uso normalmente. Estou sempre trabalhando com dados em tempo real, portanto, isso pressupõe entrada contínua. Aqui estão alguns pseudo-códigos:
Usando um minmax treinável:
define function peak:
// keeps the highest value it has received
define function trough:
// keeps the lowest value it has received
define function calibrate:
// toggles whether peak() and trough() are receiving values or not
define function scale:
// maps input range [trough.value() to peak.value()] to [0.0 to 1.0]
Esta função requer que você execute uma fase inicial de treinamento (usando calibrate()) ou que treine novamente em determinados intervalos ou de acordo com determinadas condições. Por exemplo, imagine uma função como esta:
define function outBounds (val, thresh):
if val > (thresh*peak.value()) || val < (trough.value() / thresh):
calibrate()
O pico e a calha normalmente não estão recebendo valores, mas se outBounds()recebe um valor superior a 1,5 vezes o pico atual ou menor que a calha atual dividido por 1,5, calibrate()é chamado o que permite que a função seja recalibrada automaticamente.
Usando um minmax histórico:
var arrayLength = 1000
var histArray[arrayLength]
define historyArray(f):
histArray.pushFront(f) //adds f to the beginning of the array
define max(array):
// finds maximum element in histArray[]
return max
define min(array):
// finds minimum element in histArray[]
return min
define function scale:
// maps input range [min(histArray) to max(histArray)] to [0.0 to 1.0]
main()
historyArray(histArray)
scale(min(histArray), max(histArray), histArray[0])
// histArray[0] is the current element