Author Topic: How can I count the number of middle pulses from the given signal  (Read 1754 times)

0 Members and 1 Guest are viewing this topic.

Offline tranvannhancuTopic starter

  • Newbie
  • Posts: 3
  • Country: hk
Hi all,

I have the following signal where I need to design a circuit to count the number of pulses.

The pulse is at the middle. There are valleys before and after each pulse.
The amplitude of pulses are also different.

Could anyone guide me on what kind of circuit I can use to do this?
Thanks!
 

Online moffy

  • Super Contributor
  • ***
  • Posts: 1966
  • Country: au
Re: How can I count the number of middle pulses from the given signal
« Reply #1 on: July 05, 2024, 10:51:11 am »
Use a small micro for logic and say a comparator with a threshold of 300mv and some hysteresis or just feed the signal into the ADC of a small micro and do all the filtering, detection and counting in code.
 

Online 2N3055

  • Super Contributor
  • ***
  • Posts: 7026
  • Country: hr
Re: How can I count the number of middle pulses from the given signal
« Reply #2 on: July 05, 2024, 10:52:39 am »
Hi all,

I have the following signal where I need to design a circuit to count the number of pulses.

The pulse is at the middle. There are valleys before and after each pulse.
The amplitude of pulses are also different.

Could anyone guide me on what kind of circuit I can use to do this?
Thanks!

On that image, number of positive pulses in the middle of that negative pulse is same as all those groups...
That whole valley before, pulse in the middle and valley behind repeats as a group.

I would detect first negative going edge, ignore everything for a time length of a group, and then be ready to detect another one..
Either AC couple the signal and use negative going zero pass detector, or if DC levels are stable a comparator (with some hysteresis) to detect edge. And then you can use microcontroler to read state, ignore changes for the short period, and count the groups..
 
The following users thanked this post: tranvannhancu

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: au
Re: How can I count the number of middle pulses from the given signal
« Reply #3 on: July 06, 2024, 12:17:29 am »
The pulse is at the middle. There are valleys before and after each pulse.
The amplitude of pulses are also different.
You have not said how that varies (aside from the middle peak) and if you need to reject any pulses.

A simple scheme would be a comparator that slices on ~50% of the negative swings, feeding a counter, and you divide by 2 / shift right 1 bit, as you increment by 2 every pulse.

Modern Rail-Rail comparators with push pull outputs, often have inbuilt hysteresis.
Your signal looks quite slow, so you could add more noise filtering by adding a RC filter between the Comp output and a counter with a schmitt trigger clock.
« Last Edit: July 06, 2024, 02:30:08 am by PCB.Wiz »
 
The following users thanked this post: tranvannhancu

Offline CaptDon

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: is
Re: How can I count the number of middle pulses from the given signal
« Reply #4 on: July 06, 2024, 02:01:15 pm »
Trigger a one shot from the negative going leading edge (probably through a comparator) and set the one shot so it can't retrigger until after the duration of your total pulse width plus about 10%. The negative side of your pulses look uniform and of the same width within a few percent. What will be your time base? You say you want to count the number of pulses?? Total number? How many occur in a second, a minute, a year? You could build a reliable circuit with a comparator with adjustable threshold and a one shot 74LS121 with variable 'non-retrigger' timeout. 74LS123 won't be suitable because it is retriggerable during the current pulse. A 555 may work as I think they have to time out before being retriggerable. In any event I could do it with two very simple readily available I.C.'s and just a very few resistors and a couple of capacitors.
Collector and repairer of vintage and not so vintage electronic gadgets and test equipment. What's the difference between a pizza and a musician? A pizza can feed a family of four!! Classically trained guitarist. Sound engineer.
 
The following users thanked this post: tranvannhancu

Offline tranvannhancuTopic starter

  • Newbie
  • Posts: 3
  • Country: hk
Re: How can I count the number of middle pulses from the given signal
« Reply #5 on: July 08, 2024, 02:50:14 am »
Thanks a lot to everyone who contributed to my question. I appreciate all your suggestions!
I'm by no mean a professional EE engineer so please bear with me if I ask a dumb question  :(.

