https://github.com/albertomarquillas/block-codes-ber-matlab
MATLAB simulation of Hamming (7,4) and general (5,2) block codes over a Binary Symmetric Channel, analyzing BER performance.
https://github.com/albertomarquillas/block-codes-ber-matlab
ber-simulation block-codes bsc-channel communications digital-communications error-correcting-codes hamming-code matlab
Last synced: 8 months ago
JSON representation
MATLAB simulation of Hamming (7,4) and general (5,2) block codes over a Binary Symmetric Channel, analyzing BER performance.
- Host: GitHub
- URL: https://github.com/albertomarquillas/block-codes-ber-matlab
- Owner: AlbertoMarquillas
- License: mit
- Created: 2025-09-07T01:06:31.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-09-07T01:17:31.000Z (9 months ago)
- Last Synced: 2025-09-07T03:11:40.267Z (9 months ago)
- Topics: ber-simulation, block-codes, bsc-channel, communications, digital-communications, error-correcting-codes, hamming-code, matlab
- Language: MATLAB
- Homepage:
- Size: 780 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Block Codes BER Simulation (MATLAB)




---
## π Overview
This project implements a **MATLAB simulation** of block codes over a **Binary Symmetric Channel (BSC)** to analyze the **Bit Error Rate (BER)** performance. The goal is to compare two families of linear block codes:
* **Hamming (7,4) code**
* **General linear (5,2) code**
The simulation encodes random bit sequences, transmits them through a BSC with varying error probabilities, decodes the received sequences, and computes the resulting BER. The results are plotted and discussed in relation to redundancy, minimum distance, and error correction capabilities.
This repository is part of the **Digital Communications coursework (2024β2025)**.
---
## π Repository Structure
```
/
ββ src/ # MATLAB source code
β ββ simulate_block_codes.m
ββ test/ # Placeholder for future test scripts
ββ docs/ # Reports and written documentation
β ββ Memoria_AC2.pdf # Project report (Catalan)
β ββ Activitat prΓ ctica AC2.pdf # Original assignment statement
β ββ assets/ # Figures and simulation results
β ββ grafica_BER_AC2.png
ββ build/ # Temporary outputs (ignored)
ββ README.md # Project documentation
```
---
## βοΈ How to Run
Run the MATLAB simulation script from the repository root:
```powershell
# Run in MATLAB headless mode
tmatlab -batch "run('src/simulate_block_codes.m')"
```
This will:
1. Generate random bit sequences.
2. Encode them using Hamming (7,4) and linear (5,2) codes.
3. Transmit them through a BSC with 9 logarithmically spaced error probabilities (0.01 β 0.1).
4. Decode the received words.
5. Compute and display BER for both codes.
6. Save the resulting BER plot to `docs/assets/grafica_BER_AC2.png`.
---
## π Results
The script produces a **log-log BER curve** comparing the two codes:
* **Hamming (7,4)** β blue line
* **Linear (5,2)** β red line
The plot visually shows how each code performs as channel error probability increases.

---
## π Theoretical Background
### Hamming (7,4) Code
* Parameters: (n=7, k=4)
* Minimum distance: d\_min = 3
* Error detection: up to 2 errors per word
* Error correction: up to 1 error per word
### General Linear (5,2) Code
* Parameters: (n=5, k=2)
* Minimum distance: d\_min = 3
* Error detection: up to 2 errors per word
* Error correction: up to 1 error per word
Despite both having the same theoretical minimum distance, their performance differs due to structure and redundancy.
---
## π Discussion
* The **linear (5,2) code** showed slightly better BER performance than Hamming (7,4) in this simulation.
* This suggests that efficiency depends not only on minimum distance, but also on code structure and redundancy.
* Hamming codes remain widely used in hardware implementations due to their standardization and ease of decoding.
---
## π What I Learned
Through this project I gained experience in:
* MATLAB programming for digital communications.
* Simulation of linear block codes and error correction.
* Working with the Communications Toolbox functions (`encode`, `decode`, `syndtable`, `bsc`, `biterr`).
* Evaluating coding efficiency in terms of redundancy and BER.
* Structuring academic code into a professional repository format.
---
## π License
This project is released under the [MIT License](LICENSE).