This code demonstrates the usage of a ring buffer for the estimation of derivatives using AlgDiff in C Code. The main file generates a signal, performs convolution using a predefined kernel, and saves the results to files.
-
Export filter coefficients: The notebook export2ipynb can be used to export filter coefficients into a suitable format.
-
Compile the Code: Compile the code using a C compiler (e.g., GCC) to generate the executable.
gcc main.c -o ring_buffer_convolution
-
Run the Executable: Execute the compiled program to perform the signal processing and save the results to files.
./ring_buffer_convolution
-
View Results: Check the generated
result.txt
andsignal.txt
files to view the processed signals. the python functiontest_c_code.py
can be used to plot the sitnals.
- The main function initializes a ring buffer for signal storage and performs convolution on the generated signal.
- It then saves the original and convolved signals to separate files (
signal.txt
andresult.txt
, respectively). - The number of samples (
N
) can be adjusted to change the duration the signals.
- main.c: Contains the main code for initializing the ring buffer, generating and processing signals, and saving the results.
- RingBuffer.h: Header file containing the definition of the RingBuffer struct and function prototypes for buffer initialization and value insertion. This file is automatically generated by AlgDiff.
- functions_algdiff.h: Header file containing function prototypes for signal processing functions such as convolution.
- AlgDiff.h: Header file containing predefined constants and data structures for signal processing.
- result.txt: File containing the convolved signal data.
- signal.txt: File containing the original signal data.
- C Compiler (e.g., GCC)
- Standard C Library (stdio.h, stdlib.h, math.h)