Add a simple interleaver implementation (not used yet)
This commit is contained in:
parent
04f29b94bf
commit
c9916c08da
39
impl/src/layer1/interleaver.c
Normal file
39
impl/src/layer1/interleaver.c
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
impl/src/layer1/interleaver.h
Normal file
11
impl/src/layer1/interleaver.h
Normal 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
|
|
@ -201,3 +201,17 @@ add_executable(
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
test_packet_queue
|
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
|
||||||
|
)
|
||||||
|
|
26
impl/test/test_interleaver.c
Normal file
26
impl/test/test_interleaver.c
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue