Finish DSSS demodulation stage 1
This commit is contained in:
parent
e4693349cf
commit
55ebbcbdbc
5 changed files with 167 additions and 58 deletions
|
|
@ -13,11 +13,11 @@
|
|||
#include "dsss_demod.h"
|
||||
|
||||
void print_usage() {
|
||||
fprintf(stderr, "Usage: dsss_demod_test [test_data.bin]\n");
|
||||
fprintf(stderr, "Usage: dsss_demod_test [test_data.bin] [optional recording channel number]\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 2) {
|
||||
if (argc != 2 && argc != 3) {
|
||||
fprintf(stderr, "Error: Invalid arguments.\n");
|
||||
print_usage();
|
||||
return 1;
|
||||
|
|
@ -46,7 +46,18 @@ int main(int argc, char **argv) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Reading %zd samples test data...", st.st_size/sizeof(float));
|
||||
int record_channel = -1;
|
||||
if (argc == 3) {
|
||||
char *endptr;
|
||||
record_channel = strtoul(argv[2], &endptr, 10);
|
||||
if (!endptr || *endptr != '\0') {
|
||||
fprintf(stderr, "Invalid channel number \"%s\"\n", argv[2]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (record_channel != -1)
|
||||
fprintf(stderr, "Reading %zd samples test data...", st.st_size/sizeof(float));
|
||||
size_t nread = 0;
|
||||
while (nread < st.st_size) {
|
||||
ssize_t rc = read(fd, buf, st.st_size - nread);
|
||||
|
|
@ -66,18 +77,20 @@ int main(int argc, char **argv) {
|
|||
|
||||
nread += rc;
|
||||
}
|
||||
fprintf(stderr, " done.\n");
|
||||
if (record_channel != -1)
|
||||
fprintf(stderr, " done.\n");
|
||||
|
||||
const size_t n_samples = st.st_size / sizeof(float);
|
||||
float *buf_f = (float *)buf;
|
||||
|
||||
fprintf(stderr, "Starting simulation.\n");
|
||||
if (record_channel != -1)
|
||||
fprintf(stderr, "Starting simulation.\n");
|
||||
|
||||
struct dsss_demod_state demod;
|
||||
memset(&demod, 0, sizeof(demod));
|
||||
for (size_t i=0; i<n_samples; i++) {
|
||||
//fprintf(stderr, "Iteration %zd/%zd\n", i, n_samples);
|
||||
dsss_demod_step(&demod, buf_f[i], i);
|
||||
dsss_demod_step(&demod, buf_f[i], i, record_channel);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue