First working proof of concept

This commit is contained in:
Sebastian 2021-11-21 21:31:56 +01:00
commit 05df7a7c02
4 changed files with 905 additions and 0 deletions

96
costas.c Normal file
View File

@ -0,0 +1,96 @@
#include <liquid/liquid.h>
#include <math.h>
#include <complex.h>
#include <stdio.h>
const float SAMPLINGRATE = 100000.0;
const float EXPECTED_CENTER = 25000.0;
// 15khz lowpass
float LOWPASS_COEFFS[37] = {
-0.0013484122464433312,-0.0015524507034569979,-0.0012626417446881533,
1.106597777377648e-18,0.0025128561537712812,0.005701862741261721,
0.007837646640837193,0.006523041054606438,-3.595113471383589e-18,
-0.011250422336161137,-0.02350831776857376,-0.03022352233529091,
-0.02406340278685093,6.529514774129222e-18,0.04183189943432808,
0.09489838778972626,0.14748811721801758,0.18619666993618011,
0.20043739676475525,0.18619666993618011,0.14748811721801758,
0.09489838778972626,0.04183189943432808,6.529514774129222e-18,
-0.02406340278685093,-0.03022352233529091,-0.02350831776857376,
-0.011250422336161137,-3.595113471383589e-18,0.006523041054606438,
0.007837646640837193,0.005701862741261721,0.0025128561537712812,
1.106597777377648e-18,-0.0012626417446881533,-0.0015524507034569979,
-0.0013484122464433312
};
int main() {
// create the NCO object
nco_crcf downmix = nco_crcf_create(LIQUID_NCO);
nco_crcf_set_phase(downmix, 0.0f);
float freq = -(2 * M_PI * EXPECTED_CENTER) / SAMPLINGRATE;
nco_crcf_set_frequency(downmix, freq);
nco_crcf costas_vco = nco_crcf_create(LIQUID_VCO);
nco_crcf_set_phase(costas_vco, 0.0f);
nco_crcf_set_frequency(costas_vco, 0);
firfilt_rrrf r_fir = firfilt_rrrf_create(LOWPASS_COEFFS, 37);
firfilt_rrrf i_fir = firfilt_rrrf_create(LOWPASS_COEFFS, 37);
// output complex exponential
float complex x;
FILE* output = fopen("output.raw", "w");
FILE* input = fopen("wobble.raw", "r");
float vco_freq = 0.0;
float in[2];
while(fread(in, sizeof(float), 2, input) == 2) {
// increment internal phase
nco_crcf_step(downmix);
// compute complex exponential
nco_crcf_cexpf(downmix, &x);
float complex y;
nco_crcf_step(costas_vco);
nco_crcf_cexpf(costas_vco, &y);
float complex input_sample = (in[0] + I * in[1]);
float complex downmix_sample = input_sample * x;
float complex costas_sample = downmix_sample * y;
float complex output_sample = input_sample * y;
float r_sample = creal(costas_sample);
float i_sample = cimag(costas_sample);
firfilt_rrrf_push(r_fir, r_sample); // push input sample
firfilt_rrrf_execute(r_fir,&r_sample); // compute output
firfilt_rrrf_push(i_fir, i_sample); // push input sample
firfilt_rrrf_execute(i_fir,&i_sample); // compute output
float error = i_sample * r_sample;
vco_freq += error * 0.1;
nco_crcf_set_frequency(costas_vco, -vco_freq);
float buffer[] = {creal(output_sample), cimag(output_sample)};
fwrite(buffer, sizeof(float), 2, output);
}
// destroy nco object
nco_crcf_destroy(downmix);
nco_crcf_destroy(costas_vco);
firfilt_rrrf_destroy(r_fir);
firfilt_rrrf_destroy(i_fir);
fclose(output);
fclose(input);
return 0;
}

191
oszi.grc Normal file
View File

