Skip to content

Latest commit

 

History

History

examples_c_code

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Ring Buffer Convolution Example in C

Overview

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.

Instructions

  1. Export filter coefficients: The notebook export2ipynb can be used to export filter coefficients into a suitable format.

  2. Compile the Code: Compile the code using a C compiler (e.g., GCC) to generate the executable.

     gcc main.c -o ring_buffer_convolution
    
  3. Run the Executable: Execute the compiled program to perform the signal processing and save the results to files.

     ./ring_buffer_convolution
    
  4. View Results: Check the generated result.txt and signal.txt files to view the processed signals. the python function test_c_code.py can be used to plot the sitnals.

Code Explanation

  • 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 and result.txt, respectively).
  • The number of samples (N) can be adjusted to change the duration the signals.

File Descriptions

  • 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.

Dependencies

  • C Compiler (e.g., GCC)
  • Standard C Library (stdio.h, stdlib.h, math.h)