WiseEDA-like RC Lowpass Filter Design

Automated RC Low‑Pass Filter Synthesis using ngspice + PSO


Overview

This project is an independent, simplified implementation inspired by the WiseEDA framework, focused specifically on RC low‑pass filter design.
The system automates the entire design flow — from user intent to optimized circuit values — using:

The goal is to demonstrate how modern EDA concepts (simulation + optimization + intent parsing) can be applied even to simple analog circuits.


Key Features


System Architecture

User Input
   │
   ├── Form Input
   └── Free Text ──► LLM (Gemini) ──► Parsed Draft
                         │
                    Parser / Validator
                         │
                   Topology Selection
                         │
                   Netlist Generation
                         │
                    ngspice Simulation
                         │
                   Scoring Function
                         │
                  PSO Optimization Loop
                         │
                    Best RC Values

Backend Setup

1️⃣ Create Virtual Environment

cd backend
python -m venv .venv
source .venv/bin/activate
# Windows:
# .venv\Scripts\activate

2️⃣ Install Dependencies

pip install -r requirements.txt

Backend Dependencies:


3️⃣ Install ngspice

Make sure ngspice is installed and available in your PATH:

ngspice -v

⚠️ ngspice is required for all simulations and optimization loops.


4️⃣ Run Backend Server

uvicorn app.main:app --reload --port 8000

Backend will be available at:

http://localhost:8000

Health check:

GET /health

Frontend Setup

cd frontend
npm install
npm run dev

Open in browser:

http://localhost:5173

Frontend provides:


LLM‑Based Free‑Text Parsing (Optional)

The system can optionally use an LLM (Gemini API) to convert free‑text user input into a structured JSON design draft.

Example User Input:

“Design a 3‑stage RC low‑pass filter with 1 kHz cutoff and at least 40 dB attenuation.”

This text is converted into a validated schema (ParsedDraft) used directly by the optimizer.


Environment Variables (Backend)

Set the following variables:

export GEMINI_API_KEY="YOUR_API_KEY"
export GEMINI_MODEL="gemini-2.5-flash-lite"
# Optional:
# export GEMINI_API_BASE_URL="https://generativelanguage.googleapis.com/v1beta"
Variable Description
GEMINI_API_KEY Required – Gemini API key
GEMINI_MODEL Optional – default: gemini-2.5-flash-lite
GEMINI_API_BASE_URL Optional – Gemini REST endpoint

If the API key is not set, the system still works using the local rule‑based parser (/parse_request).


Optimization Details


Project Structure (Backend)

backend/
 ├── app/
 │   ├── main.py          # FastAPI entry point
 │   ├── routes.py        # API routes
 │   ├── engine.py        # Optimization loop
 │   ├── optimizer.py    # PSO implementation
 │   ├── scoring.py      # Cost functions
 │   ├── netlist.py      # ngspice netlist generation
 │   ├── ngspice.py      # ngspice interface
 │   ├── topologies.py   # RC topology library
 │   ├── parser.py       # Input parsing
 │   ├── llm.py          # Gemini LLM integration
 │   ├── models.py       # Pydantic data models
 │   └── e_series.py     # E‑series rounding
 └── requirements.txt

Future Improvements