# davidmoranuclm/ekf_c architecture

> Architecture diagram of the GitHub repository davidmoranuclm/ekf_c, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/davidmoranuclm/ekf_c
- Repository: https://github.com/davidmoranuclm/ekf_c

## Overview

##### Project Type and Purpose
- This is a C-based mathematical library providing an implementation of an Extended Kalman Filter (EKF) and supporting quaternion mathematics.
- It includes a small test suite (using Unity), utility scripts for plotting results, and integrates with GNU Scientific Library (GSL) for core math routines.

##### Key Components (to represent
a. Core EKF Module
- src/EKF.c and include/EKF.h – the filter logic
- /EKF_const.h – configuration and constant definitions
b. Math Utilities
- src/math_utils.c + include/math_utils.h – linear algebra helpers
- src/jacobian.c + include/jacobian.h – Jacobian matrix computations
c. Quaternion Support
- src/gsl_quaternion_float.c + include/gsl_quaternion_float.h – quaternion operations
- src/rotations.c + include/rotations.h – 3D rotation helpers
d. External Dependencies
- GSL (cloned in top level, used for more advanced math routines)
- Unity (in Unity/ folder, C unit testing framework)
e. Test Suite
- tests/*.c & tests/CMakeLists.txt – test cases for EKF, primitives, quaternions, jacobians
- Unity runner & harness in Unity/src
f. Utilities

##### Relationships & Interactions
- Core EKF calls math_utils, jacobian, and quaternion modules to perform state prediction and update.
- Quaternion and rotation modules may rely on GSL’s low-level vector/matrix types.
- Test suite invokes EKF, math_utils, jacobian, quaternion modules via Unity harness.
- Build system (CMakeLists.txt files) orchestrates compilation of src, linking to GSL and Unity, and execution of tests.
- utils/plotResults.m consumes output data generated by tests or example runs.

##### Architectural Patterns & Principles
- Layered architecture:
1) External libraries (GSL, Unity)
2) Core algorithm (EKF)
3) Supporting libraries (math, jacobian, quaternion, rotations)
4) Testing & utilities
- Separation of interface (include/) from implementation (src/)
- Test-driven development via Unity

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Dependencies
    subgraph "External Libraries" 
        direction TB
        GSL["GSL Library"]:::external
        subgraph "Unity Test Framework" 
            direction TB
            U_C["unity.c"]:::external
            U_H["unity.h"]:::external
            U_I["unity_internals.h"]:::external
            U_CMake["CMakeLists.txt"]:::external
        end
    end

    %% Core EKF Module
    subgraph "Core Algorithm" 
        direction TB
        EKF["EKF\n(src/EKF.c, include/EKF.h, include/EKF_const.h)"]:::core
    end

    %% Support Libraries
    subgraph "Supporting Libraries" 
        direction TB
        Math["Math Utils\n(src/math_utils.c, include/math_utils.h)"]:::support
        Jacobian["Jacobian\n(src/jacobian.c, include/jacobian.h)"]:::support
        Quat["Quaternion Support\n(src/gsl_quaternion_float.c, include/gsl_quaternion_float.h)"]:::support
        Rot["3D Rotations\n(src/rotations.c, include/rotations.h)"]:::support
    end

    %% Tests and Utilities
    subgraph "Tests & Utilities" 
        direction TB
        subgraph "Test Suite" 
            direction TB
            T1["EKF_test.c"]:::test
            T2["EKF_test_primitives.c"]:::test
            T3["jacobian_test.c"]:::test
            T4["quaternion_test.c"]:::test
            T_CMake["CMakeLists.txt"]:::test
        end
        Plot["Plot Results\n(utils/plotResults.m)"]:::utility
    end

    %% Build System
    subgraph "Build System" 
        direction TB
        CTop["CMakeLists.txt"]:::build
        CSrc["src/CMakeLists.txt"]:::build
        CTests["tests/CMakeLists.txt"]:::build
        CUnity["Unity/CMakeLists.txt"]:::build
    end

    %% Dependencies and Interactions
    CTop -->|configures| GSL
    CTop -->|configures| U_CMake
    CTop -->|compiles| CSrc
    CTop -->|compiles| CTests
    CTop -->|compiles| CUnity

    EKF -->|calls| Math
    EKF -->|calls| Jacobian
    EKF -->|calls| Quat
    EKF -->|calls| Rot

    Quat -->|uses GSL types| GSL

    T1 -->|tests| EKF
    T2 -->|tests| Math
    T3 -->|tests| Jacobian
    T4 -->|tests| Quat

    U_CMake -->|builds tests| T_CMake
    T_CMake -->|runs| U_C
    T_CMake -->|runs| U_H
    T_CMake -->|runs| U_I

    Plot -->|consumes output| EKF

    %% Click Events
    click EKF "https://github.com/davidmoranuclm/ekf_c/blob/main/src/EKF.c"
    click EKF "https://github.com/davidmoranuclm/ekf_c/blob/main/include/EKF.h"
    click EKF "https://github.com/davidmoranuclm/ekf_c/blob/main/include/EKF_const.h"
    click Math "https://github.com/davidmoranuclm/ekf_c/blob/main/src/math_utils.c"
    click Math "https://github.com/davidmoranuclm/ekf_c/blob/main/include/math_utils.h"
    click Jacobian "https://github.com/davidmoranuclm/ekf_c/blob/main/src/jacobian.c"
    click Jacobian "https://github.com/davidmoranuclm/ekf_c/blob/main/include/jacobian.h"
    click Quat "https://github.com/davidmoranuclm/ekf_c/blob/main/src/gsl_quaternion_float.c"
    click Quat "https://github.com/davidmoranuclm/ekf_c/blob/main/include/gsl_quaternion_float.h"
    click Rot "https://github.com/davidmoranuclm/ekf_c/blob/main/src/rotations.c"
    click Rot "https://github.com/davidmoranuclm/ekf_c/blob/main/include/rotations.h"
    click U_C "https://github.com/davidmoranuclm/ekf_c/blob/main/Unity/src/unity.c"
    click U_H "https://github.com/davidmoranuclm/ekf_c/blob/main/Unity/src/unity.h"
    click U_I "https://github.com/davidmoranuclm/ekf_c/blob/main/Unity/src/unity_internals.h"
    click U_CMake "https://github.com/davidmoranuclm/ekf_c/blob/main/Unity/CMakeLists.txt"
    click T1 "https://github.com/davidmoranuclm/ekf_c/blob/main/tests/EKF_test.c"
    click T2 "https://github.com/davidmoranuclm/ekf_c/blob/main/tests/EKF_test_primitives.c"
    click T3 "https://github.com/davidmoranuclm/ekf_c/blob/main/tests/jacobian_test.c"
    click T4 "https://github.com/davidmoranuclm/ekf_c/blob/main/tests/quaternion_test.c"
    click T_CMake "https://github.com/davidmoranuclm/ekf_c/blob/main/tests/CMakeLists.txt"
    click Plot "https://github.com/davidmoranuclm/ekf_c/blob/main/utils/plotResults.m"
    click CTop "https://github.com/davidmoranuclm/ekf_c/blob/main/CMakeLists.txt"
    click CSrc "https://github.com/davidmoranuclm/ekf_c/blob/main/src/CMakeLists.txt"
    click CTests "https://github.com/davidmoranuclm/ekf_c/blob/main/tests/CMakeLists.txt"
    click CUnity "https://github.com/davidmoranuclm/ekf_c/blob/main/Unity/CMakeLists.txt"

    %% Styles
    classDef external fill:#cccccc,stroke:#666666,color:#000000
    classDef core fill:#82c0ff,stroke:#1f4e79,color:#000000
    classDef support fill:#a8e6a3,stroke:#2f6f2f,color:#000000
    classDef test fill:#f4b183,stroke:#b35d2f,color:#000000
    classDef utility fill:#f4b183,stroke:#b35d2f,color:#000000
    classDef build fill:#e7e7e7,stroke:#888888,color:#000000
```
