19c2daa00SOllivier Robert<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 29c2daa00SOllivier Robert<html> 39c2daa00SOllivier Robert<head> 4ea906c41SOllivier Robert<meta http-equiv="content-type" content="text/html;charset=iso-8859-1"> 59c2daa00SOllivier Robert<meta name="generator" content="HTML Tidy, see www.w3.org"> 69c2daa00SOllivier Robert<title>Radio CHU Audio Demodulator/Decoder</title> 7ea906c41SOllivier Robert<link href="scripts/style.css" type="text/css" rel="stylesheet"> 89c2daa00SOllivier Robert</head> 99c2daa00SOllivier Robert<body> 109c2daa00SOllivier Robert<h3>Radio CHU Audio Demodulator/Decoder</h3> 11*2b15cb3dSCy Schubert<p>Author: David L. Mills (mills@udel.edu)<br> 12*2b15cb3dSCy SchubertLast update: 13*2b15cb3dSCy Schubert <!-- #BeginDate format:En2m -->17-Jul-2014 02:17<!-- #EndDate --> 14*2b15cb3dSCy Schubert UTC</p> 159c2daa00SOllivier Robert<hr> 169c2daa00SOllivier Robert<h4>Synopsis</h4> 179c2daa00SOllivier RobertAddress: 127.127.7.<i>u</i><br> 189c2daa00SOllivier RobertReference ID: <tt>CHU</tt><br> 199c2daa00SOllivier RobertDriver ID: <tt>CHU</tt><br> 209c2daa00SOllivier RobertModem Port: <tt>/dev/chu<i>u</i></tt>; 300 baud, 8-bits, no parity<br> 219c2daa00SOllivier RobertAutotune Port: <tt>/dev/icom</tt>; 1200/9600 baud, 8-bits, no parity<br> 22*2b15cb3dSCy SchubertAudio Device: <tt>/dev/audio</tt> and <tt>/dev/audioctl</tt> 239c2daa00SOllivier Robert<h4>Description</h4> 24*2b15cb3dSCy Schubert<p>This driver synchronizes the computer time using shortwave radio transmissions 25*2b15cb3dSCy Schubert from Canadian time/frequency station <a href="http://inms-ienm.nrc-cnrc.gc.ca/time_services/shortwave_broadcasts_e.html">CHU</a> in 26*2b15cb3dSCy Schubert Ottawa, Ontario. CHU transmissions are made continuously on 3.330, 27*2b15cb3dSCy Schubert 7.850 and 14.670 MHz in upper sideband, compatible AM mode. An ordinary 28*2b15cb3dSCy Schubert shortwave receiver can be tuned manually to one of these frequencies or, in 29*2b15cb3dSCy Schubert the case of ICOM receivers, the receiver can be tuned automatically as propagation 30*2b15cb3dSCy Schubert conditions change throughout the day and season.</p> 31*2b15cb3dSCy Schubert<p>The driver can be compiled to use either an audio codec or soundcard, or a Bell 103-compatible, 300-b/s modem or modem chip, as described on the <a href="../pps.html">Pulse-per-second (PPS) Signal Interfacing</a> page. If compiled for a modem, the driver uses it to receive the radio signal and demodulate the data. If compiled for the audio codec, it requires a sampling rate of 8 kHz and μ-law companding to demodulate the data. This is the same standard as used by the telephone industry and is supported by most hardware and operating systems, including Solaris, FreeBSD and Linux, among others. The radio is connected via an optional attenuator and cable to either the microphone or line-in port of a workstation or PC. In this implementation, only one audio driver and codec can be supported on a single machine.</p> 32*2b15cb3dSCy Schubert<p>In general and without calibration, the driver is accurate within 1 ms relative to the broadcast time when tracking a station. However, variations up to 0.3 ms can be expected due to diurnal variations in ionospheric layer height and ray geometry. In Newark DE, 625 km from the transmitter, the predicted one-hop propagation delay varies from 2.8 ms in sunlight to 2.6 ms in moonlight. When not tracking the station the accuracy depends on the computer clock oscillator stability, ordinarily better than 0.5 PPM.</p> 33*2b15cb3dSCy Schubert<p>After calibration relative to the PPS signal from a GPS receiver, the mean offset with a 2.4-GHz P4 running FreeBSD 6.1 is generally within 0.2 ms short-term with 0.4 ms jitter. The long-term mean offset varies up to 0.3 ms due to propagation path geometry variations. The processor load due to the driver is 0.4 percent on the P4.</p> 34*2b15cb3dSCy Schubert<p>The driver performs a number of error checks to protect against overdriven or underdriven input signal levels, incorrect signal format or improper hardware configuration. The specific checks are detailed later in this page. Note that additional checks are done elsewhere in the reference clock interface routines.</p> 359c2daa00SOllivier Robert<p>This driver incorporates several features in common with other audio drivers such as described in the <a href="driver36.html">Radio WWV/H Audio Demodulator/Decoder</a> and the <a href="driver6.html">IRIG Audio Decoder</a> pages. They include automatic gain control (AGC), selectable audio codec port and signal monitoring capabilities. For a discussion of these common features, as well as a guide to hookup, debugging and monitoring, see the <a href="../audio.html">Reference Clock Audio Drivers</a> page.</p> 36*2b15cb3dSCy Schubert<h4>Technical Overview</h4> 37*2b15cb3dSCy Schubert<p>The driver processes 8-kHz μ-law companded codec samples using maximum-likelihood techniques which exploit the considerable degree of redundancy available in each broadcast message or burst. As described below, every character is sent twice and, in the case of format A bursts, the burst is sent eight times every minute. The single format B burst is considered correct only if every character matches its repetition in the burst. For the eight format A bursts, a majority decoder requires more than half of the 16 repetitions for each digit decode to the same value. Every character in every burst provides an independent timestamp upon arrival with a potential total of 60 timestamps for each minute.</p> 38*2b15cb3dSCy Schubert<p>The CHU timecode format is described on the <a href="http://inms-ienm.nrc-cnrc.gc.ca/time_services/chu_e.html">CHU website</a>. A timecode is assembled when all bursts have been received in each minute. The timecode is considered valid and the clock set when at least one valid format B burst has been decoded and the majority decoder declares success. Once the driver has synchronized for the first time, it will appear reachable and selectable to discipline the system clock. It is normal on occasion to miss a minute or two due to signal fades or noise. If eight successive minutes are missed, the driver is considered unreachable and the system clock will free-wheel at the latest determined frequency offset. Since the signals are almost always available during some period of the day and the NTP clock discipline algorithms are designed to work well even with long intervals between updates, it is unlikely that the system clock will drift more than a few milliseconds during periods of signal loss.</p> 39*2b15cb3dSCy Schubert<h4>Baseband Signal Processing</h4> 40*2b15cb3dSCy Schubert<p>The program consists of four major parts: the DSP modem, maximum-likelihood UART, burst assembler and majority decoder. The DSP modem demodulates Bell 103 modem answer-frequency signals; that is, frequency-shift keyed (FSK) tones of 2225 Hz (mark) and 2025 Hz (space). It consists of a 500-Hz bandpass filter centered on 2125 Hz followed by a limiter/discriminator and raised-cosine lowpass filter optimized for the 300-b/s data rate. </p> 41*2b15cb3dSCy Schubert<p>The maximum likelihood UART is implemented using a set of eight 11-stage shift registers, one for each of eight phases of the 300-b/s bit clock. At each phase a new baseband signal from the DSP modem is shifted into the corresponding register and the maximum and minimum over all 11 samples computed. This establishes a span (difference) and slice level (average) over all 11 stages. For each stage, a signal level above the slice is a mark (1) and below that is a space (0). A quality metric is calculated for each register with respect to the slice level and the a-priori signal consisting of a start bit (space), eight arbitrary information bits and two stop bits (mark).</p> 42*2b15cb3dSCy Schubert<p>The shift registers are processed in round-robin order as the phases of each bit arrive. At the end of each bit all eight phases are searched for valid framing bits, sufficient span and best metric. The best candidate found in this way represents the maximum-likelihood character. The process then continues for all ten characters in the burst.</p> 43*2b15cb3dSCy Schubert<p>The burst assembler processes characters either from the maximum-likelihood UART or directly from the serial port as configured. A burst begins when a character is received and is processed after a timeout interval when no characters are received. If the interval between characters is greater than two characters, but less than the timeout interval, the burst is rejected as a runt and a new burst begun. As each character is received, a timestamp is captured and saved for later processing.</p> 44*2b15cb3dSCy Schubert<p>A valid burst consists of ten characters in two replicated five-character blocks, each block representing ten 4-bit BCD digits. The format B blocks sent in second 31 contain the year and other information in ten digits. The eight format A blocks sent in seconds 32-39 contain the timecode in ten digits, the first of which is a framing code (6). The burst assembler must deal with cases where the first character of a format A burst is lost or is noise. This is done using the framing codes to correct the discrepancy, either one character early or one character late.</p> 45*2b15cb3dSCy Schubert<p>The burst distance is incremented by one for each bit in the first block that matches the corresponding bit in the second block and decremented by one otherwise. In a format B burst the second block is bit-inverted relative to the first, so a perfect burst of five 8-bit characters has distance -40. In a format A burst the two blocks are identical, so a perfect burst has distance +40. Format B bursts must be perfect to be acceptable; however, format A bursts, which are further processed by the majority decoder, are acceptable if the distance is at least 28.</p> 46*2b15cb3dSCy Schubert<h4>Majority Decoder</h4> 47*2b15cb3dSCy Schubert<p>Each minute of transmission includes eight format A bursts containing two timecodes for each second from 32 through 39. The majority decoder uses a decoding matrix of ten rows, one for each digit position in the timecode, and 16 columns, one for each 4-bit code combination that might be decoded at that position. In order to use the character timestamps, it is necessary to reliably determine the second number of each burst. In a valid burst, the last digit of the two timecodes in the burst must match and the value must be in the range 2-9 and greater than in the previous burst.</p> 48*2b15cb3dSCy Schubert<p>As each digit of a valid burst is processed, the value at the row corresponding to the digit position in the timecode and column corresponding to the code found at that position is incremented. At the end of the minute, each row of the decoding matrix encodes the number of occurrences of each code found at the corresponding position.</p> 49*2b15cb3dSCy Schubert<p>The maximum over all occurrences at each digit position is the distance for that position and the corresponding code is the maximum-likelihood digit. If the distance is not more than half the total number of occurrences, the decoder assumes a soft error and discards all information collected during the minute. The decoding distance is defined as the sum of the distances over the first nine digits; the tenth digit varies over the seconds and is uncounted.</p> 50*2b15cb3dSCy Schubert<p>The result of the majority decoder is a nine-digit timecode representing the maximum-likelihood candidate for the transmitted timecode in that minute. Note that the second and fraction within the minute are always zero and that the actual reference point to calculate timestamp offsets is backdated to the first second of the minute. At this point the timecode block is reformatted and the year, days, hours and minutes extracted along with other information from the format B burst, including DST state, DUT1 correction and leap warning. The reformatting operation checks the timecode for invalid code combinations that might have been left by the majority decoder and rejects the entire timecode if found.</p> 51*2b15cb3dSCy Schubert<p>If the timecode is valid, it is passed to the reference clock interface along with the backdated timestamps accumulated over the minute. A perfect set of eight bursts could generate as many as 80 timestamps, but the maximum the interface can handle is 60. These are processed using a median filter and trimmed-mean average, so the resulting system clock correction is usually much better than would otherwise be the case with radio noise, UART jitter and occasional burst errors.</p> 529c2daa00SOllivier Robert<h4>Autotune</h4> 53*2b15cb3dSCy Schubert<p>The driver includes provisions to automatically tune the radio in response to changing radio propagation conditions throughout the day and night. The radio interface is compatible with the ICOM CI-V standard, which is a bidirectional serial bus operating at TTL levels. The bus can be connected to a standard serial port using a level converter such as the CT-17. Further details are on the <a href="../audio.html">Reference Clock Audio Drivers</a> page.</p> 54*2b15cb3dSCy Schubert<p>If specified, the driver will attempt to open the device <tt>/dev/icom</tt> and, if successful will tune the radio to 3.331 MHz. The 1-kHz offset is useful with a narrowband SSB filter where the passband includes the carrier and modem signals. However, the driver is liberal in what it assumes of the configuration. If the <tt>/dev/icom</tt> link is not present or the open fails or the CI-V bus is inoperative, the driver continues in single-frequency mode.</p> 55*2b15cb3dSCy Schubert<p>As long as no bursts are received, the driver cycles over the three frequencies in turn, one minute for each station. When bursts are received from one or more stations, the driver operates in a five-minute cycle. During the first four minutes it tunes to the station with the highest metric. During the last minute it alternates between the other two stations in turn in order to measure the metric.</p> 569c2daa00SOllivier Robert<h4>Debugging Aids</h4> 579c2daa00SOllivier Robert<p>The most convenient way to track the program status is using the <tt>ntpq</tt> program and the <tt>clockvar</tt> command. This displays the last determined timecode and related status and error counters, even when the program is not discipline the system clock. If the debugging trace feature (<tt>-d</tt> on the <tt>ntpd</tt> command line) is enabled, the program produces detailed status messages as it operates. If the <tt>fudge flag 4</tt> is set, these messages are written to the <tt>clockstats</tt> file. All messages produced by this driver have the prefix <tt>chu</tt> for convenient filtering with the Unix <tt>grep</tt> command.</p> 58*2b15cb3dSCy Schubert<p>With debugging enabled the driver produces messages in the following formats: A single message beginning with <tt>chuB</tt> is produced for each format B burst received in second 31, while eight messages beginning with <tt>chuA</tt> are produced for each format A burst received in seconds 32 through 39 of the minute. The first four fields are</p> 59*2b15cb3dSCy Schubert<p><tt>stat sig n b</tt></p> 60*2b15cb3dSCy Schubert<p>where <tt>stat</tt> is the status code, <tt>sig</tt> the character span, <tt>n</tt> the number of characters in the burst (9-11) and <tt>b</tt> the burst distance (0-40). Good bursts will have spans of a 800 or more and the other numbers near the top of the range specified. See the source for the interpretation of the remaining data in the burst. Note that each character of the burst is encoded as two digits in nibble-swapped order.</p> 619c2daa00SOllivier Robert<p>If the CI-V interface for ICOM radios is active, a debug level greater than 1 will produce a trace of the CI-V command and response messages. Interpretation of these messages requires knowledge of the CI-V protocol, which is beyond the scope of this document.</p> 629c2daa00SOllivier Robert<h4>Monitor Data</h4> 639c2daa00SOllivier RobertWhen enabled by the <tt>filegen</tt> facility, every received timecode is written to the <tt>clockstats</tt> file in the following format: 649c2daa00SOllivier Robert<pre> 65*2b15cb3dSCy Schubert sq yyyy ddd hh:mm:ss lw dst du lset agc rfrq bcnt dist tsmp 669c2daa00SOllivier Robert 679c2daa00SOllivier Robert s sync indicator 689c2daa00SOllivier Robert q quality character 699c2daa00SOllivier Robert yyyy Gregorian year 709c2daa00SOllivier Robert ddd day of year 719c2daa00SOllivier Robert hh hour of day 729c2daa00SOllivier Robert mm minute of hour 739c2daa00SOllivier Robert ss second of minute 74*2b15cb3dSCy Schubert lw leap second warning 75*2b15cb3dSCy Schubert dst DST state 769c2daa00SOllivier Robert dut DUT sign and magnitude in deciseconds 779c2daa00SOllivier Robert lset minutes since last set 789c2daa00SOllivier Robert agc audio gain (0-255) 79*2b15cb3dSCy Schubert ident CHU identifier code 80*2b15cb3dSCy Schubert dist decoder distance 819c2daa00SOllivier Robert tsmp timestamps captured 829c2daa00SOllivier Robert</pre> 839c2daa00SOllivier RobertThe fields beginning with <tt>year</tt> and extending through <tt>dut</tt> are decoded from the received data and are in fixed-length format. The <tt>agc</tt> and <tt>lset</tt> fields, as well as the following driver-dependent fields, are in variable-length format. 849c2daa00SOllivier Robert<dl> 85*2b15cb3dSCy Schubert <dt><tt>s</tt></dt> 86*2b15cb3dSCy Schubert <dd>The sync indicator is initially <tt>?</tt> before the clock is set, but turns to space when the clock has been correctly set.</dd> 87*2b15cb3dSCy Schubert <dt><tt>q</tt></dt> 889c2daa00SOllivier Robert <dd>The quality character is a four-bit hexadecimal code showing which alarms have been raised during the most recent minute. Each bit is associated with a specific alarm condition according to the following: 899c2daa00SOllivier Robert <dl> 90*2b15cb3dSCy Schubert <dt><tt>8</tt></dt> 91*2b15cb3dSCy Schubert <dd>Timestamp alarm. Fewer than 20 timestamps have been determined.</dd> 92*2b15cb3dSCy Schubert <dt><tt>4</tt></dt> 93*2b15cb3dSCy Schubert <dd>Decoder alarm. A majority of repetitions for at least one digit of the timecode fails to agree.</dd> 94*2b15cb3dSCy Schubert <dt><tt>2</tt></dt> 95*2b15cb3dSCy Schubert <dd>Format alarm. One or more bursts contained invalid data or was improperly formatted.</dd> 96*2b15cb3dSCy Schubert <dt><tt>1</tt></dt> 97*2b15cb3dSCy Schubert <dd>Frame alarm. One or more bursts was improperly framed or contained too many repetition errors.</dd> 989c2daa00SOllivier Robert </dl> 99*2b15cb3dSCy Schubert The timestamp and decoder alarms are fatal; the data accumulated during the minute are not used to set the clock. The format and fram alarm are nonfatal; only the data in the burst are discarded.</dd> 100*2b15cb3dSCy Schubert <dt><tt>yyyy ddd hh:mm:ss</tt></dt> 101*2b15cb3dSCy Schubert <dd>The timecode format itself is self explanatory. Note that the Gregorian year is decoded directly from the transmitted timecode.</dd> 102*2b15cb3dSCy Schubert <dt><tt>lw</tt></dt> 103*2b15cb3dSCy Schubert <dd>The leap second warning is normally space, but changes to <tt>L</tt> if a leap second is to occur at the end of the month.</dd> 104*2b15cb3dSCy Schubert <dt><tt>dst</tt></dt> 105*2b15cb3dSCy Schubert <dd>The DST code for Canada encodes the state for all provinces. It is encoded as two hex characters.</dd> 106*2b15cb3dSCy Schubert <dt><tt>dut</tt></dt> 107*2b15cb3dSCy Schubert <dd>The DUT sign and magnitude shows the current UT1 offset relative to the displayed UTC time, in deciseconds. It is encoded as one digit preceeded by sign.</dd> 108*2b15cb3dSCy Schubert <dt><tt>lset</tt></dt> 109*2b15cb3dSCy Schubert <dd>Before the clock is set, this is the number of minutes since the program was started; after the clock is set, this is the number of minutes since the time was last verified relative to the broadcast signal.</dd> 110*2b15cb3dSCy Schubert <dt><tt>agc</tt></dt> 111*2b15cb3dSCy Schubert <dd>The audio gain shows the current codec gain setting in the range 0 to 255. Ordinarily, the receiver audio gain control should be set for a value midway in this range.</dd> 112*2b15cb3dSCy Schubert <dt><tt>ident</tt></dt> 113*2b15cb3dSCy Schubert <dd>The CHU identifier <tt>CHU </tt>followed by the current radio frequency 114*2b15cb3dSCy Schubert code, if the CI-V interface is active, or <tt>CHU</tt> if not. The radio 115*2b15cb3dSCy Schubert frequncy is encoded as 0 for 3.330 MHz, 1 for 7.850 MHz and 2 116*2b15cb3dSCy Schubert for 14.670 MHz.</dd> 117*2b15cb3dSCy Schubert <dt><tt>dist</tt></dt> 118*2b15cb3dSCy Schubert <dd>The decoding distance determined during the most recent minute bursts were received. The values range from 0 to 160, with the higher values indicating better signals. The decoding algorithms require the distance at least 50; otherwise all data in the minute are discarded.</dd> 119*2b15cb3dSCy Schubert <dt><tt>tsmp</tt></dt> 120*2b15cb3dSCy Schubert <dd>The number of timestamps determined during the most recent minute bursts were received. The values range from 0 to 60, with the higher values indicating better signals. The decoding algoriths require at least 20 timestamps in the minute; otherwise all data in the minute are discarded.</dd> 1219c2daa00SOllivier Robert</dl> 1229c2daa00SOllivier Robert<h4>Fudge Factors</h4> 1239c2daa00SOllivier Robert<dl> 124*2b15cb3dSCy Schubert <dt><tt>time1 <i>time</i></tt></dt> 125*2b15cb3dSCy Schubert <dd>Specifies the propagation delay for CHU (45:18N 75:45N), in seconds and fraction, with default 0.0.</dd> 126*2b15cb3dSCy Schubert <dt><tt>time2 <i>time</i></tt></dt> 127*2b15cb3dSCy Schubert <dd>Not used by this driver.</dd> 128*2b15cb3dSCy Schubert <dt><tt>stratum <i>number</i></tt></dt> 129*2b15cb3dSCy Schubert <dd>Specifies the driver stratum, in decimal from 0 to 15, with default 0.</dd> 130*2b15cb3dSCy Schubert <dt><tt>refid <i>string</i></tt></dt> 131*2b15cb3dSCy Schubert <dd>Specifies the driver reference identifier, an ASCII string from one to four characters, with default <tt>CHU</tt>.</dd> 132*2b15cb3dSCy Schubert <dt><tt>flag1 0 | 1</tt></dt> 133*2b15cb3dSCy Schubert <dd>Not used by this driver.</dd> 134*2b15cb3dSCy Schubert <dt><tt>flag2 0 | 1</tt></dt> 135*2b15cb3dSCy Schubert <dd>When the audio driver is compiled, this flag selects the audio input port, where 0 is the mike port (default) and 1 is the line-in port. It does not seem useful to select the compact disc player port.</dd> 136*2b15cb3dSCy Schubert <dt><tt>flag3 0 | 1</tt></dt> 137*2b15cb3dSCy Schubert <dd>When the audio driver is compiled, this flag enables audio monitoring of the input signal. For this purpose, the speaker volume must be set before the driver is started.</dd> 138*2b15cb3dSCy Schubert <dt><tt>flag4 0 | 1</tt></dt> 139*2b15cb3dSCy Schubert <dd>Enable verbose <tt>clockstats</tt> recording if set.</dd> 1409c2daa00SOllivier Robert</dl> 1419c2daa00SOllivier Robert<hr> 142ea906c41SOllivier Robert<script type="text/javascript" language="javascript" src="scripts/footer.txt"></script> 1439c2daa00SOllivier Robert</body> 1449c2daa00SOllivier Robert</html> 145