This repository contains a complete KiCad SPICE simulation of a Pulse Code Modulation (PCM) pipeline. It demonstrates the full analog-to-digital conversion process — continuous-time Sampling, voltage Quantization, and 3-bit Digital Encoding — using KiCad's integrated ngspice engine to verify each stage through transient analysis.
- Design and simulate a Sample & Hold circuit using a MOSFET as a high-speed switch
- Model voltage quantization and 3-bit digital encoding using SPICE behavioral sources
- Verify the complete PCM pipeline against a continuous analog input signal
- MOSFET-based Sample & Hold (S/H) stage driven by a high-frequency clock
- Behavioral SPICE voltage sources (
B_V) implementing quantization and encoding logic - 3-bit digital output (MSB, Bit 1, LSB) derived from a sine wave input
- Staggered bit-trace voltages for clear, distinguishable waveform visualization
The pipeline is built in three sequential stages:
- Sampling: An N-Channel MOSFET acts as a Sample & Hold switch, capturing the instantaneous analog voltage and holding it across a capacitor.
- Quantization: The held voltage is mapped to the nearest discrete level, producing a "staircase" approximation of the original waveform.
- Encoding: The quantized levels are converted into a 3-bit binary stream — MSB (Bit 2), Bit 1, and LSB (Bit 0) — using SPICE behavioral sources with
sgn()math functions.
| Type | Component | Value / Rating |
|---|---|---|
| Active | N-Channel MOSFET (Sampling Switch) | — |
| Passive | Capacitor (Holding Element) | 10 nF |
| Mathematical | SPICE Behavioral Voltage Sources (B_V) | Quantization & encoding logic |
| Source | Sine Wave Voltage Source (Analog Input) | 1 kHz, 2.5 V offset, 2.5 V amplitude |
| Source | Pulse Voltage Source (Sampling Clock) | 10 kHz, 10 V amplitude, 10 µs pulse width |
Built and simulated entirely in KiCad EDA, using its core subsystems:
- Schematic Editor — for laying out the MOSFET, capacitor, behavioral sources, and routing the circuit nets
- Integrated SPICE Simulator (ngspice) — translates the schematic into a netlist and runs the configured Transient Analysis to plot the input, sampled, and encoded waveforms
Requirements: KiCad (v6.0+ recommended) with the integrated ngspice simulator (included by default).
Pulse-Code-Modulation-Simulation-kicad
├── PCM.kicad_pro # Main KiCad project file
├── PCM.kicad_sch # Schematic and SPICE directives
├── PCM.kicad_pcb # PCB layout file
├── PCM_Schematic.png # Circuit schematic
├── PCM_Output.png # Simulation waveform output
└── README.md
- Clone the repository:
git clone https://github.com/satvikpandurangi/Pulse-Code-Modulation-Simulation-kicad.git
- Open
PCM.kicad_proin the KiCad Project Manager. - Open the Schematic Editor to view the circuit layout.
- Go to Inspect > Simulator and click Run/Stop Simulation.
- Probe the analog input,
/HOLD, and the/BIT2,/BIT1,/BIT0nets to observe the conversion stages.
| Signal | Trace Color | Description |
|---|---|---|
| Analog Input | Red | Continuous 1 kHz sine wave between 0 V and 5.0 V |
Sampled Signal (/HOLD) |
Green | Staircase pattern tracking the input during each clock pulse |
Bit 0 / LSB (/BIT0) |
Yellow (peak 4.8 V) | Square wave from the lowest quantization thresholds |
Bit 1 (/BIT1) |
Orange (peak 5.0 V) | Square wave from the mid-level quantization thresholds |
Bit 2 / MSB (/BIT2) |
Purple (peak 5.2 V) | HIGH for the upper half of the sine wave, LOW for the lower half |
The simulation confirms the full PCM pipeline operating correctly — the analog input is sampled, held, quantized, and encoded into a 3-bit digital representation that accurately tracks the source waveform's amplitude.
Schematic:
Simulation Output:

