Author Topic: A peak detector that restarts (multiple peaks)  (Read 1946 times)

0 Members and 1 Guest are viewing this topic.

Offline baksuzTopic starter

  • Newbie
  • Posts: 9
  • Country: at
A peak detector that restarts (multiple peaks)
« on: February 08, 2019, 09:43:53 am »
Hiiiiii I new here be gentle  ;D

First to explain I have a sensor that emits output, wave with different amplitude, that is AC 5V 10kHz.
My question is: Is it possible to make a peak detector that resets it peak value every time when V = 0, for collecting peaks I am going to use Arduino UNO.


I would like to thank you for you time.
   
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 15151
  • Country: de
Re: A peak detector that restarts (multiple peaks)
« Reply #1 on: February 08, 2019, 09:59:30 am »
One could use a normal peak detector circuit and use the zero crossing as a trigger for the reset and maybe Arduino to start the ADC  conversion first.  The peak detector could be the normal way and the Arduino would trigger the reset.

With just 10 kHz a fast Arduino (ARM based) may be fast enough to use direct digital sampling and peak detection in software.
 

Offline baksuzTopic starter

  • Newbie
  • Posts: 9
  • Country: at
Re: A peak detector that restarts (multiple peaks)
« Reply #2 on: February 08, 2019, 10:36:06 am »
If was planning to use Arduino, but I have a STM32 that I believe that well be enough for ADC.
Regarding that trigger for zero crossing, which component would I use, I apologize if that is a dum question.
And during conversion I would just convert a peaks as they are coming if I am correct.
 

Online Kleinstein

  • Super Contributor
  • ***
  • Posts: 15151
  • Country: de
Re: A peak detector that restarts (multiple peaks)
« Reply #3 on: February 08, 2019, 01:44:38 pm »
With a fast (e.g. ARM based) µC the HW would be mainly scaling the signal to the ADC range and everything else would be in software.

With the relatively slow (especially the ADC) AVR based Arduino one would likely need an analog peak detector (maybe 2) and zero detection with a comparator. The µC internal comparator would need some extra level adjustment / limiting to stay inside the operating range. It slightly depends on how the signal is relative to the µC's supply. It likely is something like some diodes for clamping the signal and a shift to bring zero signal somewhere to the center of the range.

After trigger the first thing would be reading the peak value with the ADC and only than the actual reset of the peak detector. Sampling of the ADC takes some 20 µs - so the actual reset maybe 20 µs after zero crossing. With a true AC this would be in the opposite polarity phase and thus likely enough time before the next peak. If both polarities are needed this might need 2 separate peak detectors.
 
The following users thanked this post: baksuz

Offline baksuzTopic starter

  • Newbie
  • Posts: 9
  • Country: at
Re: A peak detector that restarts (multiple peaks)
« Reply #4 on: February 08, 2019, 02:18:48 pm »
Thank you very much for your time and your explanation, it is really helpful to me.
 

Offline rhb

  • Super Contributor
  • ***
  • Posts: 3516
  • Country: us
Re: A peak detector that restarts (multiple peaks)
« Reply #5 on: February 08, 2019, 03:24:39 pm »
Do you want the time of the peak, the amplitude or both?

An analog differentiator and a comparator will give you the instant of the peak, so one option would be to use that to trigger the ADC.  The differentiator output  goes through zero at the peak. The STM32F4 has three 2.4 MSa/S 12 bit ADCs, so you should be able to separately resolve 3 closely spaced peaks by using all three ADCs.  Timing might get tricky.  It's been a while since I read the STM32F4 documentation and don't recall the rules for reading a single sample.

The interrupt service routine would need to be very short and just read an ADC into one of 3 registers.  The main routine could then sit in a loop polling the registers and storing the data.  That should let you catch peaks a few MCU clock periods apart which is much better time resolution than sampling a 7.2 MSa/S using all 3 ADCs.

The LPC4370 runs at 204 MHz and has an 80 MSa/S 12 bit ADC. You can use an LPC-Link2 (OM13054) to program a 2nd one.  Digikey had them from Embedded Artists for $20 and from NXP for $24, but I don't see the embedded Artists' board now.
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9963
  • Country: us
Re: A peak detector that restarts (multiple peaks)
« Reply #6 on: February 08, 2019, 04:34:02 pm »
It is sometimes helpful to frame the question at the next layer up.  What you are trying to accomplish rather than how you intend to accomplish it.

There are analog solutions using comparators and peak detector circuits.  The easiest, and most flexible solution might involve a high sampling rate with a uC.  But it need not be all that high, 2 times the highest input frequency will probably do it and it should be easy to sample at 10 times the input - even higher.  But once you move to the digital domain, you are dealing with discrete time.  Usually, a block of data is read into memory and then some calculation is performed to find the peak.  This is altogether different than how it works in the analog domain where the peak is captured in real time on a capacitor.   No calculation required.  And the result of the analog solution is a voltage, not a number.

