Tweaked syncing code
This commit is contained in:
parent
7e899d01e0
commit
645bc3463f
|
@ -73,7 +73,6 @@ std::complex<float> CostasBeaconSync::work(std::complex<float> in) {
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CostasBeaconSync::~CostasBeaconSync() {
|
CostasBeaconSync::~CostasBeaconSync() {
|
||||||
firfilt_crcf_destroy(bandpass);
|
firfilt_crcf_destroy(bandpass);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include "fft-beacon-finder.h"
|
#include "fft-beacon-finder.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
FFTBeaconFinder::FFTBeaconFinder(int samplingrate) {
|
FFTBeaconFinder::FFTBeaconFinder(int samplingrate) {
|
||||||
this->samplingrate = samplingrate;
|
this->samplingrate = samplingrate;
|
||||||
|
|
||||||
|
@ -10,6 +12,9 @@ FFTBeaconFinder::FFTBeaconFinder(int samplingrate) {
|
||||||
|
|
||||||
pos = 0;
|
pos = 0;
|
||||||
next_fft_in = 0;
|
next_fft_in = 0;
|
||||||
|
|
||||||
|
last_center = 0;
|
||||||
|
last_center_level = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::complex<float> FFTBeaconFinder::work(std::complex<float> in) {
|
std::complex<float> FFTBeaconFinder::work(std::complex<float> in) {
|
||||||
|
@ -28,29 +33,52 @@ std::complex<float> FFTBeaconFinder::work(std::complex<float> in) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float max_levels = 0;
|
std::cout << std::endl;
|
||||||
int max_center = 0;
|
|
||||||
for (int bin = -50; bin <= 50; bin++) {
|
|
||||||
int center_idx = spectral_bin_to_fft_idx(bin);
|
|
||||||
float center_val = std::abs(fft_out[center_idx]) / fft_max;
|
|
||||||
if (center_val > 0.25) {
|
|
||||||
int left_idx = spectral_bin_to_fft_idx(bin - 127);
|
|
||||||
int right_idx = spectral_bin_to_fft_idx(bin + 127);
|
|
||||||
float left_val = std::abs(fft_out[left_idx]) / fft_max;
|
|
||||||
float right_val = std::abs(fft_out[right_idx]) / fft_max;
|
|
||||||
|
|
||||||
if (center_val + left_val + right_val > max_levels) {
|
int last_center_idx = spectral_bin_to_fft_idx(last_center);
|
||||||
max_levels = center_val + left_val + right_val;
|
float last_center_val =
|
||||||
max_center = bin;
|
std::abs(fft_out[last_center_idx]) / fft_max;
|
||||||
|
|
||||||
|
if (last_center_val < 0.25) {
|
||||||
|
float max_levels = 0;
|
||||||
|
int max_center = 0;
|
||||||
|
for (int bin = -50; bin <= 50; bin++) {
|
||||||
|
int center_idx = spectral_bin_to_fft_idx(bin);
|
||||||
|
float center_val = std::abs(fft_out[center_idx]) / fft_max;
|
||||||
|
if (center_val > 0.25) {
|
||||||
|
int left_idx = spectral_bin_to_fft_idx(bin - 127);
|
||||||
|
int right_idx = spectral_bin_to_fft_idx(bin + 127);
|
||||||
|
float left_val = std::abs(fft_out[left_idx]) / fft_max;
|
||||||
|
float right_val =
|
||||||
|
std::abs(fft_out[right_idx]) / fft_max;
|
||||||
|
|
||||||
|
std::cout << bin << " " << left_val << " | "
|
||||||
|
<< center_val << " | " << right_val
|
||||||
|
<< std::endl;
|
||||||
|
|
||||||
|
if (center_val + left_val + right_val > max_levels) {
|
||||||
|
max_levels = center_val + left_val + right_val;
|
||||||
|
max_center = bin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (max_levels > 0.0) {
|
if (max_levels > 0.0) {
|
||||||
float center_freq = max_center * samplingrate / FFT_LEN;
|
last_center = max_center;
|
||||||
nco_crcf_set_frequency(
|
|
||||||
coarse_correction,
|
float center_freq =
|
||||||
-(2 * M_PI * center_freq) / samplingrate);
|
float(max_center) / FFT_LEN * samplingrate;
|
||||||
|
nco_crcf_set_frequency(
|
||||||
|
coarse_correction,
|
||||||
|
-(2 * M_PI * center_freq) / samplingrate);
|
||||||
|
|
||||||
|
std::cout << "New center " << center_freq << " "
|
||||||
|
<< max_center << std::endl;
|
||||||
|
} else {
|
||||||
|
std::cout << "No center found!" << std::endl;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cout << "Last center still valid" << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
next_fft_in = samplingrate / 4;
|
next_fft_in = samplingrate / 4;
|
||||||
|
@ -74,11 +102,10 @@ int FFTBeaconFinder::spectral_bin_to_fft_idx(int bin) {
|
||||||
} else if (bin > 0) {
|
} else if (bin > 0) {
|
||||||
return bin - 1;
|
return bin - 1;
|
||||||
} else {
|
} else {
|
||||||
return bin + FFT_LEN;
|
return FFT_LEN + bin;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FFTBeaconFinder::~FFTBeaconFinder() {
|
FFTBeaconFinder::~FFTBeaconFinder() {
|
||||||
nco_crcf_destroy(coarse_correction);
|
nco_crcf_destroy(coarse_correction);
|
||||||
fft_destroy_plan(fft);
|
fft_destroy_plan(fft);
|
||||||
|
|
|
@ -20,12 +20,15 @@ class FFTBeaconFinder {
|
||||||
size_t pos;
|
size_t pos;
|
||||||
int next_fft_in;
|
int next_fft_in;
|
||||||
|
|
||||||
|
int last_center;
|
||||||
|
float last_center_level;
|
||||||
|
|
||||||
int spectral_bin_to_fft_idx(int);
|
int spectral_bin_to_fft_idx(int);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FFTBeaconFinder(int);
|
FFTBeaconFinder(int);
|
||||||
~FFTBeaconFinder();
|
~FFTBeaconFinder();
|
||||||
|
|
||||||
std::complex<float> work(std::complex<float>);
|
std::complex<float> work(std::complex<float>);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ blocks:
|
||||||
alias: ''
|
alias: ''
|
||||||
amp: '1'
|
amp: '1'
|
||||||
comment: ''
|
comment: ''
|
||||||
freq: '35000'
|
freq: '-10000'
|
||||||
maxoutbuf: '0'
|
maxoutbuf: '0'
|
||||||
minoutbuf: '0'
|
minoutbuf: '0'
|
||||||
offset: '0'
|
offset: '0'
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include "costas-beacon-sync.h"
|
#include "costas-beacon-sync.h"
|
||||||
#include "fft-beacon-finder.h"
|
#include "fft-beacon-finder.h"
|
||||||
|
|
||||||
|
const size_t buffer_size = 4069;
|
||||||
|
|
||||||
int main(int argc, char const* argv[]) {
|
int main(int argc, char const* argv[]) {
|
||||||
FILE* output = fopen("output.raw", "w");
|
FILE* output = fopen("output.raw", "w");
|
||||||
FILE* input = fopen("input.raw", "r");
|
FILE* input = fopen("input.raw", "r");
|
||||||
|
@ -16,14 +18,24 @@ int main(int argc, char const* argv[]) {
|
||||||
int sample_count = 0;
|
int sample_count = 0;
|
||||||
clock_t start_time = clock();
|
clock_t start_time = clock();
|
||||||
|
|
||||||
std::complex<float> in;
|
std::complex<float> in_buffer[buffer_size];
|
||||||
while (fread(&in, sizeof(std::complex<float>), 1, input) == 1) {
|
std::complex<float> out_buffer[buffer_size];
|
||||||
std::complex<float> coarse_synced = finder.work(in);
|
|
||||||
std::complex<float> sync_correction = sync.work(coarse_synced);
|
|
||||||
std::complex<float> out = coarse_synced * sync_correction;
|
|
||||||
|
|
||||||
fwrite(&out, sizeof(std::complex<float>), 1, output);
|
size_t len =
|
||||||
sample_count++;
|
fread(in_buffer, sizeof(std::complex<float>), buffer_size, input);
|
||||||
|
while (len > 0) {
|
||||||
|
for (size_t i = 0; i < len; i++) {
|
||||||
|
std::complex<float> coarse_synced = finder.work(in_buffer[i]);
|
||||||
|
std::complex<float> sync_correction = sync.work(coarse_synced);
|
||||||
|
out_buffer[i] = coarse_synced * sync_correction;
|
||||||
|
}
|
||||||
|
|
||||||
|
sample_count += len;
|
||||||
|
|
||||||
|
fwrite(out_buffer, sizeof(std::complex<float>), buffer_size, output);
|
||||||
|
|
||||||
|
len =
|
||||||
|
fread(&in_buffer, sizeof(std::complex<float>), buffer_size, input);
|
||||||
};
|
};
|
||||||
|
|
||||||
clock_t end_time = clock();
|
clock_t end_time = clock();
|
||||||
|
|
Loading…
Reference in New Issue