Skip to content

Commit

Permalink
Merge branch 'master' into bind-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaeddert committed Mar 7, 2024
2 parents 47c6973 + bbfa588 commit 8f9f8b1
Show file tree
Hide file tree
Showing 87 changed files with 1,419 additions and 795 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ jobs:
- name: make
run: make -j 2

- name: make doc-check
run: make doc-check
- name: make check-doc
run: make check-doc

- name: make check
run: make -j 2 check
Expand Down
6 changes: 3 additions & 3 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ compile:
stage: build
script:
- ./bootstrap.sh
- ./configure --enable-strict
- ./configure
- make -j4
artifacts: # save output objects for test stages
paths: [makefile, configure, config.h, config.h.in]
Expand Down Expand Up @@ -44,10 +44,10 @@ bench:
paths: [benchmark.json]

# compile and run documenation checks (e.g. example code in README.md)
doc-check:
check-doc:
stage: test
script:
- make doc-check
- make check-doc

# compile and run all example programs, timing how long each takes to run
examples:
Expand Down
25 changes: 14 additions & 11 deletions bench/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ typedef void(benchmark_function_t) (

// define benchmark_t
typedef struct {
unsigned int id;
benchmark_function_t * api;
const char* name;
unsigned int name_len;
unsigned int num_trials;
float extime;
float rate;
float cycles_per_trial;
unsigned int id; // identification of benchmark
benchmark_function_t * api; // function interface
const char * name; // name of function
unsigned int name_len;
unsigned int num_trials;
float extime;
float rate;
float cycles_per_trial;//
unsigned int num_attempts; // number of attempts to reach target time
} benchmark_t;

// define package_t
Expand Down Expand Up @@ -292,12 +293,13 @@ int main(int argc, char *argv[])
fprintf(fid," \"num_trials\" : %lu,\n", num_base_trials);
fprintf(fid," \"benchmarks\" : [\n");
for (i=0; i<NUM_AUTOSCRIPTS; i++) {
fprintf(fid," {\"id\":%5u, \"trials\":%12u, \"extime\":%12.4e, \"rate\":%12.4e, \"cycles_per_trial\":%12.4e, \"name\":\"%s\"}%s\n",
fprintf(fid," {\"id\":%5u, \"trials\":%12u, \"extime\":%12.4e, \"rate\":%12.4e, \"cycles_per_trial\":%12.4e, \"attempts\":%2u, \"name\":\"%s\"}%s\n",
scripts[i].id,
scripts[i].num_trials,
scripts[i].extime,
scripts[i].rate,
scripts[i].cycles_per_trial,
scripts[i].num_attempts,
scripts[i].name,
i==NUM_AUTOSCRIPTS-1 ? "" : ",");
}
Expand Down Expand Up @@ -394,6 +396,7 @@ void execute_benchmark(benchmark_t* _benchmark, int _verbose)
} while (1);

_benchmark->num_trials = num_trials;
_benchmark->num_attempts = num_attempts;
_benchmark->rate = _benchmark->extime==0 ? 0 : (float)(_benchmark->num_trials) / _benchmark->extime;
_benchmark->cycles_per_trial = _benchmark->extime==0 ? 0 : cpu_clock / (_benchmark->rate);

Expand Down Expand Up @@ -448,8 +451,8 @@ void print_benchmark_results(benchmark_t* _b)
float cycles_format = _b->cycles_per_trial;
char cycles_units = convert_units(&cycles_format);

printf(" %-3u: %-30s: %6.2f %c trials / %6.2f %cs (%6.2f %c t/s, %6.2f %c c/t)\n",
_b->id, _b->name,
printf(" %-3u: [%2u] %-30s: %6.2f %c trials / %6.2f %cs (%6.2f %c t/s, %6.2f %c c/t)\n",
_b->id, _b->num_attempts, _b->name,
trials_format, trials_units,
extime_format, extime_units,
rate_format, rate_units,
Expand Down
78 changes: 78 additions & 0 deletions examples/flexframesync_debug_example.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// This example exports the output constellation to file for debugging.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#include <getopt.h>
#include <assert.h>

#include "liquid.h"

// flexframesync callback function
static int callback(unsigned char * _header,
int _header_valid,
unsigned char * _payload,
unsigned int _payload_len,
int _payload_valid,
framesyncstats_s _stats,
void * _userdata)
{
const char * filename = (const char*)_userdata;
FILE * fid = fopen(filename,"w");
if (fid == NULL) {
printf("could not open '%s' for writing\n", filename);
return 0;
}
unsigned int i;
for (i=0; i<_stats.num_framesyms; i++)
fprintf(fid,"%12.8f %12.8f\n", crealf(_stats.framesyms[i]), cimagf(_stats.framesyms[i]));
fclose(fid);
return 0;
}

int main(int argc, char *argv[])
{
// options
modulation_scheme ms = LIQUID_MODEM_QPSK; // mod. scheme
crc_scheme check = LIQUID_CRC_32; // data validity check
fec_scheme fec0 = LIQUID_FEC_NONE; // fec (inner)
fec_scheme fec1 = LIQUID_FEC_NONE; // fec (outer)
unsigned int payload_len = 480; // payload length
const char * filename = "flexframesync_debug_example.dat";

// create flexframegen object
flexframegenprops_s fgprops;
flexframegenprops_init_default(&fgprops);
fgprops.mod_scheme = ms;
fgprops.check = check;
fgprops.fec0 = fec0;
fgprops.fec1 = fec1;
flexframegen fg = flexframegen_create(&fgprops);

// create flexframesync object
flexframesync fs = flexframesync_create(callback,(void*)filename);

// assemble the frame (NULL pointers for default values)
flexframegen_assemble(fg, NULL, NULL, payload_len);

// generate the frame in blocks
unsigned int buf_len = 256;
float complex buf[buf_len];

int frame_complete = 0;
while (!frame_complete) {
// write samples to buffer
frame_complete = flexframegen_write_samples(fg, buf, buf_len);

// run through frame synchronizer
flexframesync_execute(fs, buf, buf_len);
}

// destroy allocated objects
flexframegen_destroy(fg);
flexframesync_destroy(fs);
return 0;
}

7 changes: 1 addition & 6 deletions examples/freqmodem_example.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
// file: freqmodem_test.c
//
// Tests simple modulation/demodulation without noise or phase
// offset
//

// Tests simple frequency modulation/demodulation
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion examples/nco_pll_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ int main(int argc, char*argv[])
fprintf(fid,"e(%4u) = %12.4e;\n", i+1, phase_error[i]);
}
fprintf(fid,"t=0:(n-1);\n");
fprintf(fid,"figure;\n");
fprintf(fid,"figure('color','white','position',[100 100 1200 600]);\n");
fprintf(fid,"subplot(3,1,1);\n");
fprintf(fid," hold on;\n");
fprintf(fid," plot(t,real(x),'Color',[1 1 1]*0.8);\n");
Expand Down
52 changes: 25 additions & 27 deletions examples/nco_pll_modem_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,29 @@
void usage()
{
printf("nco_pll_modem_example [options]\n");
printf(" u/h : print usage\n");
printf(" s : signal-to-noise ratio, default: 30dB\n");
printf(" b : pll bandwidth, default: 20e-3\n");
printf(" n : number of symbols, default: 256\n");
printf(" P : phase offset (radians), default: pi/10 ~ 0.3146\n");
printf(" F : frequency offset (radians), default: 0.001\n");
printf(" m : modulation scheme, default: qpsk\n");
printf(" -h : print help\n");
printf(" -s : signal-to-noise ratio, default: 30dB\n");
printf(" -b : pll bandwidth, default: 0.002\n");
printf(" -n : number of symbols, default: 1200\n");
printf(" -P : phase offset (radians), default: pi/10 ~ 0.3146\n");
printf(" -F : frequency offset (radians), default: 0.1\n");
printf(" -m : modulation scheme, default: qpsk\n");
liquid_print_modulation_schemes();
}

int main(int argc, char*argv[]) {
srand( time(NULL) );
// parameters
float phase_offset = M_PI/10;
float frequency_offset = 0.001f;
float frequency_offset = 0.10f;
float SNRdB = 30.0f;
float pll_bandwidth = 0.02f;
float pll_bandwidth = 0.002f;
modulation_scheme ms = LIQUID_MODEM_QPSK;
unsigned int n=256; // number of iterations
unsigned int n=1200; // number of iterations

int dopt;
while ((dopt = getopt(argc,argv,"uhs:b:n:P:F:m:")) != EOF) {
while ((dopt = getopt(argc,argv,"hs:b:n:P:F:m:")) != EOF) {
switch (dopt) {
case 'u':
case 'h': usage(); return 0;
case 's': SNRdB = atof(optarg); break;
case 'b': pll_bandwidth = atof(optarg); break;
Expand Down Expand Up @@ -129,7 +128,7 @@ int main(int argc, char*argv[]) {
i+1, crealf(v), cimagf(v));

if ((i+1)%d == 0 || i==n-1) {
printf(" %4u: e_hat : %6.3f, phase error : %6.3f, freq error : %6.3f\n",
printf(" %4u: e_hat : %6.3f, phase error : %6.3f, freq error : %12.9f\n",
i+1, // iteration
phase_error, // estimated phase error
nco_crcf_get_phase(nco_tx) - nco_crcf_get_phase(nco_rx),// true phase error
Expand All @@ -147,29 +146,28 @@ int main(int argc, char*argv[]) {
nco_crcf_step(nco_rx);
}

fprintf(fid, "figure;\n");
fprintf(fid, "figure('color','white','position',[100 100 1200 320]);\n");
fprintf(fid, "n = length(phase_error);\n");
fprintf(fid, "t = 0:(n-1);\n");
fprintf(fid, "subplot(2,1,1);\n");
fprintf(fid, "subplot(2,3,1:2);\n");
fprintf(fid, " plot(t,phase_error,'LineWidth',2,'Color',[0 0.25 0.5]);\n");
fprintf(fid, " xlabel('Symbol Index');\n");
fprintf(fid, " ylabel('Phase Error [radians]');\n");
fprintf(fid, " grid on;\n");
fprintf(fid, "subplot(2,1,2);\n");
fprintf(fid, "subplot(2,3,4:5);\n");
fprintf(fid, " plot(t,freq_error,'LineWidth',2,'Color',[0 0.25 0.5]);\n");
fprintf(fid, " xlabel('Symbol Index');\n");
fprintf(fid, " ylabel('Frequency Error [radians/sample]');\n");
fprintf(fid, " ylabel('Freq. Error [radians/sample]');\n");
fprintf(fid, " grid on;\n");

fprintf(fid, "t0 = round(0.25*length(r));\n");
fprintf(fid, "figure;\n");
fprintf(fid, "plot(r(1:t0),'x','Color',[0.6 0.6 0.6],r(t0:end),'x','Color',[0 0.25 0.5]);\n");
fprintf(fid, "grid on;\n");
fprintf(fid, "axis([-1.5 1.5 -1.5 1.5]);\n");
fprintf(fid, "axis('square');\n");
fprintf(fid, "xlabel('In-Phase');\n");
fprintf(fid, "ylabel('Quadrature');\n");
fprintf(fid, "legend(['first 25%%'],['last 75%%']);\n");
fprintf(fid, "subplot(2,3,[3,6]);\n");
fprintf(fid, " t0 = round(0.5*length(r));\n");
fprintf(fid, " plot(r(1:t0),'.','Color',[1 1 1]*0.7,r(t0:end),'.','Color',[0 0.25 0.5]);\n");
fprintf(fid, " grid on;\n");
fprintf(fid, " axis([-1 1 -1 1]*1.5);\n");
fprintf(fid, " axis('square');\n");
fprintf(fid, " xlabel('In-Phase');\n");
fprintf(fid, " ylabel('Quadrature');\n");
fprintf(fid, " legend(['first 50%%'],['last 50%%']);\n");
fclose(fid);

printf("results written to %s.\n",OUTPUT_FILENAME);
Expand Down
Loading

0 comments on commit 8f9f8b1

Please sign in to comment.