Sample Rate- and Frequency Offset Detector

 - still under construction -

Chapter overview

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 .


Introduction

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


One-time calibration of the sampling rate

With the following steps, you can calibrate the sampling rate once. This is enough for most applications.

  1. 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
  2. Use a relatively high FFT resolution, for example 32768 points.
  3. Make sure the spectrum/waterfall cursor readout operates in peak detecting mode.
  4. 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 !)
  5. 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.
  6. 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:


Principle for continuous calibration of the sample rate

The sample rate detector is a sofware implementation of...

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


Settings for the sample rate calibrator in Spectrum Lab

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


Continuous detection (+"calibration?") of a frequency offset

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...

(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


Frequency Reference Sources

Some frequency reference sources to calibrate the ADC's sample rate:

chapter overview


Interpreter commands for the frequency calibrators

fo_cal.xxxx = commands and functions for the frequency offset calibrator:

sr_cal.xxxx = commands and functions for the sampling rate calibrator:

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)

  1. 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 !)
  2. 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)
  3. 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 !)
  4. 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