@ -0,0 +1,191 @@
options:
parameters:
author: sebastian
catch_exceptions: 'True'
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: ''
description: ''
gen_cmake: 'On'
gen_linking: dynamic
generate_options: qt_gui
hier_block_src_path: '.:'
id: oszi
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: prompt
sizing_mode: fixed
thread_safe_setters: ''
title: Not titled yet
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: samp_rate
id: variable
parameters:
comment: ''
value: '100000'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [184, 12]
rotation: 0
state: enabled
- name: blocks_file_source_0
id: blocks_file_source
parameters:
affinity: ''
alias: ''
begin_tag: pmt.PMT_NIL
comment: ''
file: /home/sebastian/projects/QO100-trx/prototypes/output.raw
length: '0'
maxoutbuf: '0'
minoutbuf: '0'
offset: '0'
repeat: 'False'
type: float
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [96, 180.0]
rotation: 0
state: true
- name: blocks_throttle_0
id: blocks_throttle
parameters:
affinity: ''
alias: ''
comment: ''
ignoretag: 'True'
maxoutbuf: '0'
minoutbuf: '0'
samples_per_second: samp_rate
type: float
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [328, 196.0]
rotation: 0
state: true
- name: qtgui_time_sink_x_0
id: qtgui_time_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
axislabels: 'True'
color1: blue
color10: dark blue
color2: red
color3: green
color4: black
color5: cyan
color6: magenta
color7: yellow
color8: dark red
color9: dark green
comment: ''
ctrlpanel: 'False'
entags: 'True'
grid: 'False'
gui_hint: ''
label1: Signal 1
label10: Signal 10
label2: Signal 2
label3: Signal 3
label4: Signal 4
label5: Signal 5
label6: Signal 6
label7: Signal 7
label8: Signal 8
label9: Signal 9
legend: 'True'
marker1: '-1'
marker10: '-1'
marker2: '-1'
marker3: '-1'
marker4: '-1'
marker5: '-1'
marker6: '-1'
marker7: '-1'
marker8: '-1'
marker9: '-1'
name: '""'
nconnections: '1'
size: '1024'
srate: samp_rate
stemplot: 'False'
style1: '1'
style10: '1'
style2: '1'
style3: '1'
style4: '1'
style5: '1'
style6: '1'
style7: '1'
style8: '1'
style9: '1'
tr_chan: '0'
tr_delay: '0'
tr_level: '0.0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_slope: qtgui.TRIG_SLOPE_POS
tr_tag: '""'
type: float
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
ylabel: Amplitude
ymax: '1'
ymin: '-1'
yunit: '""'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [544, 172.0]
rotation: 0
state: true
connections:
- [blocks_file_source_0, '0', blocks_throttle_0, '0']
- [blocks_throttle_0, '0', qtgui_time_sink_x_0, '0']
metadata:
file_format: 1

341
view_waterfall.grc Normal file
View File