I should provide more scope to my original question.
The signal you're seeing is from an IR receiver.
The transmitter and receiver pair are approximately 3cm apart.
They are used to detect a small and fast-moving subject.
My goal is to generate an interrupt signal to the MCU (which is sleeping to save battery) every time the subject moves across the transmitter-receiver pair.

I tried using an inverting comparator with hysteresis where I set my reference voltage to be slightly larger than the input voltage when there are no pulses.
The input signal is subject to ambient light, i.e. signal amplitude will vary within around 200mV. That's why I can't use a fixed reference voltage.

Do you know how I can make the reference voltage adapted to the ambient light?
Thanks again.
« Last Edit: July 08, 2024, 04:29:35 am by tranvannhancu »
 

Offline PCB.Wiz

  • Super Contributor
  • ***
  • Posts: 1722
  • Country: au
Re: How can I count the number of middle pulses from the given signal
« Reply #6 on: July 08, 2024, 03:57:25 am »
...The signal you're seeing is from an IR receiver.
...
Do you know how I can make the reference voltage adapted to the ambient light?
IR receivers usually have some inbuilt means for handling ambient light. What is the part number ?
Usually that is a low frequency current feedback, that tracks slow light changes, but it needs care if you have fluorescent or LED lighting, or sunlight through tree leaves.

Take some scope captures at varying light levels.
 
The following users thanked this post: tranvannhancu

Offline jbb

  • Super Contributor
  • ***
  • Posts: 1193
  • Country: nz
Re: How can I count the number of middle pulses from the given signal
« Reply #7 on: July 08, 2024, 08:49:04 am »
How about an analog band pass filter followed by a comparator?
 
The following users thanked this post: tranvannhancu

Offline CaptDon

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: is
Re: How can I count the number of middle pulses from the given signal
« Reply #8 on: July 08, 2024, 01:21:44 pm »
Can you show more revealing scope shots that show 'no subject in beam' and 'subject in beam'?? You want to count "The middle pulses". Every one of the negative pulses shown on your scope shot has a 'middle pulse'. Are you saying the only valid middle pulses to be counted are the ones above the reference line as you are showing one of the pulses is way more positive than the rest? If you want to detect a fast moving object you don't do it with a pulsed beam!!!! What if the object goes through the beam when the pulsing beam is off?? I think you need a total re-think of this detector scheme and we need more scope shots if we are to provide any sort of valuable insight to your project. 'Counting' the pulses? What will the count reveal since it is a pulsed beam? Why not use the normal LED with photodiode in the standard fashion like they do to count parts or pieces on a conveyor line. Putting a short piece of tubing in front of the LED and the photodiode can make the device less effected by ambient light.
Collector and repairer of vintage and not so vintage electronic gadgets and test equipment. What's the difference between a pizza and a musician? A pizza can feed a family of four!! Classically trained guitarist. Sound engineer.
 
The following users thanked this post: tranvannhancu

Online selcuk

  • Regular Contributor
  • *
  • Posts: 205
  • Country: tr
Re: How can I count the number of middle pulses from the given signal
« Reply #9 on: July 08, 2024, 01:55:14 pm »
If you cannot detect from amplitude difference, you can try frequency domain as suggested above. If it is possible to keep CPU running, you may use sliding window fast FFT algorithms.
 
The following users thanked this post: tranvannhancu

Offline nfmax

  • Super Contributor
  • ***
  • Posts: 1580
  • Country: gb
Re: How can I count the number of middle pulses from the given signal
« Reply #10 on: July 08, 2024, 02:00:21 pm »
It looks like you are trying to detect mostly opaque objects, but which have a hole in the middle that contains something that reflects or refracts the light passing through it. Are you trying to count the number of objects, or the number of holes? Do they all travel at the same speed? All in the same direction? At different angles?
 
The following users thanked this post: tranvannhancu

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3155
  • Country: us
Re: How can I count the number of middle pulses from the given signal
« Reply #11 on: July 09, 2024, 12:58:08 am »
Here is a piecewise linear representation of the signal presented in the first post -- can be used for testing algorithms and/or circuit simulation.

The "x" and "y" columns are pixel positions within the screenshot PNG - the "t" and "mv" columns are time in ms and signal voltage in mV.

« Last Edit: July 09, 2024, 01:59:44 am by ledtester »
 
