test/freq_est: add channel simulation

This commit is contained in:
Thomas Kolb 2024-03-30 22:05:02 +01:00
parent 66c88bf889
commit bbf7bcf2f0

View file

@ -1,8 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <time.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <liquid/liquid.h> #include <liquid/liquid.h>
@ -21,18 +18,26 @@
int main(void) int main(void)
{ {
#define N 1024 #define N 63
float complex s1[N]; float complex s1[N];
float complex s2[N]; float complex s2[N];
float complex s3[N];
nco_crcf nco; nco_crcf nco;
channel_cccf chan;
// ** Initialize ** // ** Initialize **
srand(time(NULL));
nco = nco_crcf_create(LIQUID_NCO); nco = nco_crcf_create(LIQUID_NCO);
nco_crcf_set_frequency(nco, 0.05f); nco_crcf_set_frequency(nco, -0.08f);
nco_crcf_set_phase(nco, 1.37f); nco_crcf_set_phase(nco, -1.37f);
chan = channel_cccf_create();
channel_cccf_add_awgn(chan, -80, 5);
// ** Generate signal ** // ** Generate signal **
@ -44,14 +49,17 @@ int main(void)
nco_crcf_mix_block_up(nco, s1, s2, N); nco_crcf_mix_block_up(nco, s1, s2, N);
channel_cccf_execute_block(chan, s2, N, s3);
dump_array_cf(s1, N, 1.0f, "/tmp/freq_est_source.cpx"); dump_array_cf(s1, N, 1.0f, "/tmp/freq_est_source.cpx");
dump_array_cf(s2, N, 1.0f, "/tmp/freq_est_mixed.cpx"); dump_array_cf(s2, N, 1.0f, "/tmp/freq_est_mixed.cpx");
dump_array_cf(s3, N, 1.0f, "/tmp/freq_est_channelized.cpx");
// ** Estimate frequency ** // ** Estimate frequency **
float final_phase; float final_phase;
float est_freq = freq_est_data_free(s2, 32, &final_phase); float est_freq = freq_est_data_free(s3, N, &final_phase);
fprintf(stderr, "Estimated frequency: %.6f rad/sample\n", est_freq); fprintf(stderr, "Estimated frequency: %.6f rad/sample\n", est_freq);
fprintf(stderr, "Final phase: %.6f rad\n", final_phase); fprintf(stderr, "Final phase: %.6f rad\n", final_phase);