From 8479e8c7f7f8b000bad494c980dd8871e8c3b7a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Pleva=C4=8D?= Date: Tue, 10 Oct 2023 15:38:25 +0200 Subject: [PATCH] FFT on RPI --- station/config.py | 2 +- station/tools/baseband_spectogram.py | 45 +++++++++++++++++++++------- web/seeds.php | 39 +++++++++++++++++++++++- 3 files changed, 73 insertions(+), 13 deletions(-) diff --git a/station/config.py b/station/config.py index fa55356..84390b5 100644 --- a/station/config.py +++ b/station/config.py @@ -1,4 +1,4 @@ masterUrl = "http://10.0.0.8" -apiKey = "37c82347-f4fb-4552-950c-7e0767275eb6" +apiKey = "6f44206f-6d59-4761-b5a2-07172ecea2e6" pullInterval = 120 # in sec planInterval = 1200 # in sec \ No newline at end of file diff --git a/station/tools/baseband_spectogram.py b/station/tools/baseband_spectogram.py index b98f76e..58b7e67 100644 --- a/station/tools/baseband_spectogram.py +++ b/station/tools/baseband_spectogram.py @@ -10,7 +10,7 @@ if __name__ == '__main__': cliParser.add_argument('input_file', type=str, help='input filename') cliParser.add_argument('output_file', type=str, help='output filename') - cliParser.add_argument('-fs', '--sampleRate', type=float, help='sets the sample rate [hz]') + cliParser.add_argument('-fs', '--sampleRate', type=float, help='sets the sample rate [hz]') cliParser.add_argument('-fc', '--centralFreq', type=float, help='sets the sample rate [hz]') cliParser.add_argument('-f', '--format', type=str, @@ -20,22 +20,45 @@ if __name__ == '__main__': args = cliParser.parse_args() - data = np.fromfile(args.input_file, dtype=args.format) - - data = data[1::2] + 1j * data[0::2] + data = np.memmap(args.input_file, dtype=args.format, mode="r") fft_size = 1024 - sample_rate = args.sampleRate - Fc = args.centralFreq - num_rows = len(data) // fft_size # // is an integer division which rounds down + sampleSize = 2 # I and Q + + sample_rate = args.sampleRate + Fc = args.centralFreq + num_rows = len(data) // fft_size // sampleSize + + # ok compute how many data to one row + num_rows_real = 100 + if num_rows < num_rows_real: + num_rows_real = num_rows + + abstract_rows_per_row = int(num_rows / num_rows_real) - spectrogram = np.zeros((num_rows, fft_size)) + spectrogram = np.zeros((num_rows_real, fft_size)) - for i in range(num_rows): - spectrogram[i,:] = 10 * np.log10(np.abs(np.fft.fftshift(np.fft.fft(data[i*fft_size:(i+1)*fft_size])))**2) + sub_fft = None + for i in range(abstract_rows_per_row * num_rows_real): + + subdata_start = i * sampleSize * fft_size + subdata = data[subdata_start : subdata_start + fft_size * sampleSize] + + subdata = subdata[1::2] + 1j * subdata[0::2] # convert to complex + + cur_fft = 10 * np.log10(np.abs(np.fft.fftshift(np.fft.fft(subdata)))**2) + + if sub_fft is None: + sub_fft = cur_fft + else: + sub_fft = np.mean(np.array([cur_fft, sub_fft]), axis=0) + + if i % abstract_rows_per_row == 0: + img_row = int(i // abstract_rows_per_row) + spectrogram[img_row,:] = sub_fft + sub_fft = None fig = plt.figure(figsize=(5, num_rows / sample_rate * 20)) - plt.imshow(spectrogram, cmap=plt.get_cmap('winter'), aspect='auto', extent = [sample_rate/-2/1e6 + Fc/1e6, sample_rate/2/1e6 + Fc/1e6, 0, len(data)/sample_rate], vmin=0, vmax=np.max(spectrogram)) plt.xlabel("Frequency [MHz]") plt.ylabel("Time [s]") diff --git a/web/seeds.php b/web/seeds.php index 5d2fafa..efc220d 100644 --- a/web/seeds.php +++ b/web/seeds.php @@ -12,6 +12,10 @@ $leoWSatTape->name->set("Weather Satellite"); $leoWSatTape->commit(); + $nanosatelliteType = new \DAL\targetType(); + $nanosatelliteType->name->set("Nanosatellite"); + $nanosatelliteType->commit(); + $avhrrType = new \DAL\dataType(); $avhrrType->name->set("AVHRR"); $avhrrType->commit(); @@ -20,6 +24,10 @@ $msumrType->name->set("MSU-MR"); $msumrType->commit(); + $telemetryType = new \DAL\dataType(); + $telemetryType->name->set("Telemetry"); + $telemetryType->commit(); + /** * Antennas seeds */ @@ -102,6 +110,10 @@ $lrpt->name->set("LRPT"); $lrpt->commit(); + $cw = new \DAL\modulation(); + $cw->name->set("CW"); + $cw->commit(); + /** * Process pipes */ @@ -304,12 +316,37 @@ $meteor23HRPT->antenna->set($qfh); $meteor23HRPT->commit(); + $maxvalier = new \DAL\target(); + $maxvalier->name->set("MAX VALIER SAT"); + $maxvalier->type->set($nanosatelliteType); + $maxvalier->orbit->set("leo"); + $maxvalier->description->set(""); + $maxvalier->locator->set([ + "tle" => [ + "line1" => "1 42778U 17036P 23282.84620820 .00050788 00000-0 10567-2 0 9991", + "line2" => "2 42778 97.1421 315.3778 0008233 57.6254 302.5791 15.45432755350391" + ] + ]); + $maxvalier->commit(); + + $maxvalierCW = new \DAL\transmitter(); + $maxvalierCW->target->set($maxvalier); + $maxvalierCW->dataType->set($telemetryType); + $maxvalierCW->bandwidth->set(120000); + $maxvalierCW->centerFrequency->set(145960000); + $maxvalierCW->modulation->set($cw); + $maxvalierCW->antenna->set($yagi); + $maxvalierCW->priority->set(0); + $maxvalierCW->processPipe->set($spectogramPipe); + $maxvalierCW->commit(); + // add autoplas $myStation137->autoPlan->set([ $noaa15APT->id->get(), $noaa18APT->id->get(), $noaa19APT->id->get(), - $meteor23LRPT1->id->get() + $meteor23LRPT1->id->get(), + $maxvalierCW->id->get() ]); $myStation137->commit(); \ No newline at end of file