Sample Rate- and Frequency Offset
Detector
- still under construction
-
Introduction
One-time calibration of the sampling rate
Continuous calibration of the sampling rate
Continuous detection (and -possibly-
calibration) of a frequency offset / "drift"
Frequency Calibration Sources
Interpreter Commands to control and monitor
the frequency calibrators
See also: Spectrum Lab's main index ,
circuit window ,
phase meter .
This chapter is only important for phase- and precise frequency measurements.
You don't the functions explained in this chapter for most 'normal' applications
like audio frequency analysis.
To improve the accuracy of frequency- and phase readings, it is possible
to reduce the influence of "drifting" soundcard sample rates by
permanently monitoring the frequency and phase of an external
reference signal.
( This is different from the 'normal' sample rate calibration table on the
audio settings screen, where the
sample rate is only calibrated once but not
permanently)
With the permanent frequency calibration, you can (almost) eliminate
the effect of a drifting VFO in an external receiver.
Some frequency reference sources are listed
in one of the following paragraphs.
back to top
With the following steps, you can calibrate the sampling rate once. This
is enough for most applications.
-
Select a nominal sample rate which is high enough to detect the
"reference signal" of your choice.
For example, chose 44100 samples / second under "audio settings" to observe
a 15625 Hz TV line sync signal
-
Use a relatively high FFT resolution, for example 32768 points.
-
Make sure the spectrum/waterfall cursor readout operates in
peak detecting mode.
-
With the peak-detecting cursor in the spectrum graph or the waterfall, measure
the frequency of the reference signal.
Move the mouse close to the peak frequency. The "peak indicator" circle in
the spectrum plot should jump to the peak.
For example, the 'cursor' function will show a value of 15623.2345 Hz (this
is an interpolated value, the resolution is much higher than the FFT bin
width ! The interpolation algorithm was suggested by DF6NM, thanks Markus
... it really does an amazing job !)
-
Enter the "correct" and the "measured" frequency in the calibrator fields
of the audio settings dialog. Then
click "Calibrate". The program calculates the new sampling rate and shows
it in the calibration table. If you think it's reasonale, click "Apply" to
make the new value effective.
-
Move the mouse to the peak of the reference signal again and check the displayed
frequency (again, in 'peak'-mode). It should be very close to the true frequency
of the reference signal, like 15625.0001 Hz for the "TV-sync" example.
Notes:
-
The mentioned accuracy in the sub-milliHertz-region is realistic, if the
soundcard in your PC has a crystal oscillator, and has been running for a
few hours. If the frequency of the soundcard's oscillator drifts too fast,
try the continuous calibration routine which is explained in the next chapter.
Don't calibrate immediately after powering on the system.
-
The calibration table is saved in the machine-depending configuration file
MCONFIG.INI in the installation directory. It is not part of a user configuration
file (SETTINGS.INI etc). So, if someone sends you a test setup file via e-mail,
your calibration does not get lost.
-
There are different entries in the calibration table for some 'nomimal' sampling
rates (like 11025, 22050, 44100 Hz). Because it is very likely that all rates
are derived from the same clock oscillator, it's ok to do the calibration
procedure for the highest sampling rate only, divide the calibrated result
by two or four, and enter the result manually in the table. This way you
can calibrate 11025 samples/second with the 15625 Hz TV sync.
The sample rate detector is a sofware implementation of...
-
a numerical controlled oscillator (NCO) with two outputs, 90° phase
difference ("I/Q output")
-
a complex multiplier ("I/Q" mixer), the reference signal is multiplied with
the NCO's outputs like in an "image cancelling zero-IF receiver"
-
a chain of low-pass filters and decimators, with adjustable bandwidths
-
a phase meter for the decimated I/Q-samples
The phase meter produces a new reading every second (or so, depending on
the bandwidth). From the difference of phase values, the new deviation of
the sampling rate is calculated, and the 'calibrated' sampling rate (which
is an input parameter for some other function blocks) will be is slowly adjusted.
In fact, the phase meter used in the frequency calibrator routine is almost
the same as used in Spectrum Lab's time
domain scope. Other function blocks in SpecLab like the phase meter in
the time domain scope benefit from the "calibrated" (or better: "measured")
sampling rate. Of course it is impossible to pull the soundcard's oscillator
to the nominal frequency. If you need even better stability, use an
external A/D converter clocked
with an oven-controlled or GPS-disciplined 10 MHz oscillator !
There are some additional function blocks in the frequency calibrator which
detect the presence and the quality of the reference signal. This prevents
the 'calibrated' sample rate from running away if the reference signal is
bad or even missing. The 'pulling range' for the calibrated sampling rate
can be adjusted by the user.
Some parts of the calibration algorithm
are explained in the appendix.
chapter overview
There is a special control window for the sample rate calibrator in Spectrum
Lab. To get there, select "View/Windows".."Sample Rate Calibrator"
from Spectrum Lab's main menu, or click on the "SR calib" function block
in the circuit diagram.
Controls for the 'Sample Rate Calibrator'
-
Enabled
-
Must be checked to activate the sample rate calibrator
-
Measure Only
-
Used during development or for "testing purposes". If this checkbox is marked,
the phase meter is active but the sample rate for all other components of
Spectrum Lab is not affected.
-
Source Channel
-
Defines where the reference signal is taken from. Choices are 'LEFT input'
or 'RIGHT input' if the program runs in stereo mode.
-
Precise Reference Frequency
-
Enter the well-known reference frequency here. A few examples can be found
in the chapter "Frequency Reference Sources" in this manual.
-
Min. Reference Amplitude
-
If the strength of the reference signal is less than this value, the sample
rate calibration will be temporarily disabled (important if you use 15625
Hz as reference and someone turns the TV off !). A typical value is -80 dB,
wich means "80 dB below the maximum level which can be handled by the ADC).
Keep the amplitude of the reference signal as low as possible (typically
about -60 dB) to leave enough headroom for other signals you want to
measure.
The current (measured) signal strength is displayed in the lower part of
the control window.
-
Phase Meter Bandwidth
-
Defines the width of the frequency window for the sample rate. The program
derives the decimation ratio from this parameter and the "nominal" value.
A typical value is 0.5 Hz (for a 15625 Hz reference). If the bandwidth is
too low, the phase meter may not "see" the reference signal if the sample
rate is too far off. If the bandwidth is set too high, the phase meter gets
less immune to noise.
-
Max. deviation from calibrated Sample Rate value
-
The initial value for the ADC's sample rate is taken from a table in SpecLab's
'audio settings'. The deviation
between the sample rate in the table and the result of the calibration procedure
must not exceed a certain value, like this:
Sample Rate from calibration table in the 'audio settings': 44103 Hz
Max Deviation: 1 Hz -> true calibrated sample rate = 44103 Hz +/-
1 Hz = 44102...44104 Hz.
(Note: this has nothing to do with the 'nominal sample rate' 44100 Hz, so
you should do a first 'coarse' calibration for your soundcard before using
this calibrator. The reason why only a small 'deviation' range should be
used is to have a good starting value for the narrow-band phase meter. See
notes below)
-
Current sample rate
-
Displays the currently calculated sample rate. You cannot edit this field,
but copy its contents into the clipboard. Mark the text with the mouse and
press CTRL-C to copy into the windows clipboard. You can then insert the
copied value as a "very good starting point" into the calibration table in
SpecLab's audio settings screen.
Displayed values on 'Sample Rate Calibrator' control panel
These values are displayed on the control panel:
-
Decimation:
-
Shows the scheme how the high audio sample rate and ADC bandwidth (like 44100
samples/second and 22050 Hz bandwidth) is reduced in chain of decimator stages
down to the phase meter's sample rate and bandwidth (like 1 sample/second
and 0.5 Hz bandwidth). Every decimator stage can reduce sample rate and bandwidth
either by 2 or by 3, the total decimation ratio is also shown here. With
a large decimation ratio, you can use signals buried in the noise as reference
!
-
Signal strength and quality:
-
Shows the signal strength after narrow-band filtering and the signal to
signal-plus-noise ratio ( "S/(S+N)" ). The S/(S+N) value compares the amplitude
of the narrow-band filtered value against a medium-bandwidth value, usually
ten times the narrow-band value.
-
Phase angle:
-
Shows the actual value of the phase meter (reference
signal - oscillator). The displayed value should be constant, only
a small phase jitter is unavoidable (usually below 0.5 °).
-
Status:
-
If this panel is green, everything is ok; otherwise the text shows what may
be wrong, for example:
"SR range exceeded"
"S/(S+N) ratio too bad"
"Reference signal too weak", etc.
chapter overview
The frequency offset detector works similar like the sample rate detector
(see previous chapter). The result from the frequency measurement is not
used to determine the (corrected) sample rate. Instead, the frequency difference
(deviation) between a reference frequency and the measured
frequency is calculated. This can be used to...
-
compensate a slowly drifting oscillator in an external receiver
-
measure small changes in the frequency between a well-known
"reference" signal and an unknown "received" signal
-
correct the frequency error for the display by subtracting it from the
frequency shift for the complex
FFT.
-
steer the VFO (in SpecLab's test circuit)
to compensate the offset in the time domain
(Note: The detection of the soundcard's sampling rate AND the frequency offset
detector can run simultaneously, but you need two different reference
signals then. For example: one reference signal at 15.625 kHz to "calibrate"
the sampling rate, and another like 1000 Hz to detect the frequency drift
in your shortwave receiver. To calibrate your receiver, the 2nd reference
signal must be produced in your receiver, of course. Details below).
To activate the frequency offset detector from SpecLab's main menu, select
"View/Windows" ... "Frequency Offset Detector".
A small control window opens, where the following parameters can be set:
-
Enabled:
-
Must be checked to start the F.O. calibrator.
-
Source:
-
Select the LEFT or RIGHT input channel of the soundcard (unlike other function
blocks in SpecLab, this one cannot be connected to any signal in the
signal processing chain !).
If the input (into SpecLab) is a complex aka "I/Q"-signal, set the source
to "BOTH inputs (complex)". In that case the frequency offset detector can
process positive as well as negative input frequencies.
-
Reference Audio Frequency (Hz):
-
The known frequency of the reference signal (as it should be).
Please note that the frequency offset detector uses audio, or "baseband"
frequencies but not "radio" frequency. So, in this field, enter the AUDIO
(or "downconverted") frequency.
-
Min Reference Amplitude (dB):
-
The detector will be passive if the amplitude of the reference signal is
below this value. This prevents "running away" if the reference fails.
-
Max Offset (Hz):
-
This is the maximum "pulling range" for the detector. In most cases, this
field will be set to the same value as the "PM bandwidth" below.
-
PM bandwidth (Hz):
-
This is the bandwidth of phase meter (which is used internally used to measure
the frequency offset). If your receiver may be "off" by +/-0.5 Hz, set "PM
bandwidth" to 1.0 (!) Hz. Otherwise the detector may not be able to "see"
the initial frequency of the reference signal and never lock on it.
-
Actual Peak Frequency:
-
Shows the "main peak frequency" within the detector's bandwidth. Can be used
for high-precision frequency measurements, but depends a bit on the signal/noise
ratio (within the phase meter's bandwidth).
-
Averages:
-
Can be used to suppress unstable reference signals, and reduce the effect
of pulse-type noise. "50" means, the "average offset value" is calculated
from the last 50 values from the phase meter. Practical values are 50...200.
If the displayed average frequency offset appears to be "too noisy" (see
below), increase the number of averages. If the detector reacts too slow,
reduce this number.
-
Avrg Offset:
-
Shows the current output of the detector, which can optionally be used to
enhance the accuracy of the main spectrum analyser (when running in "complex
FFT mode with frequency shift"), and in the time domain scope (when used
as a "phase meter"). The frequency error measured with the frequency offset
detector can be "subtracted" by the local oscillator which sets the "center
frequency" of the FFT and the scope's phase meter.
In the lower part of the window, some other values are displayed which were
used during program development. One of them is the "signal / (signal+noise)"
ratio, which is a crude indicator for the reference signal's quality. If
the quality is very poor, the "result" of the frequency offset detector freezes,
and the detector's "status" indicator turns yellow or even red (which can
also be seem on the circuit window).
RED = "Reference signal too weak"
YELLOW = "Signal to noise ratio of reference signal too bad"
To calibrate a drifting receiver, you must find a way to feed a add a weak
but very stable reference signal to the antenna input, which produces a suitable
audio tone in the output. Use your imagination - and an oven controlled crystal
oscillator, and a chain of dividers/multipliers, or a programmable DDS generator.
chapter overview
Some frequency reference sources to calibrate the ADC's sample rate:
-
The line sync signal of some TV broadcasting stations.
In EUROPE (and, most likely, countries with 50 Hz AC mains): Frequency exactly
15625 Hz. While we still had terrestrial "analog" TV transmitters, the german
"ZDF" derived their TV sync signals from a high-precision standard clock.
In the US (and other countries using 60 Hz AC mains), the line sync frequency
is ideally 15734.2657343 Hz (for NTSC, colour, 4.5 MHz sound subcarrier divided
by 286).
Update: It is questionable if the TV sync frequency still has this precision,
now that everything (in Europe, even terrestrial transmissions) are digital.
The sync frequencies *may* be generated by a cheap computer-grade crystal
in the set-top box of your TV, so in case of doubt use one of the other
sources...
-
The 1-pulse-per-second output of a good GPS receiver with little jitter.
Spectrum Lab can lock to a harmonic of this 1-Hz-signal because the phase
comparator can be set to a very narrow bandwidth
-
The divided-down carrier frequency of a longwave time-code transmitter like
MSF (60kHz), DCF77 (77.5kHz), or similar. Use a PLL cuircuit to recover a
'clean' carrier signal, then (for example) divide 77.5kHz by 31 or 60kHz
by 24. The result should be a very stable 2500 Hz signal which can be fed
into the soundcard.
-
Some longwave broadcasters (like the BBC's Droitwich transmitter on 198 kHz)
use Rubidium standards for their carrier signal. In western europe, use a
simple PLL oscillator, and divide the signal down with a cheap CMOS circuit.
-
The stereo pilot tone of a few FM broadcasting stations. Unfortunately, in
nothern DL there was no signal which seemed to be locked to an atomic clock,
maybe the BBC in London has one, or your local radio station (ask the chief
engineer, usually he will shake his head ;-)
-
Any other reference can be used, as long as it can be processed with the
audio card. If the ADC supports a sample rate of 44100 Hz, the reference
signal can be everything between 16 Hz ... 22 kHz.
chapter overview
fo_cal.xxxx = commands and functions for
the frequency offset calibrator:
-
fo_cal.avrg
Average frequency offset (difference between "measured" frequency and "known
reference" frequency ).
A positive offset means "the measured frequency is TOO HIGH". So to correct
a "measured" frequency, subtract fo_cal.avrg from the measured value before
you display it (but beware: Do NOT subtract fo_cal.avrg if the FFT frequency
bins have already been corrected as explained
here ).
-
fo_cal.delta_phi
Phase angle difference between to consecutive phase calculations. Should
ideally be zero. Mainly used for program development.
-
sr_cal.fc
Current center frequency which has been measured by the frequency offset
calibrator. Should ideally be the same value as the "known reference frequency".
You may (ab-)use this function for a precise measurement of a single frequency.
Example: To measure the exact mains frequency ("hum"), set the "Reference
audio frequency" to 50.000 Hz, the PM bandwidth to 0.5 Hz (PM=phase meter),
and the max. offset also to 0.5 Hz (all these values on the control panel
of the Frequency Offset Detector).
sr_cal.xxxx = commands and functions for
the sampling rate calibrator:
-
sr_cal.avrg
Average sampling rate measured by the sampling rate calibrator. This value
is also displayed in the calibrator's control window. You may use it for
your own application.
-
sr_cal.delta_phi
Phase angle difference between to consecutive calculations. Should ideally
be zero. Mainly used for program development.
-
sr_cal.fc
Current center frequency calculated by the sampling rate calibrator. Should
ideally be the same value as the "known reference frequency", for example
15625 Hz for European TV line sync.
See also: Interpreter command overview,
circuit window, main index
.
See also: Spectrum Lab's main index .
Appendix
Sample Rate
Calibration Algorithm
(Rev date 2002-04-18)
The example explained here uses a reference frequency f_ref = 15625 Hz (TV
line sync)
-
NCO frequency for the I/Q mixer
theoretically: f_ref = 15625 Hz (this value must be entered by the
user)
practically : f_nco = f_ref * k, where k = true sample
rate / assumed sample rate,
because the program only THINKS it mixes the input signal with f_ref, but
in fact -due to the sample rate error- the true NCO frequency is different
!
Here for example: k = f_sample_assumed / f_sample_true = 44101 Hz / 44100
Hz,
so f_nco = 15625 Hz * 44101/44100 = 15625.35431 Hz. Of course, the NCO is
initially programmed for '15625.0 Hz' because the program does not know the
true sample rate (this is what we're looking for !)
-
Frequency at the output of the I/Q mixer (not decimated)
f_mix = (f_ref - f_nco) = f_ref - f_ref*k = f_ref * (1-k) = 15625 Hz * (1-44101
/ 44100) = -0.3543 Hz
(dont bother about the negative frequency, we are processing I/Q samples)
-
Accumulation of the phase (from f_mix_decimated, observed over the measuring
interval)
Measuring interval: t_meas = decimation_ratio / true sample rate = 16384
/ 44101 Hz
Phase deviation: delta_phi = 360° * t_meas * f_mix =
-47.3866°
(the phase deviation is what the software actually measures. It does
not know the true sample rate !)
-
Calculation of the 'calibrated' sample rate.
known: delta_phi, f_ref, decimation_ratio, f_sample_assumed
wanted: k (correction factor), f_sample_true
delta_phi = 360° * t_meas * f_mix
= 360° *
(decimation_ratio * f_mix) / f_sample_true
= 360° *
decimation_ratio * (f_ref - f_ref * f_sample_true / f_sample_assumed)
/ f_sample_true
-> ... ->
f_sample_true = f_sample_assumed / ( 1 + delta_phi * f_sample_assumed /
(360° * decimation_ratio * f_ref) )
Note that the NCO frequency is not reprogrammed with the "true
value" f_ref. Reason: The lowpass filters in the decimation chain introduce
a significant 'delay' (they are 'very long' FIR filters), and so the decision
was made to keep the 'programmed' NCO frequency constant and only look at
the phase values. This avoids an "oscillating loop" and keeps everything
clean, and the "delta phi" values can be easily interpreted - I tried to
plot them with SpecLab's "Watch List and Plot Window", after adding the function
"sr_cal.delta_phi" (this interpreter function just returns the last "delta_phi"
from the sample rate calibrator).
Plotting the "delta_phi" values over a couple of hours can give you a rough
idea how stable the soundcard's oscillator actually is (assuming you have
a very stable reference signal, don't use the TV sync from a geostationary
sattelite; too much "phase jitter" !). This kind of research was done in
April 2002 for a planned 'propagation experiment' on longwave where the
ionospheric effect of day- and nighttime propagation may introduce a small
phase variation, depending on the path length between transmitter and receiver
(ToDo: move this paragraph into a separate file).
Last modified: 2002-04-18