### Author Topic: Measuring time (or phase) between sync pulse and maximum of sine-like signal  (Read 2322 times)

0 Members and 1 Guest are viewing this topic.

#### simplynaoh

• Newbie
• Posts: 4
• Country:
##### Measuring time (or phase) between sync pulse and maximum of sine-like signal
« on: July 01, 2017, 09:22:27 pm »
Hi there! First time posting in the forums, hope I don't break any rules. I need help with an analog problem, I only know fairly basic electronics, and mostly having to do with microcontrollers. For this project I would like to do everything without a microcontroller.

I've been thinking about building a DIY polarimeter after the one we had at my college broke. Without going into much detail, the problem at hand is the following: There is a linear polarizer mounted on a rotating platform. Polarized light goes through it and into a phototransistor. The intensity of the light that reaches the detector, and therefore the current/voltage drop on a resistor, is related to the angle of the platform through Malus's law. The purpose of the setup is to measure the angle that makes the signal either a maximum or a minimum. In our particular use-case, this value will change over time. A manual polarimeter is operated by a person who rotates the polarizer (which has a goniometer attached) until he/she sees a maximum or minimum light intensity. The same could be done replacing the direct observation with the phototransistor, and manually rotating the polarizer until the voltage reaches a maximum.

However, I had this idea: what if the polarizer is continuously rotated at a known frequency and we include a sync signal each time a revolution starts. Given the Malu's law, the intensity of light reaching the phototransistor will change periodically (cos^2(t)). The angle at which the intensity of light reaches a maximum is related to the phase between the sync signal and the photodetector signal. Therefore, with this setup, we could continuously measure the polarization angle, which would be helpful to study systems with variation in time.

In this scenario, the measurement of the angle is reduced to the measurement of the phase between the signals, or the time between the sync pulse and the maximum of the photocurrent. This involves a series of problems, as a quick research into peak detectors and phase detectors made me realize. Using a simple phase detector (such as a XOR-gate) is a good start: it generates a signal whose duty cycle is proportional to the phase of two signals. The catch is, it requires two square-wave signals as inputs. In our case, the sync pulse is OK, but the phototransistor current is a sine-like signal. Adding a comparator/schmitt trigger would allow to convert the photocurrent into a square wave, which turns high only when the maximum of the signal is reached... if only we knew what voltage the maximum is at! (this could vary with time/between experiments, as it has to do with optical alignment, and the nature of the substance being put in the light path). So, here is where a peak detector comes into play. A peak detector can detect and hold a maximum voltage of a signal, thus, one could first sample the maximum voltage, and then feed that as the threshold for the comparator, which in turns feeds the phase detector which measures the time passed between the sync pulse and when the maximum signal is reached.

In conclusion, my question is, does any of that make any sense? And if it does, how would one go about to putting the pieces of the puzzle together? For instance, the peak detector used to detect the maximum voltage should reset every so often in case the maximum voltage got lower (maybe allowing the capacitor to discharge slowly? the signal is periodic anyway, so when a new maximum is reached, the cap would be charged again). However, the threshold for the schmitt trigger should be a little bit lower than the peak detected, I think, so that we are sure that the maximum will trigger the output of the comparator, and then be fed into the phase comparator. And finally, the phase comparator outputs a PWM-like signal, maybe a low-pass filter could be used to transform that into a voltage that then can be measured? Once we know the timing information, using the frequency (or angular velocity), one can transform that into an angle, which is what we are after. Could this operation be also made in an analog fashion? And if so, what would be a good way of measuring the angular velocity? (essentially the frequency of the sync pulse).

Sorry for the wall of text! And thanks for your time!
« Last Edit: July 02, 2017, 12:14:05 am by simplynaoh »

• Super Contributor
• Posts: 11519
• Country:
##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal
« Reply #1 on: July 01, 2017, 09:33:04 pm »
What is the frequency of rotation, or time intervals we are talking about here? Won't $1 MCU with ACD solve all your problems? Alex #### simplynaoh • Newbie • Posts: 4 • Country: ##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal « Reply #2 on: July 01, 2017, 09:38:57 pm » What is the frequency of rotation, or time intervals we are talking about here? Won't$1 MCU with ACD solve all your problems?

To be honest, there is no minimum frequency required, the only hard-limit is the response time of the phototransistor, and the physical/mechanical constraints of actually having the thing rotate. So you are right that one could choose a low RPM value, and use an MCU to measure the time between the start of a revolution and the maximum photo-current. However, I want to take the opportunity to experiment with analog design.

• Super Contributor
• Posts: 11519
• Country:
##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal
« Reply #3 on: July 01, 2017, 09:42:13 pm »
So you are right that one could choose a low RPM value, and use an MCU to measure the time between the start of a revolution and the maximum photo-current.
Even the cheapest MCUs will have at least 200-300 ksps ADC. This should be enough to sample a photo-resistor.

However, I want to take the opportunity to experiment with analog design.
Then I'm of no help here. I've given up messing with analog stuff and discreet logic in cases where MCU will do the trick.
Alex

#### simplynaoh

