From the original SynthMaker forum (2004–2014), with its members’ names and dates.
Leslie147 ·
I've been playing around with the Hilbert transform and quadrature oscillators again and I started wondering if there's an easy way to test the quality of the quadrature of two equal-amplitide sinusoidal signals - to determine what the phase difference is between the two signals. This would have been done using a vector voltmeter in the analogue world in the past.
After trying scope models it dawned on me that an answer is offered by the 'factor formulas' such as:
sinA.sinB = -0.5[cos(A+B) - cos(A-B)]
If A=wt and B=wt+phi, where w is the angular frequency (2.Pi.f) and phi is the phase difference as a fraction of a radian (1 radian = 180/Pi degrees = 57.3 degrees), then:
sin(wt).sin(wt+phi) = -0.5cos(2wt+phi) + 0.5cos(-phi)
So multiplying the two signals together and viewing the result on a scope provides some guidance to the phase difference. If it is a true 90 degrees (Pi/2 radians) then the resulting trace is a double-frequency sine wave with no 'DC' offset. For unit amplitude sine waves, as above, the offset is 0.5cos(-phi) or 0.5cos(phi) because the cos of a negative angle is equal to the cos of the positive angle of the same size.
One degree of phase difference in one direction gives phi = 91 degrees and 0.5cos(phi) = -0.0087 or -0.87%,
or +0.87% for the same phase difference in the other direction (i.e. phi negative).
Ten degrees difference gives an offset of 8.7%.
Twenty degrees gives an offset of 17.1%.
The relationship would be expected to be fairly linear for smallish angular differences because sinA is roughly equal to A expressed in radians.
If a delay is inserted in one of the signal paths to the multiplier then the delay can be varied, either to demonstrate the offset for a given phase difference, or to measure the delay required to cancel out whatever offset exists. For a sampling frequency Fs and a signal frequency f, a delay of N samples introduces a phase shift of 360.N.f/Fs degrees. For example, a 1-sample delay at Fs=44.1 kHz gives a phase shift of 8.16 degrees at f = 1 kHz. Of course, this phase shift is frequency-dependent.
The deluxe version would automatically null-out the double frequency wave, measure the offset and present the result on a 'meter' - et voila: the hard bit of a vector voltmeter! 😉
Chris
lesobrod ·
Very interesting post, thank you! 😀
As I like math too, a couple of questions.
1.
Leslie147 wrote: automatically null-out the double frequency wave
- seems not so simple to do it, hmm?
But in "Zombie pitch detector" I try to find DC offset using some "averaging" algorithm, without any info about frequency,and seems it works..
2. Most of signals are not pure sinusoids, but kinda of Fourie sums. Let we leave behind some weird noises and think
about periodicall ones. Then conception "phase" makes sense too, but could your method help in this way?
I now I start some experiments... 😉
martinvicanek ·
Leslie147 wrote: an easy way to test the quality of the quadrature of two equal-amplitide sinusoidal signals - to determine what the phase difference is between the two signals.
One way to do that is measure the cross correlation coefficient, i.e. take the product, lowpass, and normalize. Some time back I posted an OSM.
If you want to test Hilbert transformers, stack two of them in series and check for 180 degrees phase difference which is easier (just add the two signals and see if they cancel).
Leslie147 ·
measure the cross correlation coefficient, i.e. take the product, lowpass,
sounds like the same process but using a filter to remove the double-frequency wave, and is fine for mid to high audio frequencies. My requirement includes testing the phase difference of oscillators, as I mentioned, and low-frequency ones at that. Trying to remove a 1 Hz wave by low-pass filtering would be very slow, which is why I suggested nulling-out the wave.
to test Hilbert transformers, stack two of them in series and check for 180 degrees phase difference
True, but that doesn't give a simple comparitive figure for one design versus another. To be more specific, I've been playing with FIR Hilbert transformers of different lengths, trying to balance CPU demand with performance. Actually, I've found that a 513 tap FIR, the longest that can be designed at http://www-users.cs.york.ac.uk/~fisher/mkfilter/, provides very accurate quadrature at all frequencies with modest CPU demand. Its limitation is a high-pass frequency response, -3 dB at 260 Hz, that I can overcome using a high-pass filter, but that will introduce some amount of unwanted phase shift - hence the need to instrument the amount of phase error.
I try to find DC offset using some "averaging" algorithm
is low-pass filtering by another name.
Most of signals are not pure sinusoids, but kinda of Fourie sums
Of course, but a simple sinusoid can be used to test the phase response of a Hilbert transformer or any other kind of filter.
Chris
Leslie147 ·
that I can overcome using a high-pass filter
... a low-pass filter of course!
martinvicanek ·
Leslie147 wrote:
measure the cross correlation coefficient, i.e. take the product, lowpass,
sounds like the same process but using a filter to remove the double-frequency wave, and is fine for mid to high audio frequencies. My requirement includes testing the phase difference of oscillators, as I mentioned, and low-frequency ones at that. Trying to remove a 1 Hz wave by low-pass filtering would be very slow, which is why I suggested nulling-out the wave.
You are right, it is the same as you suggested in your first post. I think you'll need to analyze one full cycle or so to know the phase shift, and a carefully designed lowpass will not take much longer to give you the answer. Anyhow, another idea occurred to me: taking the derivative amounts to a 90 deg phase shift (apart from a scale factor), which leaves you with a much easier task of comparing two signals in phase.
to test Hilbert transformers, stack two of them in series and check for 180 degrees phase difference
True, but that doesn't give a simple comparitive figure for one design versus another.
Why not? For instance the Oli Hilbert Transformer gives you cancellation to better than 30 dB over the whole audible range, that is a figure of merit.
To be more specific, I've been playing with FIR Hilbert transformers of different lengths, trying to balance CPU demand with performance. Actually, I've found that a 513 tap FIR, the longest that can be designed at http://www-users.cs.york.ac.uk/~fisher/mkfilter/, provides very accurate quadrature at all frequencies with modest CPU demand.
That's quite interesting, I'd be happy to see an example OSM. 🙂
Leslie147 ·
That's quite interesting, I'd be happy to see an example OSM
... perhaps you mean 'interested' to see an example?
One is attached, making use of a convolver provided by Tzarls (Just a test (Realtime Convolution)) but with the internal attenuator removed and replaced by an external one before the convolver. The .wav file is just a re-formatted list of coefficients.
Oddly, although the centre sample in the .wav file is sample 256 (can be seen using Wavelab), this convolver places it at sample 265 so the compensating delay has to have this number of samples.
Another oddity is that the high-pass magnitude frequency response is missing although the web site with the coefficient calculator, to which I've referred before, shows the expected LF loss.
Anyway, when varying the oscillator frequency in the attached .osm, the scope trace has a constant 'DC pedestal' indicating quadrature, but if the compensating delay is changed the pedestal fluctuates with changing frequency indicating departure from quadrature ... unless I'm mistaken!
Chris
Leslie147 ·
Well I am mistaken about the frequency response. I've just realised the 264 Hz breakpoint is for a 129-tap FIR. For the 513-tap one, for which I've posted the .wav, the low-frequency breakpoint is at 64 Hz which makes it almost good enough for general audio use - certainly good enough for frequency translation effects, which was my original objective.
Of course, before anyone picks me up on this, there's no need to use such a lengthy, complicated convolver for only 513 taps - I used that general one for the sake of this demonstration because it's readily available. Indeed, every other coefficient is zero and those for samples 257 to 513 have the same magnitudes as those for samples 255 to 1 but with opposite sign, so only 128 unique non-zero numbers are involved and they could be hard-coded into the convolver.
I've also just realised that by reversing the .wav using Wavelab the phase shift of the transformer is reversed (e.g. from +90 to -90 degrees) but its magnitude response stays the same. So there may be scope for producing +45 and -45 degree components with identical magnitudes, and the difference between them would give quadrature with a flat magnitude response. I'll try that out over the next couple of days.
Chris
martinvicanek ·
Thanks for the example, Leslie. I don't have access to SM here but will take a closer look when home next week. Thanks also for the link to the convolution thread, I didn't know that stream FFT in SM had actually gotten that far.
martinvicanek ·
The OSM below provides a test of three Hibert transformers: one by Olli Niemitalo (http://yehar.com/blog/?p=368), Leslie's, and one that I designed in an attempt to improve Olli's. As suggested above, I cascaded each of the transformers to produce a 180 degrees phase shift and then check how well the two signals cancel. Olli's design has a nice frequency response with a cancellation better than 30 dB over the entire audible range. Leslie's device performs well (40 dB) down to about 150 Hz. My own creation seems to achieve close to 50 dB 🙂 , although the response is not as uniform as Olli's.
It is interesting to note that Leslie's design has FIR characteristics, whereas the other two are IIR based. That is probably the reason for the different low frequency behavior.
Leslie147 ·
Try changing one of the attenuators to 0.633 in the FIR version - then it achieves >50 dB over most of the audio band.
The FIR convolver I used in the example I gave doesn't appear to hold a copy of the .wav for the coefficients, even though it does remember the number of taps, so I have needed to re-load the .wav (which I posted here before) in order to make this version operate. Has anyone else found the same?
Also, I suspect there may be one or more errors in that convolver (viz. the requirement for a compensating delay of 265 samples when the .wav file is centred on 256) and it may be possible to achieve better cancellation with a different convolver. I will investigate this.
However, whilst I acknowledge that this cancellation method is fine as to check the ultimate performance of a design, and in a relative 'shoot out' as here, it would be of less use when trying to improve the performance of one particular design, for example by adding an all-pass network to the FIR, because it cannot be calibrated in degrees at a given frequency, whereas the method I proposed for this purpose can.
Chris
Wrote something here? To have a post removed or your name hidden, write to [email protected].