The following users thanked this post: tranvannhancu

Offline CaptDon

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: is
Re: How can I count the number of middle pulses from the given signal
« Reply #12 on: July 09, 2024, 10:00:49 pm »
O.P. still hasn't given enough information about his signal to be of any use to us. Detect 'which' middle pulses???? Every pulse shown has a middle pulse, some bigger than others. What is the 'go / no go' criteria? I'm not convinced the O.P. even knows and who detects 'fast moving objects' with a pulsed beam?
Collector and repairer of vintage and not so vintage electronic gadgets and test equipment. What's the difference between a pizza and a musician? A pizza can feed a family of four!! Classically trained guitarist. Sound engineer.
 
The following users thanked this post: tranvannhancu

Offline CaptDon

  • Super Contributor
  • ***
  • Posts: 1905
  • Country: is
Re: How can I count the number of middle pulses from the given signal
« Reply #13 on: July 10, 2024, 01:00:44 am »
I guess I misunderstand. The beam itself isn't pulsed, the pulses shown are the actual objects passing through the beam. Please O.P., tell us more about the objects and which of the middle pulses you consider to be valid. Your original scope shot shows various heights of middle pulses.
Collector and repairer of vintage and not so vintage electronic gadgets and test equipment. What's the difference between a pizza and a musician? A pizza can feed a family of four!! Classically trained guitarist. Sound engineer.
 
The following users thanked this post: tranvannhancu

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 3678
  • Country: us
Re: How can I count the number of middle pulses from the given signal
« Reply #14 on: July 10, 2024, 09:29:17 am »
I've been following this thread and waiting for the OP to refine the question. 

@CaptDon (#5)
I was tempted to add a concurring comment.  It seems the items give a complex signal, but all you need to do for an accurate count is detect the signal start and then use something to effectively inhibit response until the next item.  A one-shot is one approach.

Then I saw that the user wants to use simple on/off IR in what seems like an open area.  That will be the problem, and I don't see an easy solution or why one would want to do that.  Modulated IR modules are plentiful and cheap.  They do not require an MCU to operate. 
 
The following users thanked this post: tranvannhancu

Offline mino-fm

  • Regular Contributor
  • *
  • Posts: 147
  • Country: de
Re: How can I count the number of middle pulses from the given signal
« Reply #15 on: July 10, 2024, 10:40:32 am »
Simply count all rising (or falling) edges and divide by 2.
:-)
 
The following users thanked this post: tranvannhancu

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 3678
  • Country: us
Re: How can I count the number of middle pulses from the given signal
« Reply #16 on: July 10, 2024, 11:09:12 am »
Look at peaks #1 and #7 (as examples).  The center peak is not a single peak sometimes -- probably due in part to using straight IR rather than modulated IR.
 
The following users thanked this post: tranvannhancu

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2271
  • Country: br
    • CADT Homepage
Re: How can I count the number of middle pulses from the given signal
« Reply #17 on: July 10, 2024, 01:31:51 pm »
The posted csv file contains a reduction to piecewise linear data. I think that is the algorithm the OP is asking for. Probably a test question.

Regards, Dieter
« Last Edit: July 10, 2024, 02:01:49 pm by dietert1 »
 
The following users thanked this post: tranvannhancu

Offline johnk0gcj@gmail.com

  • Contributor
  • Posts: 12
  • Country: us
Re: How can I count the number of middle pulses from the given signal
« Reply #18 on: July 10, 2024, 07:12:31 pm »

How about a delayed sweep scope?
 
 
The following users thanked this post: tranvannhancu

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3155
  • Country: us
Re: How can I count the number of middle pulses from the given signal
« Reply #19 on: July 10, 2024, 10:10:13 pm »
Here's an attempt using a data slicer circuit.

It uses the digitized signal from my earlier post but in this case formatted to work as a PWL file.

The Vdelta source is just an time-dependent offset to test how sensitive the detector is to slow changes in the DC offset.
 
The following users thanked this post: tranvannhancu

Offline tranvannhancuTopic starter

  • Newbie
  • Posts: 3
  • Country: hk
Re: How can I count the number of middle pulses from the given signal
« Reply #20 on: July 12, 2024, 04:45:29 am »
Thanks for all your comments.

