hamnet70/impl/test/layer1/test_freq_est.c

73 lines
1.3 KiB
C
Raw Normal View History

2023-05-17 22:26:46 +02:00
#include <stdio.h>
2024-03-30 22:05:02 +01:00
#include <time.h>
2023-05-17 22:26:46 +02:00
#include <liquid/liquid.h>
#include "layer1/freq_est.h"
#include "utils.h"
#define RESULT_CHECK(stmt) { \
result_t res = stmt; \
if(res != OK) { \
fprintf(stderr, "Error %d in %s:%d!\n", res, __FILE__, __LINE__); \
exit(1); \
} \
}
int main(void)
{
2024-03-30 22:05:02 +01:00
#define N 63
2023-05-17 22:26:46 +02:00
float complex s1[N];
float complex s2[N];
2024-03-30 22:05:02 +01:00
float complex s3[N];
2023-05-17 22:26:46 +02:00
nco_crcf nco;
2024-03-30 22:05:02 +01:00
channel_cccf chan;
2023-05-17 22:26:46 +02:00
// ** Initialize **
2024-03-30 22:05:02 +01:00
srand(time(NULL));
2023-05-17 22:26:46 +02:00
nco = nco_crcf_create(LIQUID_NCO);
2024-03-30 22:05:02 +01:00
nco_crcf_set_frequency(nco, -0.08f);
nco_crcf_set_phase(nco, -1.37f);
chan = channel_cccf_create();
channel_cccf_add_awgn(chan, -80, 5);
2023-05-17 22:26:46 +02:00
// ** Generate signal **
for(size_t i = 0; i < N; i++) {
s1[i] = 1.0f;
}
// ** Mix up **
nco_crcf_mix_block_up(nco, s1, s2, N);
2024-03-30 22:05:02 +01:00
channel_cccf_execute_block(chan, s2, N, s3);
2023-05-17 22:26:46 +02:00
dump_array_cf(s1, N, 1.0f, "/tmp/freq_est_source.cpx");
dump_array_cf(s2, N, 1.0f, "/tmp/freq_est_mixed.cpx");
2024-03-30 22:05:02 +01:00
dump_array_cf(s3, N, 1.0f, "/tmp/freq_est_channelized.cpx");
2023-05-17 22:26:46 +02:00
// ** Estimate frequency **
float final_phase;
2024-03-30 22:05:02 +01:00
float est_freq = freq_est_data_free(s3, N, &final_phase);
2023-05-17 22:26:46 +02:00
fprintf(stderr, "Estimated frequency: %.6f rad/sample\n", est_freq);
fprintf(stderr, "Final phase: %.6f rad\n", final_phase);
// ** Cleanup **
nco_crcf_destroy(nco);
fprintf(stderr, "Done.\n");
}