An interesting book is: "A software defined GPS and Galileo receiver" , a single frequency approach, by Kai Borre et al. At the back of the book is a CDROM with a dataset. That dataset contains the if-output of a real SDR tuned to a GPS-signal. I copied the test-file to a convenient place and renamed it to testdata.dat. Then I wrote (actually based on a snippet of java-code somewhere on the internet) a FileIO-method:
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class FileIO { private String status = ""; private FileReader fr; private BufferedReader br; private String inputFileName; String sourceRoot = "data\\"; public void fileSetup() { // open the input-file inputFileName = sourceRoot + "testdata.bin"; try { status = "OK"; fr = new FileReader(inputFileName); br = new BufferedReader(fr); } catch (IOException e) { status = "IO-error input file"; } System.out .println("Reading input-file...\n status = " + status); } public int readchar() { int record = 0; try { record = br.read(); } catch (IOException e) { // // put your error-handling code here // status = "some IO-error during reading"; } return record; } } |
I called this method in fillArray5():
public void fillArray5() { // use external dataset with samples // show histogram of sample-values FileIO inputfile = new FileIO(); inputfile.fileSetup(); int kar; int min = 0; int max = 0; int avg = 0; int[] bins = new int[16]; for(int k=0; k <16; k++) {bins[k] = 0;} int aantal = 1000; for(int k=0; k < aantal; k++) { kar = inputfile.readchar(); if (kar > 127) {kar = kar - 256;} //System.out.print(kar); System.out.print(','); //if (k/32 == k%32) {System.out.println();} if (kar < min) { min = kar; } if (kar > max) { max = kar; } avg = avg + kar; bins[kar + 8]++; } System.out.println(); System.out.println("aantal = " + aantal); System.out.println("min = " + min + " max = " + max); System.out.println("average = " + avg); plotData = new double[16]; for(int k=0; k <16; k++) {System.out.println("bins[" + (k-8) + "] = " + bins[k]); plotData[k] = bins[k]; } } |
The program calculates a histogram of the values in the dataset. The output from System.out reads:
Reading input-file... status = OK aantal = 1000 min = -8 max = 7 average = -637 bins[-8] = 2 bins[-7] = 4 bins[-6] = 16 bins[-5] = 25 bins[-4] = 76 bins[-3] = 106 bins[-2] = 133 bins[-1] = 164 bins[0] = 146 bins[1] = 139 bins[2] = 96 bins[3] = 46 bins[4] = 29 bins[5] = 15 bins[6] = 1 bins[7] = 2
and the graphical output:
A nice noisy input-signal. Obviously a 3-bit signal with a sign.
fillArray6() simply shows the first samples:
public void fillArray6() { // simply display the first 100 samples of external dataset FileIO inputfile = new FileIO(); inputfile.fileSetup(); int kar; int aantal = 100; double x[] = new double[aantal]; for(int k=0; k < aantal; k++) { kar = inputfile.readchar(); if (kar > 127) {kar = kar - 256;} x[k] = kar; } plotData = x; } |
With output:
public void fillArray7() { // show Fourier-transform of first 1268 samples of external dataset FileIO inputfile = new FileIO(); inputfile.fileSetup(); int kar; int aantal = 1268; double x[] = new double[aantal]; for(int k=0; k < aantal; k++) { kar = inputfile.readchar(); if (kar > 127) {kar = kar - 256;} x[k] = kar; } Complex bins[] = dft(x); // calculate the DFT System.out.println("dft calculated"); plotData = new double[aantal]; for (int i=0; i < bins.length; i++) { plotData[i] = bins[i].magnitude(); } } |
the corresponding picture:
samplesFFT.png
public void fillArray8() { // show averaged Fourier-transform of dataset // this calculation may take some minutes... FileIO inputfile = new FileIO(); inputfile.fileSetup(); int kar; int aantal = 1268; int n = 10; int naantal = n * aantal; double x[] = new double[naantal]; for(int k=0; k < naantal; k++) { kar = inputfile.readchar(); if (kar > 127) {kar = kar - 256;} x[k] = kar; } Complex bins[] = dft(x); // calculate the DFT System.out.println("dft calculated"); plotData = new double[aantal]; for (int i=0; i < aantal; i++) { double acc = 0; for(int j=0; j < n; j++) { acc = acc + bins[i * n + j].magnitude(); } plotData[i] = acc; } } |
Calculation takes over a minute on my laptop. This is what you would expect of a GPS-signal!!