@ -0,0 +1,341 @@
options:
parameters:
author: ''
catch_exceptions: 'True'
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: ''
description: ''
gen_cmake: 'On'
gen_linking: dynamic
generate_options: qt_gui
hier_block_src_path: '.:'
id: view_waterfall
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: prompt
sizing_mode: fixed
thread_safe_setters: ''
title: Not titled yet
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: samp_rate
id: variable
parameters:
comment: ''
value: '100000'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [184, 12]
rotation: 0
state: enabled
- name: blocks_file_source_0
id: blocks_file_source
parameters:
affinity: ''
alias: ''
begin_tag: pmt.PMT_NIL
comment: ''
file: /home/sebastian/projects/QO100-trx/prototypes/output.raw
length: '0'
maxoutbuf: '0'
minoutbuf: '0'
offset: '0'
repeat: 'False'
type: complex
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [184, 212.0]
rotation: 0
state: true
- name: blocks_file_source_0_0
id: blocks_file_source
parameters:
affinity: ''
alias: ''
begin_tag: pmt.PMT_NIL
comment: ''
file: /home/sebastian/projects/QO100-trx/prototypes/wobble.raw
length: '0'
maxoutbuf: '0'
minoutbuf: '0'
offset: '0'
repeat: 'False'
type: complex
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [184, 92.0]
rotation: 0
state: true
- name: blocks_throttle_0
id: blocks_throttle
parameters:
affinity: ''
alias: ''
comment: ''
ignoretag: 'True'
maxoutbuf: '0'
minoutbuf: '0'
samples_per_second: samp_rate
type: complex
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [496, 244.0]
rotation: 0
state: true
- name: blocks_throttle_1
id: blocks_throttle
parameters:
affinity: ''
alias: ''
comment: ''
ignoretag: 'True'
maxoutbuf: '0'
minoutbuf: '0'
samples_per_second: samp_rate
type: complex
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [400, 124.0]
rotation: 0
state: true
- name: qtgui_freq_sink_x_0
id: qtgui_freq_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
autoscale: 'False'
average: '1.0'
axislabels: 'True'
bw: samp_rate
color1: '"blue"'
color10: '"dark blue"'
color2: '"red"'
color3: '"green"'
color4: '"black"'
color5: '"cyan"'
color6: '"magenta"'
color7: '"yellow"'
color8: '"dark red"'
color9: '"dark green"'
comment: ''
ctrlpanel: 'False'
fc: '0'
fftsize: '4096'
freqhalf: 'True'
grid: 'False'
gui_hint: ''
label: Relative Gain
label1: ''
label10: ''''''
label2: ''''''
label3: ''''''
label4: ''''''
label5: ''''''
label6: ''''''
label7: ''''''
label8: ''''''
label9: ''''''
legend: 'True'
maxoutbuf: '0'
minoutbuf: '0'
name: '""'
nconnections: '1'
norm_window: 'False'
showports: 'False'
tr_chan: '0'
tr_level: '0.0'
tr_mode: qtgui.TRIG_MODE_FREE
tr_tag: '""'
type: complex
units: dB
update_time: '0.10'
width1: '1'
width10: '1'
width2: '1'
width3: '1'
width4: '1'
width5: '1'
width6: '1'
width7: '1'
width8: '1'
width9: '1'
wintype: window.WIN_BLACKMAN_hARRIS
ymax: '10'
ymin: '-140'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [712, 156.0]
rotation: 0
state: true
- name: qtgui_waterfall_sink_x_0
id: qtgui_waterfall_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
axislabels: 'True'
bw: samp_rate
color1: '0'
color10: '0'
color2: '0'
color3: '0'
color4: '0'
color5: '0'
color6: '0'
color7: '0'
color8: '0'
color9: '0'
comment: ''
fc: '0'
fftsize: '4096'
freqhalf: 'True'
grid: 'False'
gui_hint: ''
int_max: '10'
int_min: '-140'
label1: ''
label10: ''
label2: ''
label3: ''
label4: ''
label5: ''
label6: ''
label7: ''
label8: ''
label9: ''
legend: 'True'
maxoutbuf: '0'
minoutbuf: '0'
name: '""'
nconnections: '1'
showports: 'False'
type: complex
update_time: '0.10'
wintype: window.WIN_BLACKMAN_hARRIS
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [704, 348.0]
rotation: 0
state: true
- name: qtgui_waterfall_sink_x_0_0
id: qtgui_waterfall_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
axislabels: 'True'
bw: samp_rate
color1: '0'
color10: '0'
color2: '0'
color3: '0'
color4: '0'
color5: '0'
color6: '0'
color7: '0'
color8: '0'
color9: '0'
comment: ''
fc: '0'
fftsize: '4096'
freqhalf: 'True'
grid: 'False'
gui_hint: ''
int_max: '10'
int_min: '-140'
label1: ''
label10: ''
label2: ''
label3: ''
label4: ''
label5: ''
label6: ''
label7: ''
label8: ''
label9: ''
legend: 'True'
maxoutbuf: '0'
minoutbuf: '0'
name: '""'
nconnections: '1'
showports: 'False'
type: complex
update_time: '0.10'
wintype: window.WIN_BLACKMAN_hARRIS
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [696, 60.0]
rotation: 0
state: true
connections:
- [blocks_file_source_0, '0', blocks_throttle_0, '0']
- [blocks_file_source_0_0, '0', blocks_throttle_1, '0']
- [blocks_throttle_0, '0', qtgui_freq_sink_x_0, '0']
- [blocks_throttle_0, '0', qtgui_waterfall_sink_x_0, '0']
- [blocks_throttle_1, '0', qtgui_waterfall_sink_x_0_0, '0']
metadata:
file_format: 1

277
wobble.grc Normal file
View File