Does it matter?
« Last Edit: February 08, 2019, 08:03:30 pm by rstofer »
 

Offline baksuzTopic starter

  • Newbie
  • Posts: 9
  • Country: at
Re: A peak detector that restarts (multiple peaks)
« Reply #7 on: March 04, 2019, 06:19:29 pm »
First I would like to thank you for you time,
As I said I have 5V AC 10kHz, I forget to mention that is modulated signal, It will look like this

[5][5]

I need to detect all peaks to, and in the end I need to connect all that peaks to get a new signal, that will in the end be the envelope of this signal that I mentioned before. My plan is to build a Non-Inverting Op-Amp Level Shifter(change of plans) to get voltage to 0-3,3 V and connect it to stm32 , and do all programming where my output will be as mentioned the envelope. I am a bit skeptic about all of that, cause I already have bought all material.
 

Offline rhb

  • Super Contributor
  • ***
  • Posts: 3516
  • Country: us
Re: A peak detector that restarts (multiple peaks)
« Reply #8 on: March 04, 2019, 07:13:22 pm »
What you want to do is take the magnitude of the analytic signal.   The analytic signal is a complex function whose real part is f(t) and whose imaginary part is -i*Hilbert(f(t)).

This is treated in any good book on the Fourier transform.  My standard reference is the 2nd ed of "The Fourier Transform and its Applications" by Ronald Bracewell.  As that is 39 years old, very likely older than you are, but there is a more recent edition that is in print in India.  It's a very good investment.

The Hilbert transform is a 90 degree phase shift operator.  So you can do this by generating an analog I/Q pair or you can do it digitally.  Never having implemented the analog version, I am a bit unsure how one would produce the envelope via an analog circuit,  But as you are using an STM32, I suggest that you   generate an I/Q stream and then feed those to a pair of the STM32 ADCs.  However, you could also just sample the in-phase signal and generate the quadrature part in software.

Reg

I should add that the envelope function is commonly referred to as the "instantaneous amplitude".  The phase is called the "instantaneous frequency".
« Last Edit: March 04, 2019, 08:14:32 pm by rhb »
 

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9963
  • Country: us
Re: A peak detector that restarts (multiple peaks)
« Reply #9 on: March 04, 2019, 10:05:50 pm »
If its the envelope you want to explore, you need only use a simple analog circuit to integrate the modulated signal onto a capacitor.  If the absolute value matters, you will need to account for the diode drop.

https://wiki.analog.com/university/courses/electronics/electronics-lab-envelope-detector

So, you have two signals:  The carrier frequency and the modulating frequency.  Which one is 10 kHz?  If you need to sample the modulated carrier because you don't have the envelope then you will have to sample at 2+ times the carrier frequency.  If you demodulate first, you only need to sample at 2+ times the modulating frequency.  Hence the envelope detector.  From Nyquist/Shannon sampling theory, we know that we can reconstruct the signal by sampling at 2x but most scope manufacturers go for about 2.5x.  But it's important to remember, it's 2.5x times the highest frequency in the signal.

There's a lot to sampling and perhaps Chapter 4 of the Rigol DS1000Z manual will give you some ideas:

http://int.rigol.com/File/TechDoc/20160830/MSO1000Z&DS1000Z_UserGuide_EN.pdf

« Last Edit: March 04, 2019, 10:48:43 pm by rstofer »
 

Offline unitedatoms

  • Frequent Contributor
  • **
  • !
  • Posts: 324
  • Country: us
Re: A peak detector that restarts (multiple peaks)
« Reply #10 on: March 06, 2019, 04:22:34 am »
First I would like to thank you for you time,
As I said I have 5V AC 10kHz, I forget to mention that is modulated signal, It will look like this

[5][5]

I need to detect all peaks to, and in the end I need to connect all that peaks to get a new signal, that will in the end be the envelope of this signal that I mentioned before. My plan is to build a Non-Inverting Op-Amp Level Shifter(change of plans) to get voltage to 0-3,3 V and connect it to stm32 , and do all programming where my output will be as mentioned the envelope. I am a bit skeptic about all of that, cause I already have bought all material.

Your asking, what analog circuit can form single ended (positive quadrant) signal representing envelope of AM modulated signal with carrier of 10kHz ?

This is AM detector.
https://www.st-andrews.ac.uk/~www_pa/Scots_Guide/RadCom/part9/page2.html
Interested in all design related projects no matter how simple, or complicated, slow going or fast, failures or successes
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf