Added resampling

This commit is contained in:
Sebastian 2022-01-03 16:04:09 +01:00
parent 66665622bc
commit 9e5d2b0f96
5 changed files with 29 additions and 17 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
*.raw *.raw
*.py *.py
*.csv *.csv
*.o

1
blocks/.gitignore vendored
View File

@ -1,2 +1,3 @@
.depends .depends
*.o *.o
/test

View File

@ -36,7 +36,7 @@ blocks:
id: variable id: variable
parameters: parameters:
comment: '' comment: ''
value: '1000000' value: '1024000'
states: states:
bus_sink: false bus_sink: false
bus_source: false bus_source: false

View File

@ -3,6 +3,8 @@
#include <complex> #include <complex>
#include <liquid/liquid.h>
#include "costas-beacon-sync.h" #include "costas-beacon-sync.h"
#include "fft-beacon-finder.h" #include "fft-beacon-finder.h"
@ -12,34 +14,42 @@ 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");
FFTBeaconFinder finder(1000000); FFTBeaconFinder finder(1024000);
CostasBeaconSync sync(0.03, -0.1, 0.1); CostasBeaconSync sync(0.03, -0.1, 0.1);
bool locked = false;
int sample_count = 0; int sample_count = 0;
clock_t start_time = clock(); clock_t start_time = clock();
std::complex<float> in_buffer[buffer_size]; std::complex<float> in_buffer[buffer_size];
std::complex<float> out_buffer[buffer_size]; std::complex<float> out_buffer[buffer_size/2];
firdecim_crcf decim = firdecim_crcf_create_kaiser(2,2,80);
size_t len = size_t len =
fread(in_buffer, sizeof(std::complex<float>), buffer_size, input); fread(in_buffer, sizeof(std::complex<float>), buffer_size, input);
while (len > 0) { while (len > 0) {
for (size_t i = 0; i < len; i++) { for (size_t i = 0; i < len; i+=2) {
std::complex<float> coarse_synced = std::complex<float> coarse_synced[2];
finder.work(in_buffer[i]); coarse_synced[0] = finder.work(in_buffer[i]);
std::complex<float> sync_correction = sync.work(coarse_synced); coarse_synced[1] = finder.work(in_buffer[i+1]);
std::complex<float> resampled;
firdecim_crcf_execute(decim, coarse_synced, &resampled);
std::complex<float> sync_correction = sync.work(resampled);
if(!sync.has_lock()) { if(!sync.has_lock()) {
//std::cout << "Resetting lock" << std::endl; //std::cout << "Resetting lock" << std::endl;
finder.reset_sync(); finder.reset_sync();
} }
out_buffer[i] = coarse_synced * sync_correction; out_buffer[i/2] = resampled * sync_correction;
} }
sample_count += len; sample_count += len;
fwrite(out_buffer, sizeof(std::complex<float>), buffer_size, output); fwrite(out_buffer, sizeof(std::complex<float>), buffer_size/2, output);
len = len =
fread(&in_buffer, sizeof(std::complex<float>), buffer_size, input); fread(&in_buffer, sizeof(std::complex<float>), buffer_size, input);
@ -49,7 +59,7 @@ int main(int argc, char const* argv[]) {
clock_t result = end_time - start_time; clock_t result = end_time - start_time;
std::cout << "Processed " << sample_count << " samples (" std::cout << "Processed " << sample_count << " samples ("
<< sample_count / 1000000.0 << "s) " << sample_count / 1024000.0 << "s) "
<< "in " << result / CLOCKS_PER_SEC << " s" << std::endl; << "in " << result / CLOCKS_PER_SEC << " s" << std::endl;
fclose(input); fclose(input);

View File

@ -36,7 +36,7 @@ blocks:
id: variable id: variable
parameters: parameters:
comment: '' comment: ''
value: '1000000' value: '1024000'
states: states:
bus_sink: false bus_sink: false
bus_source: false bus_source: false
@ -97,7 +97,7 @@ blocks:
ignoretag: 'True' ignoretag: 'True'
maxoutbuf: '0' maxoutbuf: '0'
minoutbuf: '0' minoutbuf: '0'
samples_per_second: samp_rate samples_per_second: samp_rate/2
type: complex type: complex
vlen: '1' vlen: '1'
states: states:
@ -144,7 +144,7 @@ blocks:
autoscale: 'False' autoscale: 'False'
average: '1.0' average: '1.0'
axislabels: 'True' axislabels: 'True'
bw: samp_rate bw: samp_rate/2
color1: '"blue"' color1: '"blue"'
color10: '"dark blue"' color10: '"dark blue"'
color2: '"red"' color2: '"red"'
@ -263,7 +263,7 @@ blocks:
name: '""' name: '""'
nconnections: '1' nconnections: '1'
size: '1024' size: '1024'
srate: samp_rate srate: samp_rate/2
stemplot: 'False' stemplot: 'False'
style1: '1' style1: '1'
style10: '1' style10: '1'
@ -320,7 +320,7 @@ blocks:
alpha8: '1.0' alpha8: '1.0'
alpha9: '1.0' alpha9: '1.0'
axislabels: 'True' axislabels: 'True'
bw: samp_rate bw: samp_rate/2
color1: '0' color1: '0'
color10: '0' color10: '0'
color2: '0' color2: '0'