@ -0,0 +1,277 @@
options:
parameters:
author: sebastian
catch_exceptions: 'True'
category: '[GRC Hier Blocks]'
cmake_opt: ''
comment: ''
copyright: ''
description: ''
gen_cmake: 'On'
gen_linking: dynamic
generate_options: qt_gui
hier_block_src_path: '.:'
id: wobble
max_nouts: '0'
output_language: python
placement: (0,0)
qt_qss_theme: ''
realtime_scheduling: ''
run: 'True'
run_command: '{python} -u {filename}'
run_options: prompt
sizing_mode: fixed
thread_safe_setters: ''
title: Not titled yet
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [8, 8]
rotation: 0
state: enabled
blocks:
- name: samp_rate
id: variable
parameters:
comment: ''
value: '100000'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [184, 12]
rotation: 0
state: enabled
- name: analog_sig_source_x_0
id: analog_sig_source_x
parameters:
affinity: ''
alias: ''
amp: '0.5'
comment: ''
freq: 25000-2500
maxoutbuf: '0'
minoutbuf: '0'
offset: '0'
phase: '0'
samp_rate: samp_rate
type: complex
waveform: analog.GR_COS_WAVE
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [368, 92.0]
rotation: 0
state: enabled
- name: analog_sig_source_x_1
id: analog_sig_source_x
parameters:
affinity: ''
alias: ''
amp: '0.5'
comment: ''
freq: 25000+2500
maxoutbuf: '0'
minoutbuf: '0'
offset: '0'
phase: '0'
samp_rate: samp_rate
type: complex
waveform: analog.GR_COS_WAVE
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [368, 236.0]
rotation: 0
state: true
- name: analog_sig_source_x_1_0
id: analog_sig_source_x
parameters:
affinity: ''
alias: ''
amp: '1'
comment: ''
freq: '0.05'
maxoutbuf: '0'
minoutbuf: '0'
offset: '-0.5'
phase: '0'
samp_rate: samp_rate
type: float
waveform: analog.GR_TRI_WAVE
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [368, 380.0]
rotation: 0
state: true
- name: blocks_add_xx_0
id: blocks_add_xx
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
num_inputs: '2'
type: complex
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [672, 200.0]
rotation: 0
state: enabled
- name: blocks_file_sink_0
id: blocks_file_sink
parameters:
affinity: ''
alias: ''
append: 'False'
comment: ''
file: /home/sebastian/projects/QO100-trx/prototypes/wobble.raw
type: complex
unbuffered: 'False'
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1344, 340.0]
rotation: 0
state: true
- name: blocks_multiply_xx_0
id: blocks_multiply_xx
parameters:
affinity: ''
alias: ''
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
num_inputs: '2'
type: complex
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [880, 280.0]
rotation: 0
state: true
- name: blocks_throttle_0
id: blocks_throttle
parameters:
affinity: ''
alias: ''
comment: ''
ignoretag: 'True'
maxoutbuf: '0'
minoutbuf: '0'
samples_per_second: samp_rate
type: complex
vlen: '1'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1152, 228.0]
rotation: 0
state: true
- name: blocks_vco_c_0
id: blocks_vco_c
parameters:
affinity: ''
alias: ''
amplitude: '1.0'
comment: ''
maxoutbuf: '0'
minoutbuf: '0'
samp_rate: samp_rate
sensitivity: '60000'
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [616, 404.0]
rotation: 0
state: true
- name: qtgui_waterfall_sink_x_0
id: qtgui_waterfall_sink_x
parameters:
affinity: ''
alias: ''
alpha1: '1.0'
alpha10: '1.0'
alpha2: '1.0'
alpha3: '1.0'
alpha4: '1.0'
alpha5: '1.0'
alpha6: '1.0'
alpha7: '1.0'
alpha8: '1.0'
alpha9: '1.0'
axislabels: 'True'
bw: samp_rate
color1: '0'
color10: '0'
color2: '0'
color3: '0'
color4: '0'
color5: '0'
color6: '0'
color7: '0'
color8: '0'
color9: '0'
comment: ''
fc: '0'
fftsize: '4096'
freqhalf: 'True'
grid: 'False'
gui_hint: ''
int_max: '10'
int_min: '-140'
label1: ''
label10: ''
label2: ''
label3: ''
label4: ''
label5: ''
label6: ''
label7: ''
label8: ''
label9: ''
legend: 'True'
maxoutbuf: '0'
minoutbuf: '0'
name: '""'
nconnections: '1'
showports: 'False'
type: complex
update_time: '0.10'
wintype: window.WIN_BLACKMAN_hARRIS
states:
bus_sink: false
bus_source: false
bus_structure: null
coordinate: [1352, 212.0]
rotation: 0
state: true
connections:
- [analog_sig_source_x_0, '0', blocks_add_xx_0, '0']
- [analog_sig_source_x_1, '0', blocks_add_xx_0, '1']
- [analog_sig_source_x_1_0, '0', blocks_vco_c_0, '0']
- [blocks_add_xx_0, '0', blocks_multiply_xx_0, '0']
- [blocks_multiply_xx_0, '0', blocks_throttle_0, '0']
- [blocks_throttle_0, '0', blocks_file_sink_0, '0']
- [blocks_throttle_0, '0', qtgui_waterfall_sink_x_0, '0']
- [blocks_vco_c_0, '0', blocks_multiply_xx_0, '1']
metadata:
file_format: 1