Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1c83de1
update(downsampling): do_cic() with fixedpoints intern
ohrenschmaus Jun 24, 2026
174c79f
update(downsampling): change downsampling_test.py
ohrenschmaus Jun 24, 2026
91316c6
fix(downsampling): match tests to functions
ohrenschmaus Jun 24, 2026
4d5a3e3
feat(downsampling): add downsampling.c/h
ohrenschmaus Jun 25, 2026
b9fbae2
test(downsampling): add downsampling_test.c
ohrenschmaus Jun 26, 2026
cdb8d74
feat(adc): add adc.c/h
ohrenschmaus Jun 28, 2026
9a5732e
feat(adc): add adc_test.c
ohrenschmaus Jun 28, 2026
eddf5bf
feat(downsampling): add c-impl in /downsampling/c_code/
ohrenschmaus Jul 4, 2026
953c7bc
test(downsampling): add downsampling_test.c
ohrenschmaus Jul 4, 2026
59639be
update(downsampling): update downsampling.c/h
ohrenschmaus Jul 4, 2026
d567eb3
test(downsampling): update downsampling_test.c
ohrenschmaus Jul 4, 2026
e08cbae
merge(main): resolve conflict in downsampling_test.py
ohrenschmaus Jul 4, 2026
ebab63b
Fix test checks for project path validation
ohrenschmaus Jul 4, 2026
113d9a4
test(downsampling): update downsampling_test.py
ohrenschmaus Jul 4, 2026
5b6bd63
test(downsampling): update downsampling_test.py
ohrenschmaus Jul 4, 2026
68cf64b
fix(downsampling): align polyphase_order_two with corrected Python impl
ohrenschmaus Jul 4, 2026
668761f
feat(downsampling): add do_simple
ohrenschmaus Jul 9, 2026
44da286
update(downsampling): update src/c_compile/__init__.py
ohrenschmaus Jul 9, 2026
a72cb09
update(downsampling): change uint32_t to size_t in subsampling_template
ohrenschmaus Jul 9, 2026
0a5d431
update(downsampling): remove unused function
ohrenschmaus Jul 9, 2026
f256210
update(downsampling): update simple.py
ohrenschmaus Jul 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#ifndef DOWNSAMPLING_SIMPLE_TEMPLATE_H
#define DOWNSAMPLING_SIMPLE_TEMPLATE_H
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>

typedef struct {
uint16_t tap_start;
uint16_t tap_length;
void *output;
void *taps;
} DoSimpleTaps;

#ifndef DOWNSAMPLING_SIMPLE_OUTPUT_LENGTH
#define DOWNSAMPLING_SIMPLE_OUTPUT_LENGTH(id, factor) \
size_t get_downsampling_simple_output_length_ ## id(size_t input_length) { \
return (input_length / (size_t)factor); \
}
#endif // DOWNSAMPLING_SIMPLE_OUTPUT_LENGTH

#ifndef DEF_DOWNSAMPLING_SIMPLE
#define DEF_DOWNSAMPLING_SIMPLE(id, input_type) \
bool calc_next_datum_do_simple_ ## id(input_type data, DoSimpleTaps *tap_memory) { \
uint16_t do_tap_start = tap_memory->tap_start; \
uint16_t do_tap_length = tap_memory->tap_length; \
input_type *do_output = (input_type *) tap_memory->output; \
input_type *do_taps = (input_type *) tap_memory->taps; \
do_taps[do_tap_start] = data; \
\
input_type sum = 0; \
for (int16_t pos_tap = 0; pos_tap < do_tap_length; pos_tap++) { \
sum += do_taps[pos_tap]; \
} \
do_tap_start++; \
tap_memory->tap_start = do_tap_start; \
if(do_tap_start >= do_tap_length) { \
tap_memory->tap_start = 0; \
*do_output = (input_type) (sum / do_tap_length); \
return true; \
} \
return false; \
}
#endif // DEF_DOWNSAMPLING_SIMPLE

#ifndef DEF_NEW_DO_SIMPLE_TAP_IMPL
#define DEF_NEW_DO_SIMPLE_TAP_IMPL(id, input_type, dsr) \
static DEF_DOWNSAMPLING_SIMPLE(id, input_type) \
bool calc_do_simple_ ## id(input_type data, input_type *out) { \
static input_type do_taps[dsr] = {0}; \
static input_type do_output_val = 0; \
static DoSimpleTaps settings = { \
.tap_length = dsr, \
.tap_start = 0, \
.taps = do_taps, \
.output = &do_output_val, \
}; \
if (calc_next_datum_do_simple_ ## id(data, &(settings))) { \
*out = *((input_type *) settings.output); \
return true; \
} \
return false; \
}
#endif // DEF_NEW_DO_SIMPLE_TAP_IMPL

#ifndef DEF_NEW_DO_SIMPLE_PROTO
#define DEF_NEW_DO_SIMPLE_PROTO(id, input_type) \
bool calc_do_simple_ ## id(input_type data, input_type *out); \
#endif // DEF_NEW_DO_SIMPLE_PROTO

#endif // DOWNSAMPLING_SIMPLE_TEMPLATE_H
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#ifndef DOWNSAMPLING_SUBSAMPLING_TEMPLATE_H
#define DOWNSAMPLING_SUBSAMPLING_TEMPLATE_H

#include <stddef.h>
#include <stdint.h>


