Peak detector

Thread Starter

victoriomariani

Joined Nov 8, 2023
7
How I can measure this peaks with 1kHz. I am projecting a superdiode peak detector, but I don’t know with for diferent amplitude peak I am Measure the peak.
1713925492210.png

I would like to using an Esp32 to calculate the median of 100 peaks and identify a standard desvian
 
Last edited by a moderator:

crutschow

Joined Mar 14, 2008
34,671
Assuming the Esp32 A/D conversion rate is at least 100k samples/sec. you can just rapidly sample the 1kHz signal and look for the peak signal in each of the samples over the 1kHz period.
 
You need to create a signal when the peak occurs so ESP knows exact time when to trig an ADC.
This signal can be made from precisely calculated RC differentiator. The edge before peak seems to be very sharp so you can use just RC with very short time constant.
There is also possible to use a comparator like LM393 with reference set to about 1/2 of smallest peak. After comparator signal rise delay the ADC start so you sample in the middle of peak.

Btw, there is no need a rectifier. Just use a small RC low pass so peaks become flat a little to measure. If you need to measure positive and negative peaks also shift the Gnd to Adc/2.

If the negative is no needed clamp it with diode.
 
Last edited:

Thread Starter

victoriomariani

Joined Nov 8, 2023
7
You need to create a signal when the peak occurs so ESP knows exact time when to trig an ADC.
This signal can be made from precisely calculated RC differentiator. The edge before peak seems to be very sharp so you can use just RC with very short time constant.
There is also possible to use a comparator like LM393 with reference set to about 1/2 of smallest peak. After comparator signal rise delay the ADC start so you sample in the middle of peak.

Btw, there is no need a rectifier. Just use a small RC low pass so peaks become flat a little to measure. If you need to measure positive and negative peaks also shift the Gnd to Adc/2.

If the negative is no needed clamp it with diode.
Eu preciso usar o amostrador e criar este sinal ou apenas um dos dois?

Moderator edit: This is an English language website. Please use English only.

Do I need to use the sampler and create this signal or just one of the two?
 

Thread Starter

victoriomariani

Joined Nov 8, 2023
7
I am using a superdiode and this circuit. The transistor is active by esp32.

1714152937531.png

but I think my code is not ideal, if you have a suggestion, please write me.
Code:
//Função para pulsar os LEDs
void gera_onda_quadrada(int pin_LED, int pin_fotodiodo, int pin_transistor) {
  float tensao;
  unsigned long inicio_loop;
  const unsigned long periodo = 500;
  float soma_tensao = 0.0;
  pinMode(pin_LED, OUTPUT);
  pinMode(pin_transistor, OUTPUT);
  pinMode(pin_fotodiodo, INPUT);
 
  for (int i = 0; i < 128; i++) {
    inicio_loop = micros();
    digitalWrite(pin_LED, HIGH);
    
    // Aguarda até que o período definido se passe
    while(micros() - inicio_loop < periodo){
    }
    // Desliga o LED após o período definido
    digitalWrite(pin_LED, LOW);
    delayMicroseconds(10);
    valor_adc = analogRead(pin_fotodiodo);
    digitalWrite(pin_transistor, HIGH);
    soma_tensao += valor_adc;
    
    digitalWrite(pin_transistor, LOW);
    // Aguarda o restante do período
    while(micros() - inicio_loop < 2 * periodo){
    }
  }
 
  tensao = (soma_tensao * 3.3) / 4095; // Converte o valor ADC em tensão
  float media_tensoes = tensao / 128;
  Serial.print("Tensão medida: ");
  Serial.println(media_tensoes);
}

void setup() {
  Serial.begin(9600); //Para comunicação USB
  //lerArquivo(); //Quando for descarregar os dados é necessário habilitar esta linha
}

void loop() {
  // Gera 128 pulsos de 1 kHz no pino 19 que alimenta o circuito NIR, lê a tensão medida pelo fotodiodo e descarrega o capacitor
  gera_onda_quadrada(19, 34, 22);
  // Gera 128 pulsos de 1 kHz no pino 23 que alimenta o circuito RED, lê a tensão medida pelo fotodiodo e descarrega o capacitor
  gera_onda_quadrada(23, 34, 22);
  delay(2000);
}
 
Top