Add a simple interleaver implementation (not used yet)

This commit is contained in:
Thomas Kolb 2024-07-21 17:23:15 +02:00
parent 04f29b94bf
commit c9916c08da
4 changed files with 90 additions and 0 deletions

View file

@ -0,0 +1,39 @@
#include "interleaver.h"
#include "config.h"
void interleaver_interleave(const float complex *in, float complex *out, size_t n)
{
size_t interleaved_base = 0;
size_t interleaved_index = 0;
/* example for this algorithm with INTERLEAVE_DISTANCE = 5:
* original: abcdefghijklmn
* output: adgjmbehkncfil
*/
for(size_t orig_index = 0; orig_index < n; orig_index++) {
out[interleaved_index] = in[orig_index];
interleaved_index += INTERLEAVE_DISTANCE;
if(interleaved_index >= n) {
interleaved_base++;
interleaved_index = interleaved_base;
}
}
}
void interleaver_deinterleave(const float complex *in, float complex *out, size_t n)
{
size_t interleaved_base = 0;
size_t interleaved_index = 0;
for(size_t orig_index = 0; orig_index < n; orig_index++) {
out[orig_index] = in[interleaved_index];
interleaved_index += INTERLEAVE_DISTANCE;
if(interleaved_index >= n) {
interleaved_base++;
interleaved_index = interleaved_base;
}
}
}

View file

@ -0,0 +1,11 @@
#ifndef INTERLEAVER_H
#define INTERLEAVER_H
#include <complex.h>
#include <stddef.h>
void interleaver_interleave(const float complex *in, float complex *out, size_t n);
void interleaver_deinterleave(const float complex *in, float complex *out, size_t n);
#endif // INTERLEAVER_H

View file

@ -201,3 +201,17 @@ add_executable(
target_link_libraries(
test_packet_queue
)
#------------------------------------
add_executable(
test_interleaver
../src/layer1/interleaver.c
../src/layer1/interleaver.h
../src/config.h
test_interleaver.c
)
target_link_libraries(
test_interleaver
)

View file

@ -0,0 +1,26 @@
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <layer1/interleaver.h>
int main(void)
{
const size_t N = 100;
float complex orig[N];
float complex interleaved[N];
float complex deinterleaved[N];
for(size_t i = 0; i < N; i++) {
orig[i] = (float complex)i;
}
interleaver_interleave(orig, interleaved, N);
interleaver_deinterleave(interleaved, deinterleaved, N);
for(size_t i = 0; i < N; i++) {
printf("%5zu %5.1f %5.1f %5.1f\n", i, crealf(orig[i]), crealf(interleaved[i]), crealf(deinterleaved[i]));
assert(orig[i] == deinterleaved[i]);
}
}