Skip to content

mohamedtareq24/Matrix-Inversion-processor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matrix-Inversion-processor

Progress

# Task Status
1 MATLAB Model — floating-point & fixed-point Q3.13 CORDIC QR reference ✅ Done
2 RTL Design — QR stage FSM, CORDIC datapath, AXI-Stream wrapper ✅ Done
3 RTL Synthesis — Vivado synthesis & timing closure 🔲 Pending
5 R⁻¹ Stage — CORDIC reciprocal in RTL 🔲 Pending
6 A⁻¹ Assembly Stage 🔲 Pending
4 UVM Verification Environemnt — UVM testbench with MATLAB HDL Verifier talking to RTL via DPI-C 🔲 Pending

An FPGA hardware accelerator for real-time 3×3 matrix inversion using the QR decomposition method, implemented entirely with iterative CORDIC arithmetic on a fixed-point Q3.13 datapath.


Matrix Inversion via QR Decomposition

Computing A⁻¹ directly requires divisions and square roots that are expensive in hardware. Instead, this design factors the problem using QR decomposition:

$$A = Q R$$

where Q is orthogonal ($Q^T Q = I$) and R is upper triangular. The inverse then follows cheaply:

$$A^{-1} = R^{-1} Q^T$$

Because Q is orthogonal, $Q^T$ costs no logic — it is just a transpose. Inverting the upper triangular R requires only 3 diagonal reciprocals and back-substitution multiplications, avoiding any general matrix inversion.

Processing Pipeline

Input A (3×3)
│
▼
┌─────────────┐ ← Step 1 — this block
│ QR Stage    │──> R matrix (upper triangular)
│ CORDIC-QR   │──> G1, G2, G3 (Givens params: c, s per stage)
└─────────────┘
│
▼
┌─────────────┐ ← Step 2
│ R Inverse   │──> R⁻¹ via CORDIC reciprocals + back-substitution
└─────────────┘
│
▼
┌─────────────┐ ← Step 3
│ Q Assembly  │──> Q = (G3·G2·G1)ᵀ built from stored (c, s) pairs
└─────────────┘
│
▼
┌──────────────────┐ ← Step 4
│ A⁻¹ = R⁻¹ · Qᵀ   │──> Final inverse output
└──────────────────┘****

Step 1 — QR Stage

The QR stage is the first and most compute-intensive step. It decomposes A into Q and R using three successive Givens rotations, each driven by a CORDIC vectoring + rotation kernel.

Architecture

Architecture Diagram

Givens Rotation Schedule

Three stages zero the three sub-diagonal entries of A:

Stage Vector pair Rotated pairs Eliminates
1 (a₁₁, a₂₁) (a₁₂, a₂₂), (a₁₃, a₂₃) a₂₁ → 0
2 (a₁₁, a₃₁) (a₁₂, a₃₂), (a₁₃, a₃₃) a₃₁ → 0
3 (a₂₂, a₃₂) (a₂₃, a₃₃) a₃₂ → 0

CORDIC Datapath

Four CORDIC units operate in parallel per stage, sharing direction bits and pre-rotation flags from the vector unit:

  • Vector CORDIC — drives y to zero; outputs angle_direction, swap, neg_x, neg_y flags each iteration and asserts slv_enable to gate all slave rotators.
  • Rotation CORDIC CS — rotates fixed vector (0, 1); s = x_out, c = y_out — Givens cosine/sine for this stage.
  • Rotation CORDIC R0 — updates matrix element pair 1 in-place.
  • Rotation CORDIC R1 — updates matrix element pair 2; receives (0, 0) in stage 3 for uniform timing.

AXI-Stream Interface

The wrapper qr_stage_axis_slave accepts the 3×3 matrix as a stream of 9 Q3.13 samples (row-major: a₁₁, a₁₂ … a₃₃):

Signal Dir Description
s_axis_tvalid in Element valid
s_axis_tready out Ready to accept — low during compute
s_axis_tdata in Matrix element, Q3.13 signed 16-bit

Outputs

Signal Description
r_elem_o[0:8] Flattened 3×3 R matrix (Q3.13)
g_c_o[0:2] Cosine c of each Givens stage
g_s_o[0:2] Sine s of each Givens stage
out_valid_o Outputs valid, held until out_ready_i

Parameters

Parameter Default Description
DATA_WIDTH 16 Word width in bits
NUM_ITERATIONS 16 CORDIC iterations per stage
FRAC_BITS 13 Fractional bits (Q3.13 format)

Source Files

File Description
src/qr_stage.sv Core QR FSM and CORDIC datapath
src/qr_stage_axis_slave.sv AXI-Stream wrapper
src/vector_cordic.sv Vector CORDIC (vectoring mode)
src/rotation_cordic.sv Rotation CORDIC (rotation mode)
MATLAB/cordic_qr_3x3_demo_fp.m Fixed-point golden reference

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors