A collection of digital signal processing (DSP) and analog filter implementations for QSPICE circuit simulator using custom C++ DLLs and Python analysis tools.
.
├── README.md # This file
├── hello_filter/ # Simple IIR digital filter (starter example)
│ ├── build_qspice_dll.bat # Build script for MSVC
│ ├── digital_filter_x1.cpp # First-order IIR filter implementation
│ └── digital_filter.qsch # Filter schematic
├── second_order/ # Adaptive LMS filter with second-order system
│ ├── second_order_x1.cpp # LMS adaptive filter (50-tap FIR)
│ ├── second_order.qsch # Adaptive filter test schematic
│ ├── lms_sim.png # Simulation results
│ └── second_order.pfg # Plot configuration
├── active_filter/ # Active analog filter design and analysis
│ ├── active_filter.qsch # Op-amp based active filter schematic
│ ├── test_filter.py # Python filter analysis script
│ └── test_filter.ipynb # Jupyter notebook for filter design
└── op_amp_math/ # Op-amp mathematical operations
└── op_amp.qsch # Op-amp circuit schematic
Note: Build outputs (.dll, .obj, .lib, .exp) and simulation data (.qraw, .qopraw) are generated in their respective directories.
A simple introductory digital filter implementing a basic IIR (Infinite Impulse Response) filter:
- Algorithm:
OUT = (1-a) * IN + a * y_last - Filter coefficient:
a = 0.90 - Type: Low-pass filter
- Use case: Learning basic digital filter concepts in QSPICE
Advanced adaptive filtering using the Least Mean Squares (LMS) algorithm:
- Architecture: 50-tap FIR filter
- Algorithm: LMS adaptive filtering for system identification
- Features:
- Real-time weight adaptation
- Clock division (10,000:1) for convergence stability
- Error signal output for convergence monitoring
- Use case: Adaptive noise cancellation, system identification, echo cancellation
Op-amp based active filter design with Python analysis:
- Components: Op-amp circuits with R, L, C components
- Analysis Tools:
- Python scripts for frequency response analysis
- Jupyter notebooks for interactive filter design
- Transfer function calculations
- Use case: Analog filter prototyping, frequency response analysis
Circuit implementations of mathematical operations using operational amplifiers.
The filter implements a simple IIR (Infinite Impulse Response) digital filter with the equation:
OUT = (1-a) * IN + a * y_last
Where:
a = 0.90(filter coefficient)INis the input signalOUTis the filtered output- The filter is clocked and updates on the rising edge of CLK
The second-order project implements a 50-tap FIR adaptive filter using the LMS algorithm:
// Prediction: y_est = Σ(w[i] * x[i])
// Error: e = desired - y_est
// Weight Update: w[i] = w[i] + μ * e * x[i]Parameters:
- Filter length: 50 taps
- Learning rate (μ): 0.001
- Clock division: 10,000:1 for stable convergence
- Outputs: Estimated signal and error for monitoring
- QSPICE - Circuit simulator (download here)
- Microsoft Visual Studio 2022 (Community Edition or higher) with C++ tools
- Python 3.x (optional, for active filter analysis)
- NumPy
- Matplotlib
- Jupyter (for notebook analysis)
- Open this folder in VS Code
- Press
Ctrl+Shift+Bor select Terminal → Run Build Task - The DLL will be compiled as
digital_filter_x1.dll
Navigate to the project directory (e.g., hello_filter/ or second_order/) and run:
cd hello_filter
build_qspice_dll.bat digital_filter_x1.cppOr for the adaptive filter:
cd second_order
build_qspice_dll.bat second_order_x1.cpp- Build the DLL using VS Code or the batch script
- Open the corresponding
.qschfile in QSPICE:hello_filter/digital_filter.qschfor basic IIR filtersecond_order/second_order.qschfor adaptive LMS filter
- Run the simulation - QSPICE will automatically load the compiled DLL
- The DLL must be in the same directory as the schematic file
- Navigate to
active_filter/directory - Run the Python script:
python test_filter.py
- Or open
test_filter.ipynbin Jupyter for interactive analysis:jupyter notebook test_filter.ipynb
- 32-bit DLL Required: QSPICE is a 32-bit application, so the DLL must be compiled for x86 (32-bit)
- Calling Convention: Uses
extern "C" __declspec(dllexport)for proper linking - Static Variables: Filter state is maintained in static variables between calls
- Clock-Triggered: Filters update on the rising edge of the CLK signal
- Convergence: Uses clock division (10,000:1) to slow down adaptation for stable convergence
- Filter Order: 50-tap FIR provides good balance between performance and computation
- Learning Rate: μ = 0.001 chosen for stable convergence
- Error Monitoring: Secondary output provides real-time error signal for convergence analysis
To change filter behavior in hello_filter/:
- Edit
hello_filter/digital_filter_x1.cpp - Rebuild with
Ctrl+Shift+B - Rerun the simulation in QSPICE
Common modifications:
- Change
acoefficient for different filtering characteristics - Implement different filter types (Butterworth, Chebyshev, etc.)
- Add additional states for higher-order filters
To modify the adaptive filter in second_order/:
- Edit
second_order/second_order_x1.cpp - Adjust parameters:
w.size(): Change filter length (number of taps)mu: Adjust learning rate for faster/slower convergenceDIV_RATIO: Modify clock division for convergence speed
- Rebuild and test in QSPICE
Modify Python scripts in active_filter/ to:
- Change component values (R, L, C)
- Analyze different frequency ranges
- Plot magnitude and phase responses
- Design custom transfer functions
- Adaptive Noise Cancellation: Use LMS filter to remove noise from desired signals
- System Identification: Model unknown systems using adaptive filtering
- Active Filter Design: Prototype and analyze op-amp based analog filters
- Digital Filter Learning: Understand DSP concepts with hands-on QSPICE simulations
- Echo Cancellation: Implement adaptive echo cancellation systems
- Signal Conditioning: Design custom filters for sensor signal processing
This project is provided as-is for educational and engineering purposes.