[time-nuts] WWV Doppler Shift
jimlux
jimlux at earthlink.net
Fri Nov 23 00:12:47 UTC 2018
On 11/22/18 3:38 PM, Attila Kinali wrote:
> On Tue, 20 Nov 2018 15:30:54 -0800
> "Tom Van Baak" <tvb at LeapSecond.com> wrote:
>
>> How hard would it be to use a hands-off SDR to produce a 5 MHz WWV phase
>> data point every second?
>
> Fairly easy. If you go for one of the RTLSDR dongles, you will
> have to do the direct-sampling-mod[1], as the tuner chips do not
> go this low, and provide an external filter.
The one from RTL-SDR (v.3) has the mod from the factory.
You *will* need a filter - there's a nice image; everything above and
below 14.4 MHz is replicated. The digital down converter inside works
just fine, so tuning to 5 MHz (or slightly off) works just fine.
It puts out 8 bit I/Q data - I use the rtl_sdr.c program (slightly
modified) to grab samples and dump them into a file, then post process.
You could probably also use rtl_tcp to stream to some utility hanging
off a socket.
I fire it off with something like this (with the rtl running connected
to a beaglebone):
ssh -f -q debian at beagle101 "rtl_sdr -D 2 -s 1e6 -f 5.001e6 -n 100000
/tmp/capture.bin 2>temperr.txt >temp.txt"
Using the right
> sampling rate (ie something odd) and both 60kHz and 5MHz will
> end up somewhere nice. For additional goodness, I would either
> lock the 28.8MHz crystal to a stable source, or use a third
> RTLSDR dongle to provide the 28.8MHz clock for the other two,
> and sample with that a convenient stable signal (eg. the harmonics
> of an 10MHz signal).
>
> Alternatively, and much simpler, bu5 more expensive, you can go
> for an airspy[2] which already has an external reference input
> and two ADC inputs. All you need are some pigtails with U-FL
> connectors for the ADC inputs, and an MCX one for the reference
> clock source.
>
> Attila Kinali
>
>
> [1] https://www.rtl-sdr.com/rtl-sdr-direct-sampling-mode/
>
> [2] https://www.itead.cc/airspy.html?acc=cfcd208495d565ef66e7dff9f98764da
>
-------------- next part --------------
/*
* rtl-sdr, turns your Realtek RTL2832 based DVB dongle into a SDR receiver
* Copyright (C) 2012 by Steve Markgraf <steve at steve-m.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* jimlux 13 Oct 2017 - add -D switch for direct sampling */
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#ifndef _WIN32
#include <unistd.h>
#else
#include <windows.h>
#include <io.h>
#include <fcntl.h>
#include "getopt/getopt.h"
#endif
#include "rtl-sdr.h"
#include "convenience/convenience.h"
#define DEFAULT_SAMPLE_RATE 2048000
#define DEFAULT_BUF_LENGTH (16 * 16384)
#define MINIMAL_BUF_LENGTH 512
#define MAXIMAL_BUF_LENGTH (256 * 16384)
static int do_exit = 0;
static uint32_t bytes_to_read = 0;
static rtlsdr_dev_t *dev = NULL;
void usage(void)
{
fprintf(stderr,
"rtl_sdr, an I/Q recorder for RTL2832 based DVB-T receivers\n\n"
"Usage:\t -f frequency_to_tune_to [Hz]\n"
"\t[-s samplerate (default: 2048000 Hz)]\n"
"\t[-d device_index (default: 0)]\n"
"\t[-g gain (default: 0 for auto)]\n"
"\t[-p ppm_error (default: 0)]\n"
"\t[-b output_block_size (default: 16 * 16384)]\n"
"\t[-n number of samples to read (default: 0, infinite)]\n"
"\t[-S force sync output (default: async)]\n"
"\tfilename (a '-' dumps samples to stdout)\n\n"
"\texperimental jimlux\n"
"\t[-D 1|2 direct sampling]\n" );
exit(1);
}
#ifdef _WIN32
BOOL WINAPI
sighandler(int signum)
{
if (CTRL_C_EVENT == signum) {
fprintf(stderr, "Signal caught, exiting!\n");
do_exit = 1;
rtlsdr_cancel_async(dev);
return TRUE;
}
return FALSE;
}
#else
static void sighandler(int signum)
{
fprintf(stderr, "Signal caught, exiting!\n");
do_exit = 1;
rtlsdr_cancel_async(dev);
}
#endif
static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
{
if (ctx) {
if (do_exit)
return;
if ((bytes_to_read > 0) && (bytes_to_read < len)) {
len = bytes_to_read;
do_exit = 1;
rtlsdr_cancel_async(dev);
}
if (fwrite(buf, 1, len, (FILE*)ctx) != len) {
fprintf(stderr, "Short write, samples lost, exiting!\n");
rtlsdr_cancel_async(dev);
}
if (bytes_to_read > 0)
bytes_to_read -= len;
}
}
int main(int argc, char **argv)
{
#ifndef _WIN32
struct sigaction sigact;
#endif
char *filename = NULL;
int n_read;
int r, opt;
int gain = 0;
int ppm_error = 0;
int sync_mode = 0;
int direct_sampling =0; //jimlux
FILE *file;
uint8_t *buffer;
int dev_index = 0;
int dev_given = 0;
uint32_t frequency = 100000000;
uint32_t samp_rate = DEFAULT_SAMPLE_RATE;
uint32_t out_block_size = DEFAULT_BUF_LENGTH;
while ((opt = getopt(argc, argv, "d:f:g:s:b:n:p:S:D:")) != -1) { //jimlux - added D:
switch (opt) {
case 'd':
dev_index = verbose_device_search(optarg);
dev_given = 1;
break;
case 'f':
frequency = (uint32_t)atofs(optarg);
break;
case 'g':
gain = (int)(atof(optarg) * 10); /* tenths of a dB */
break;
case 's':
samp_rate = (uint32_t)atofs(optarg);
break;
case 'p':
ppm_error = atoi(optarg);
break;
case 'b':
out_block_size = (uint32_t)atof(optarg);
break;
case 'n':
bytes_to_read = (uint32_t)atof(optarg) * 2;
break;
case 'D': //jimlux
direct_sampling = atoi(optarg);
break;
case 'S':
sync_mode = 1;
break;
default:
usage();
break;
}
}
if (argc <= optind) {
usage();
} else {
filename = argv[optind];
}
if(out_block_size < MINIMAL_BUF_LENGTH ||
out_block_size > MAXIMAL_BUF_LENGTH ){
fprintf(stderr,
"Output block size wrong value, falling back to default\n");
fprintf(stderr,
"Minimal length: %u\n", MINIMAL_BUF_LENGTH);
fprintf(stderr,
"Maximal length: %u\n", MAXIMAL_BUF_LENGTH);
out_block_size = DEFAULT_BUF_LENGTH;
}
buffer = malloc(out_block_size * sizeof(uint8_t));
if (!dev_given) {
dev_index = verbose_device_search("0");
}
if (dev_index < 0) {
exit(1);
}
r = rtlsdr_open(&dev, (uint32_t)dev_index);
if (r < 0) {
fprintf(stderr, "Failed to open rtlsdr device #%d.\n", dev_index);
exit(1);
}
#ifndef _WIN32
sigact.sa_handler = sighandler;
sigemptyset(&sigact.sa_mask);
sigact.sa_flags = 0;
sigaction(SIGINT, &sigact, NULL);
sigaction(SIGTERM, &sigact, NULL);
sigaction(SIGQUIT, &sigact, NULL);
sigaction(SIGPIPE, &sigact, NULL);
#else
SetConsoleCtrlHandler( (PHANDLER_ROUTINE) sighandler, TRUE );
#endif
/* Set the sample rate */
verbose_set_sample_rate(dev, samp_rate);
/* Set the frequency */
verbose_set_frequency(dev, frequency);
/* direct sampling */ //jimlux
if (direct_sampling) {
verbose_direct_sampling(dev, direct_sampling);
}
if (0 == gain) {
/* Enable automatic gain */
verbose_auto_gain(dev);
} else {
/* Enable manual gain */
gain = nearest_gain(dev, gain);
verbose_gain_set(dev, gain);
}
verbose_ppm_set(dev, ppm_error);
if(strcmp(filename, "-") == 0) { /* Write samples to stdout */
file = stdout;
#ifdef _WIN32
_setmode(_fileno(stdin), _O_BINARY);
#endif
} else {
file = fopen(filename, "wb");
if (!file) {
fprintf(stderr, "Failed to open %s\n", filename);
goto out;
}
}
/* Reset endpoint before we start reading from it (mandatory) */
verbose_reset_buffer(dev);
if (sync_mode) {
fprintf(stderr, "Reading samples in sync mode...\n");
while (!do_exit) {
r = rtlsdr_read_sync(dev, buffer, out_block_size, &n_read);
if (r < 0) {
fprintf(stderr, "WARNING: sync read failed.\n");
break;
}
if ((bytes_to_read > 0) && (bytes_to_read < (uint32_t)n_read)) {
n_read = bytes_to_read;
do_exit = 1;
}
if (fwrite(buffer, 1, n_read, file) != (size_t)n_read) {
fprintf(stderr, "Short write, samples lost, exiting!\n");
break;
}
if ((uint32_t)n_read < out_block_size) {
fprintf(stderr, "Short read, samples lost, exiting!\n");
break;
}
if (bytes_to_read > 0)
bytes_to_read -= n_read;
}
} else {
fprintf(stderr, "Reading samples in async mode...\n");
r = rtlsdr_read_async(dev, rtlsdr_callback, (void *)file,
0, out_block_size);
}
if (do_exit)
fprintf(stderr, "\nUser cancel, exiting...\n");
else
fprintf(stderr, "\nLibrary error %d, exiting...\n", r);
if (file != stdout)
fclose(file);
rtlsdr_close(dev);
free (buffer);
out:
return r >= 0 ? r : -r;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hf2.png
Type: image/png
Size: 172085 bytes
Desc: not available
URL: <http://febo.com/pipermail/time-nuts_lists.febo.com/attachments/20181122/bf2ad185/attachment.png>
More information about the Time-nuts_lists.febo.com
mailing list