An interactive Control Systems Design Tool that allows you to visualize and tune Lead and Lag compensators in real time using Bode plots.
This project is built using HTML, CSS, and JavaScript (Plotly.js) and is designed for students, engineers, and enthusiasts working with frequency-domain analysis.
-
📊 Real-time Bode Magnitude & Phase plots
-
🎛️ Interactive tuning of compensator parameters:
- Gain factor
a - Time constant
T
- Gain factor
-
🔄 Switch between:
- 🚀 Lead compensator (phase boost)
- 🐢 Lag compensator (steady-state improvement)
-
📈 Automatic calculation of:
- Gain crossover frequency (ωgc)
- Phase margin (PM)
- Gain margin (GM)
-
🧮 Custom plant transfer function input
-
🧾 Live display of transfer function
-
📱 Fully responsive modern UI
The compensator used:
-
Lead Compensator: Gc(s) = (1 + aTs) / (1 + Ts), where a > 1
-
Lag Compensator: Gc(s) = (1 + aTs) / (1 + Ts), where a < 1
The system computes:
- Bode magnitude: 20 log₁₀ |G(jω)|
- Phase: ∠G(jω)
- Gain crossover: |G(jω)| = 1
- Phase margin: PM = 180° + ∠G(jωgc)
- Frontend: HTML, CSS
- Logic: Vanilla JavaScript
- Plotting: Plotly.js
├── index.html # UI structure
├── style.css # Styling & responsiveness
├── script.js # Core computation & plotting logic
- Clone the repository:
git clone https://github.com/your-username/lead-lag-compensator-visualizer.git
cd lead-lag-compensator-visualizer- Open
index.htmlin your browser.
No build tools or installation required 🚀
-
Enter plant transfer function coefficients:
- Numerator (e.g.,
1000) - Denominator (e.g.,
1,22,40,0)
- Numerator (e.g.,
-
Select compensator type:
- Lead (a > 1)
- Lag (a < 1)
-
Adjust:
a(gain factor)T(time constant)
-
Observe:
- Bode plots updating in real time
- Phase margin improvement
- Gain crossover shift
- Magnitude & Phase plots update instantly
- Clean dark UI with smooth interaction
- Designed for intuitive learning and experimentation
- Custom complex number arithmetic engine
- Polynomial evaluation for transfer functions
- Logarithmic frequency sweep (logspace)
- Phase unwrapping to avoid discontinuities
- Numerical interpolation for accurate margin calculation
- Nyquist plot support
- Root locus visualization
- Automatic compensator design (given target PM)
- Export plots as images
- Save/load configurations
Feel free to fork the repo and submit pull requests!
MIT License
Anish Electronics & Telecommunication Engineering Jadavpur University