• Newbie
• Posts: 4
• Country:
##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal
« Reply #4 on: July 02, 2017, 12:12:04 am »
For reference, here is my idea of what could work after some testing in the Simulator:
Edit: The square signal on the bottom labelled "trigger" should read "sync", and the XOR on the right is the XOR phase comparator mentioned in the first post (outputs a square wave whose duty cycle is proportional to the phase between the inputs).

Things to note:
• The peak detector let's the capacitor discharge through the 100k resistor so that if Vmax drifts in time, the peak detector can lower the output to the new Vmax;
• The output of the peak detector is halved with a voltage divider, so that the output of the schmitt trigger is ~50% duty;

The reason I abandoned the idea of actually triggering on maximum signal (which in principle would work by removing the voltage divider from the input to the schmitt trigger, or using a higher resistor to ground in it) is to get a 50% duty square wave so that the XOR phase comparator works. Correct me if I'm wrong, but I think it wouldn't work otherwise. The downside of this, is that we rely on the signal actually following Malus's law, and therefore being sine-like.

Once again, is any of this sensible? What should I look into when choosing the op-amps for the peak detector and the schmitt trigger? Or are already packaged peak detectors/schmitt triggers?

Thanks again to anyone that takes the time to read these posts!
« Last Edit: July 02, 2017, 12:26:40 am by simplynaoh »

#### Circlotron

• Super Contributor
• Posts: 3251
• Country:
##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal
« Reply #5 on: July 02, 2017, 08:12:58 am »
Depending on how noisy your signal is, you may be able to feed it into an opamp differentiator circuit. It's output sinewave will cross zero whenever its input sinewave goes through maximum or minimum.

#### Kleinstein

• Super Contributor
• Posts: 14540
• Country:
##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal
« Reply #6 on: July 02, 2017, 08:48:50 am »
With a sine wave the best point to fix the phase is not at the peak, but at the zero transitions. It is not only more accurate, but also easier to implement than peak detection. Adjusting the DC offset could be used to make the signal an exact 50% ratio.
Depending on the light sources one might need to adjust the amplification of the detector. Usually a phototransistor is simple, but a photo-diode with suitable TIA is more linear and has better SNR.

I personally would prefer a digital implementation with a small µC. It is easier to build and more accurate. It could also give additional information, like the ratio of min and max intensity.

One point to watch for is 50/100 Hz interference. There are quite a few light source that have there light modulated at the mains frequency or twice the frequency. So even if the circuit is perfectly shielded chances are that there will be 100 Hz present.

With the polarizers there is not much to go wrong an produce a different waveform. Even then looking for the maximum is not better than any other point in the curve. The more natural point is looking at the minimum intensity points - usually sensitivity is better here.

#### Rerouter

• Super Contributor
• Posts: 4695
• Country:
• Question Everything... Except This Statement
##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal
« Reply #7 on: July 02, 2017, 09:03:53 am »
If you want as simple as possible, get an encoder disk, attach it to your motorised platform and have a binary counter chip count those pulses, the index resets the counter, and the peak detect latches the reading.

This is assuming you filter your encoder input to the frequency of interest, to prevent glitching, likely running a schmitt trigger on all encoder signals,
The peak detect would actually be used backwards to how you would think, you would have a comparitor with some tiny hysteresis so when the signal falls below the peak it triggers.

#### simplynaoh

• Newbie
• Posts: 4
• Country:
##### Re: Measuring time (or phase) between sync pulse and maximum of sine-like signal
« Reply #8 on: July 02, 2017, 02:36:03 pm »
Thanks for all the replies!

Depending on how noisy your signal is, you may be able to feed it into an opamp differentiator circuit. It's output sinewave will cross zero whenever its input sinewave goes through maximum or minimum.
That's a great idea! (assuming I can filter out the noise) The differentiated signal can then be fed into a zero-cross detector (comparator with 0V reference voltage) to get a square wave with 50% duty cycle which can be measured against the sync pulse (phase detector).

With a sine wave the best point to fix the phase is not at the peak, but at the zero transitions. It is not only more accurate, but also easier to implement than peak detection. Adjusting the DC offset could be used to make the signal an exact 50% ratio.
You are right, going back to my experimental circuit, I ended up detecting the "zero" transition (as half the peak voltage), and as per the previous reply, a differentiator could provide a signal with an actual zero transition. Adjusting a DC offset however could be tricky, as once again, the peak voltage is not known beforehand. That's why I liked the differentiator idea: it doesn't depend on the amplitude.
As per your other comments, yes, I know a µC would be way easier, but I wanted to play around with processing the signals in an analog fashion.

If you want as simple as possible, get an encoder disk, attach it to your motorised platform and have a binary counter chip count those pulses, the index resets the counter, and the peak detect latches the reading.
I like this idea, it really is simple. Though, I wonder what the angular resolution on cheap encoders is... Also, this method wouldn't allow to smooth or average several measurements in an easy way (without going the µC way), while the output of the phase detector can be fed into a filter and therefore "average" several measurements.

Thanks to all of you! I think so far I have enough ideas to try out. Any recommendations on a general purpose op-amp?

Smf