Added test for frequency estimator

This commit is contained in:
Thomas Kolb 2023-05-17 22:26:46 +02:00
parent e42602633e
commit a7db93ab9e
2 changed files with 81 additions and 0 deletions

View file

@ -4,6 +4,7 @@ add_executable(
../src/layer1/correlator.h ../src/layer1/correlator.h
../src/layer1/freq_est.c ../src/layer1/freq_est.c
../src/layer1/freq_est.h ../src/layer1/freq_est.h
../src/utils.c
layer1/test_correlator.c layer1/test_correlator.c
) )
@ -44,3 +45,19 @@ target_link_libraries(
m m
liquid liquid
) )
#------------------------------------
add_executable(
test_freq_est
../src/layer1/freq_est.c
../src/layer1/freq_est.h
../src/utils.c
layer1/test_freq_est.c
)
target_link_libraries(
test_freq_est
m
liquid
)

View file

@ -0,0 +1,64 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#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)
{
#define N 1024
float complex s1[N];
float complex s2[N];
nco_crcf nco;
// ** Initialize **
nco = nco_crcf_create(LIQUID_NCO);
nco_crcf_set_frequency(nco, 0.05f);
nco_crcf_set_phase(nco, 1.37f);
// ** 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);
dump_array_cf(s1, N, 1.0f, "/tmp/freq_est_source.cpx");
dump_array_cf(s2, N, 1.0f, "/tmp/freq_est_mixed.cpx");
// ** Estimate frequency **
float final_phase;
float est_freq = freq_est_data_free(s2, 32, &final_phase);
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");
}