#ifndef DEF_DOWNSAMPLING_SUBSAMPLING_OUTPUT_LENGTH
#define DEF_DOWNSAMPLING_SUBSAMPLING_OUTPUT_LENGTH(id, factor) \
uint32_t get_downsampling_subsampling_output_length_ ## id(uint32_t input_length) { \
size_t get_downsampling_subsampling_output_length_ ## id(size_t input_length) { \
return (input_length + factor - 1u) / factor; \
}
#endif
Expand All @@ -15,13 +16,13 @@ uint32_t get_downsampling_subsampling_output_length_ ## id(uint32_t input_length
#ifndef DEF_DOWNSAMPLING_SUBSAMPLING_IMPL
#define DEF_DOWNSAMPLING_SUBSAMPLING_IMPL(id, input_type, factor) \
void downsample_subsampling_ ## id( \
const input_type *input, input_type *output, uint32_t input_length, uint8_t augment \
const input_type *input, input_type *output, size_t input_length, uint8_t augment \
) { \
const uint32_t output_length = get_downsampling_subsampling_output_length_ ## id(input_length); \
const uint32_t offsets = augment ? factor : 1u; \
for (uint32_t offset = 0u; offset < offsets; ++offset) { \
for (uint32_t output_index = 0u; output_index < output_length; ++output_index) { \
const uint32_t input_index = offset + output_index * factor; \
const size_t output_length = get_downsampling_subsampling_output_length_ ## id(input_length); \
const size_t offsets = augment ? factor : 1u; \
for (size_t offset = 0u; offset < offsets; ++offset) { \
for (size_t output_index = 0u; output_index < output_length; ++output_index) { \
const size_t input_index = offset + output_index * factor; \
output[offset * output_length + output_index] = \
input_index < input_length ? input[input_index] : (input_type)0; \
} \
Expand All @@ -32,9 +33,9 @@ void downsample_subsampling_ ## id( \

#ifndef DEF_DOWNSAMPLING_SUBSAMPLING_PROTO
#define DEF_DOWNSAMPLING_SUBSAMPLING_PROTO(id, input_type) \
uint32_t get_downsampling_subsampling_output_length_ ## id(uint32_t input_length); \
size_t get_downsampling_subsampling_output_length_ ## id(size_t input_length); \
void downsample_subsampling_ ## id( \
const input_type *input, input_type *output, uint32_t input_length, uint8_t augment \
const input_type *input, input_type *output, size_t input_length, uint8_t augment \
);
#endif

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .simple import build_downsampling_simple as build_downsampling_simple
from .subsampling import build_downsampling_subsampling as build_downsampling_subsampling
71 changes: 71 additions & 0 deletions elasticai/creator_plugins/downsampling/src/c_compile/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from datetime import datetime
from pathlib import Path

import elasticai.creator_plugins.downsampling as design_plugin
from elasticai.preprocessor.translation.ir2c import (
generate_c_files,
get_embedded_datatype,
replace_variables_with_parameters,
)


def build_downsampling_simple(
downsampling_ratio: int,
bitwidth: int,
signed: bool,
path2save: Path,
downsampling_id: str = "0",
define_path: str = "src",
) -> None:
"""Generate C files for downsampling simple.
Args:
downsampling_ratio: Integer with downsampling ratio for reducing the input sampling rate (SR_out = SR_in / OSR)
bitwidth: Bit width of each sample
signed: Decision if data values are signed [otherwise unsigned]
path2save: Path to save the .h / .c output-files.
downsampling_id: ID appended to function names
define_path: Include path written into the generated #include line.
"""
assert bitwidth in range(2, 65), "Bitwidth must be between 2 and 64"
assert downsampling_ratio > 0, "dsr must be >= 1"

module_id = downsampling_id.lower()
params = {
"datetime_created": datetime.now().strftime("%m/%d/%Y, %H:%M:%S"),
"path2include": define_path,
"template_name": "downsampling_simple_template.h",
"device_id": module_id.upper(),
"data_type": get_embedded_datatype(bitwidth, signed),
"downsampling_ratio": str(downsampling_ratio),
}
template_c = _generate_downsampling_simple_template()
generate_c_files(
path2save=path2save,
template_name=params["template_name"],
file_name="downsampling_simple",
module_id=module_id,
proto_file=replace_variables_with_parameters(template_c["head"], params),
impl_file=replace_variables_with_parameters(template_c["func"], params),
path2template=Path(design_plugin.__file__).parent / "c",
)


def _generate_downsampling_simple_template() -> dict[str, list[str]]:
header_template = [
"// --- Generating do_simple",
"// Copyright @ UDE-IES",
"// Code generated on: {$datetime_created}",
"// Params: ID = {$device_id}, type = {$data_type}, dsr = {$downsampling_ratio}",
'#include "{$path2include}/{$template_name}"',
"DEF_NEW_DO_SIMPLE_PROTO({$device_id}, {$data_type})",
]
implementation_template = [
"// --- Generating do_simple",
"// Copyright @ UDE-IES",
"// Code generated on: {$datetime_created}",
"// Params: ID = {$device_id}, type = {$data_type}, dsr = {$downsampling_ratio}",
'#include "{$path2include}/{$template_name}"',
"DOWNSAMPLING_SIMPLE_OUTPUT_LENGTH({$device_id}, {$downsampling_ratio})",
"DEF_NEW_DO_SIMPLE_TAP_IMPL({$device_id}, {$data_type}, {$downsampling_ratio})",
]
return {"head": header_template, "func": implementation_template}
4 changes: 2 additions & 2 deletions elasticai/preprocessor/_basics_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@


def test_path_to_project() -> None:
checks = ["elastic-ai", "preprocessor"]
checks = ["elasticai", "preprocessor"]
rslt = get_path_to_project()

assert rslt.is_dir()
assert rslt.parts[-1] == f"{checks[0]}.{checks[1]}"


def test_path_to_project_ref() -> None:
checks = ["elastic-ai", "preprocessor", "test"]
checks = ["elasticai", "preprocessor", "test"]
rslt = get_path_to_project(new_folder=checks[2])

assert not rslt.exists()
Expand Down
Loading
Loading