I attached more photos to explain my setup.

1st photo:
The small object that I want to count is water droplets. It is transparent as one of you mentioned.

2nd photo:
Here the IR LED is not modulated. It is turned on all the time.
Highlighted is what I meant by "middle pulse".
The signal pattern is the same for every water droplet, only the amplitude is inconsistent.
A few mentioned that I can detect the first falling edge and wait a bit until detecting the next fall egde.
This is actually what I'm doing on the MCU.
The disadvantage of this is that its average current is much higher than what I can allow, due to the fact that IR LED is not modulated.

3rd photo:
I've recently tried to modulate the IR LED.
Here I'm doing 1kHz at 20% duty.
Highlighted is the signal pattern on there is a water droplet passing by.
In this case the average current is within my power budget.
However, I'm not really sure if I can count the drops using this approach.

I also attached the raw signal that I captured using modulated approach.
Please let me know what what think how I should go from here.
Thanks all!
 

Offline nfmax

  • Super Contributor
  • ***
  • Posts: 1580
  • Country: gb
Re: How can I count the number of middle pulses from the given signal
« Reply #21 on: July 12, 2024, 06:08:37 am »
If you stick with the 1kHz pulsing of the LED to reduce power consumption, then the task is to detect a missing pulse in the output. Since you know when the LED is turned on, you can use an analogue peak detector, reset to 0V before the LED is turned on, and sample its output just before the next pulse. Then compare the sampled level with the average over the last few pulses. If it is less than ~50% you have found a droplet. Count it, and wait the ‘dead time’ for the droplet to pass before renabling sampling. You need to remember the average level, and only start updating it after the dead time, when the droplet has passed. To save a bit more power, you could stop pulsing the LED during the dead time.

This could be done with a mixture of simple analogue circuits and microcontroller code.
 

Offline KerimF

  • Regular Contributor
  • *
  • Posts: 176
  • Country: sy
Re: How can I count the number of middle pulses from the given signal
« Reply #22 on: July 12, 2024, 07:34:26 am »
I guess it is known that a conventional IR receiver expects an IR 38 KHz signal. It has an internal BPF and a digital detector to output low (on) and high (off) levels only. (Such IR receivers are used in TVs and satellite receivers, controlled by IR remote control units).
This reduces (almost eliminates) the side-effect of the ambient light.
And the digital output will likely be cleaner.

Also, as it was mentioned by others, driving the IR LED (38 KHz) doesn’t need to be continuous (to save power). And the driving current could be made relatively small in this application (because distance between TX and RX is rather short). Obviously, its optimum value could be found experimentally.

Kerim
A philosopher: A living thing has no choice but to execute its pre-programmed instructions embedded in it (known as instincts).
Therefore, the only freedom, a human may have, is his ability to oppose or not his natural robotic nature.
But, by opposing it, such a human becomes no more of this world.
 

Online jpanhalt

  • Super Contributor
  • ***
  • Posts: 3678
  • Country: us
Re: How can I count the number of middle pulses from the given signal
« Reply #23 on: July 12, 2024, 09:30:58 am »
Re: 1kHz modulated scan

That makes it relatively simple.  Set up a a gated counter (missing pulse detector, as suggested by others earlier), count every time the pulse disappears, and then blank counting for whatever time it takes.  From the scan, it looks like that blank needs to be at least 10 ms.  About 20 ms might work well without missing a subsequent count.

As your are not using a filter in the receiver yet, that approach will still be subject to ambient light.
« Last Edit: July 12, 2024, 09:32:40 am by jpanhalt »
 

Offline ledtester

  • Super Contributor
  • ***
  • Posts: 3155
  • Country: us
Re: How can I count the number of middle pulses from the given signal
« Reply #24 on: July 12, 2024, 01:14:42 pm »
From:

https://forum.arduino.cc/t/counting-water-drops-dripping-from-iv-bottle/581542/12

Quote
Back in August 94 I published a circuit to count and time drips in order to show the emergence of chaotic behavior as the drip rate increased. I made this circuit.

The diagram also showed why you got a double pulse from transparent drops.
You don't need the 74LS74 when using an Arduino.


 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf