The 180Hz Ghost: Why Your Control Loop Is Fighting a Disturbance That Doesn’t Exist

Listen to this Post

Featured Image

Introduction

In the world of embedded control systems, a seemingly stable PID loop can suddenly exhibit unexplained oscillations, saturating actuators and degrading performance. Engineers often spend countless hours retuning gains, adjusting anti-windup parameters, and adding filters, only to find the problem persists. The root cause? Sampling rate aliasing—a signal processing artifact where high-frequency components fold back into the measurable spectrum, creating phantom disturbances that the controller desperately tries to eliminate.

Learning Objectives

  • Understand the Nyquist-Shannon sampling theorem and its critical role in control system design.
  • Identify aliasing artifacts in time-domain and frequency-domain data.
  • Design and implement anti-aliasing filters (analog and digital) to prevent frequency folding.
  • Apply practical Linux, Windows, and Python-based tools for spectral analysis and filter verification.

You Should Know

  1. The Nyquist Trap: When Sampling Becomes the Enemy

The Nyquist-Shannon sampling theorem states that to accurately reconstruct a continuous signal, the sampling frequency must be at least twice the highest frequency component present in that signal. This critical threshold—half the sampling rate—is known as the Nyquist frequency. Any signal content above this frequency will, upon sampling, “alias” or fold down into a lower, false frequency within the measurable band.

Consider the scenario described by Lance Harvie: a control loop running at 100 Hz (sampling rate). The Nyquist frequency is therefore 50 Hz. A mechanical vibration at 180 Hz on the motor mount exceeds this limit. When sampled, this 180 Hz component aliases down to 20 Hz (calculated as 180 Hz – 2 × 100 Hz = -20 Hz, with the absolute value taken). The controller now sees a strong 20 Hz disturbance that doesn’t physically exist and responds by oscillating, saturating its output, and generally misbehaving. Retuning the PID gains or adjusting the anti-windup logic will not fix this—the problem lies not in the control design but in the sampling design itself.

Step‑by‑step guide to detect and confirm aliasing:

  1. Capture raw time-domain data from your ADC at the existing sampling rate.
  2. Perform a Fast Fourier Transform (FFT) on the captured data to visualize the frequency spectrum.
  3. Identify the Nyquist frequency (half your sampling rate).
  4. Look for spectral content that appears suspiciously close to or below the Nyquist frequency but originates from known high-frequency sources (e.g., motor harmonics, switching power supplies).
  5. Increase the sampling rate temporarily (if hardware permits) and observe if the suspect frequency shifts or disappears—a classic sign of aliasing.

Linux command for real-time spectrum analysis (using `rtl_power`):

 Install rtl-sdr utilities (Debian/Ubuntu)
sudo apt-get install rtl-sdr

Capture spectrum data over a frequency range (example: 0-200 Hz with 1 Hz bins)
rtl_power -f 0:200:1 -g 40 -i 10 output.csv

This tool gathers signal data over a wide frequency spectrum, allowing you to identify active frequency components and spot potential aliasing artifacts.

Windows PowerShell (using audio capture and FFT):

 Install NAudio module (requires .NET)
Install-Package NAudio -Scope CurrentUser

Basic audio capture and spectrum analysis script (conceptual)
Add-Type -AssemblyName System.Windows.Forms
 ... (use NAudio to capture mic/line input and compute FFT)
  1. The Anti-Aliasing Filter: Your First Line of Defense

An anti-aliasing filter is a low-pass filter placed before the analog-to-digital converter (ADC). Its sole purpose is to remove all frequency content above the Nyquist frequency before sampling occurs. Without this filter, any high-frequency noise or harmonics will fold into the passband and corrupt your data. As Nick Velychko correctly notes, an anti-aliasing filter is not just “highly recommended”—it is essential.

The filter’s cutoff frequency (f_c) should be set at or slightly below the Nyquist frequency (f_s / 2). However, real-world filters have a roll-off slope, not an infinitely sharp cutoff. Therefore, you typically choose a cutoff frequency somewhat lower than the Nyquist frequency to ensure adequate attenuation of frequencies above f_s/2.

Designing a simple RC anti-aliasing filter:

For a first-order passive RC low-pass filter:

  • Cutoff frequency: f_c = 1 / (2πRC)
  • Choose R and C such that f_c ≤ f_s / 2.

Example: For a sampling rate of 100 Hz (Nyquist = 50 Hz), choose f_c = 40 Hz. With R = 10 kΩ, C = 1 / (2π × 40 × 10,000) ≈ 0.398 µF. Use a standard value like 0.39 µF.

Python code to design and visualize a Butterworth anti-aliasing filter:

import numpy as np
import matplotlib.pyplot as plt
from scipy import signal

Sampling rate and Nyquist frequency
fs = 100.0  Hz
nyquist = fs / 2.0

Design a 4th-order Butterworth low-pass filter with cutoff at 40 Hz
order = 4
cutoff = 40.0  Hz
normalized_cutoff = cutoff / nyquist
b, a = signal.butter(order, normalized_cutoff, btype='low', analog=False)

Frequency response
w, h = signal.freqz(b, a, worN=8000)
frequencies = w  fs / (2  np.pi)

plt.figure(figsize=(10, 6))
plt.semilogx(frequencies, 20  np.log10(abs(h)))
plt.title('Butterworth Anti-Aliasing Filter (Order 4, fc=40 Hz)')
plt.xlabel('Frequency [bash]')
plt.ylabel('Magnitude [bash]')
plt.grid(which='both', linestyle='--', linewidth=0.5)
plt.axvline(nyquist, color='red', linestyle='--', label='Nyquist Frequency (50 Hz)')
plt.axhline(-3, color='green', linestyle='--', label='-3 dB Cutoff')
plt.legend()
plt.show()

This code designs a 4th-order Butterworth filter with a cutoff at 40 Hz, providing attenuation above the Nyquist frequency.

3. Oversampling: Pushing the Nyquist Limit Higher

If your hardware supports it, increasing the ADC sampling rate is a powerful strategy. A higher sampling rate raises the Nyquist frequency, allowing the anti-aliasing filter to have a higher cutoff frequency and a more gradual roll-off, which reduces phase distortion. Oversampling also spreads the quantization noise over a wider bandwidth, improving the signal-to-1oise ratio (SNR) after digital filtering.

Step‑by‑step guide to implementing oversampling:

  1. Determine the maximum frequency of interest in your signal (e.g., 50 Hz for a motor control loop).
  2. Choose an oversampling ratio (e.g., 8×, 16×, or 32×). For a 50 Hz signal, an 8× oversampling would mean a sampling rate of 800 Hz.
  3. Configure your ADC to sample at the higher rate.
  4. Apply a digital low-pass filter (e.g., a moving average or FIR filter) to decimate the data back to the desired control rate, removing high-frequency noise that was pushed beyond the original Nyquist frequency.

Linux command to monitor ADC sampling rate (using `iio_info` for industrial I/O devices):

 List available IIO devices
iio_info

Read specific device attributes (example)
cat /sys/bus/iio/devices/iio:device0/in_voltage0_sampling_frequency
echo 800 > /sys/bus/iio/devices/iio:device0/in_voltage0_sampling_frequency

4. PID Tuning in the Presence of Aliasing

When aliasing is present, the PID controller sees a corrupted signal. The derivative term, in particular, is highly sensitive to high-frequency noise, which can cause the controller to become unstable or overly aggressive. Even with proper anti-aliasing filtering, residual noise can still affect performance.

Mitigation strategies:

  • Limit the derivative gain or use a filtered derivative (e.g., a first-order low-pass filter on the derivative term).
  • Adjust the controller’s scan rate to match the system’s natural frequency and avoid aliasing artifacts.
  • Use a damping constant in the measurement chain (e.g., set the transmitter damping to 1.3 times the PID scan rate) to suppress aliasing.

Windows/Python script for PID simulation with anti-aliasing:

import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter

Simulate a plant with high-frequency vibration
t = np.linspace(0, 10, 10000)
true_signal = np.sin(2  np.pi  5  t)  5 Hz desired signal
vibration = 0.5  np.sin(2  np.pi  180  t)  180 Hz vibration (above Nyquist)
measured_raw = true_signal + vibration

Sampling at 100 Hz (Nyquist = 50 Hz)
sample_rate = 100
sample_indices = np.arange(0, len(t), int(10000 / (sample_rate  10)))
t_sampled = t[bash]
measured_sampled = measured_raw[bash]

Anti-aliasing filter (analog pre-filter, simulated)
b, a = butter(4, 40 / (sample_rate / 2), btype='low')
measured_filtered = lfilter(b, a, measured_raw)
measured_filtered_sampled = measured_filtered[bash]

Plot results
plt.figure(figsize=(12, 8))
plt.subplot(2, 1, 1)
plt.plot(t, measured_raw, label='Raw (with 180 Hz vibration)')
plt.plot(t_sampled, measured_sampled, 'ro', label='Sampled at 100 Hz (aliased)')
plt.title('Aliasing Effect: 180 Hz folds to 20 Hz')
plt.xlabel('Time [bash]')
plt.ylabel('Amplitude')
plt.legend()
plt.grid(True)

plt.subplot(2, 1, 2)
plt.plot(t, measured_filtered, label='After Anti-Aliasing Filter')
plt.plot(t_sampled, measured_filtered_sampled, 'go', label='Sampled after Filter')
plt.title('Anti-Aliasing Filter Removes High-Frequency Content')
plt.xlabel('Time [bash]')
plt.ylabel('Amplitude')
plt.legend()
plt.grid(True)
plt.tight_layout()
plt.show()

5. Real-World Debugging: Spectrum Analysis in the Field

When you suspect aliasing in a deployed system, you need to confirm it with data. Portable spectrum analyzers or even sound cards with appropriate software can be used to capture and analyze signals.

Practical steps for field debugging:

  1. Connect a probe to the analog signal path before the ADC (or use a test point).
  2. Capture the signal using a portable oscilloscope or data acquisition module.
  3. Perform an FFT on the captured data using software like Audacity (Windows/Linux/macOS), MATLAB, or Python.
  4. Compare the frequency content above and below the Nyquist frequency.
  5. If aliasing is confirmed, implement an anti-aliasing filter or increase the sampling rate.

Linux command for audio spectrum analysis (using `sox` and plotspectrogram):

 Record audio from microphone (assuming line input for sensor signal)
rec -c 1 -r 44100 -t wav signal.wav trim 0 10

Generate a spectrogram to visualize frequency content over time
sox signal.wav -1 spectrogram -x 300 -y 200 -z 120 -o spectrogram.png

Windows command (using `ffmpeg` for spectrum analysis):

ffmpeg -i signal.wav -lavfi showspectrumpic=s=800x400 spectrum.png

6. Advanced Topics: Anti-Aliasing in Digital Control Loops

In digital control systems, the anti-aliasing filter is not just a pre-ADC component; it also plays a role in the digital domain when downsampling or decimating data. The `scipy.signal.decimate` function, for example, applies an anti-aliasing filter before downsampling to prevent aliasing.

Python example using `decimate`:

from scipy.signal import decimate

High-rate sampled data
high_rate_data = np.sin(2  np.pi  5  t) + 0.5  np.sin(2  np.pi  180  t)

Decimate by a factor of 10 (from 1000 Hz to 100 Hz) with anti-aliasing
decimated_data = decimate(high_rate_data, 10, ftype='fir')  FIR anti-aliasing filter

Choosing the right filter type:

  • Butterworth: Maximally flat magnitude response, good for general-purpose filtering.
  • Bessel: Linear phase response, minimal group delay distortion, ideal for control loops where phase lag is critical.
  • Chebyshev: Steeper roll-off but with ripple in the passband or stopband.
  • Elliptic: Sharpest roll-off but with ripple in both passband and stopband.

7. The Human Factor: Why Engineers Miss Aliasing

As Lance Harvie points out, engineers often focus on loop bandwidth, phase margin, and gain margin, but overlook the Nyquist frequency of their own sampling. The aliasing is invisible in the time-domain plot but obvious in a spectrum. Ten hours of debugging can be saved by one math lesson. This highlights a broader issue in embedded engineering: the disconnect between control theory (continuous-time) and implementation (discrete-time). Sampling is not an afterthought—it is a fundamental design parameter that must be considered from the very beginning.

Key practices to institutionalize:

  • Always compute the Nyquist frequency early in the design phase.
  • Include an anti-aliasing filter in the bill of materials (BOM) from day one.
  • Perform spectral analysis during system validation, not just time-domain step responses.
  • Train firmware engineers on basic signal processing concepts.

What Undercode Say

  • Key Takeaway 1: Aliasing is a sampling design problem, not a control design problem. Retuning PID gains cannot fix a corrupted signal caused by frequency folding.
  • Key Takeaway 2: An anti-aliasing filter is not optional—it is essential. Whether analog (pre-ADC) or digital (during decimation), it must be part of every sampled-data control system.

Analysis: The LinkedIn post by Lance Harvie and the commentary by Nick Velychko underscore a critical gap in engineering education and practice. Many embedded engineers are proficient in C, firmware, and real-time operating systems, but lack a deep understanding of signal processing fundamentals. The result is systems that exhibit mysterious oscillations, leading to costly debug cycles and field failures. The solution is not just technical (adding a filter) but also cultural (embedding signal processing into the engineering workflow). As control systems become more complex and sampling rates increase, the risk of aliasing does not diminish—it evolves. Engineers must be vigilant, using tools like FFT analyzers and simulation to validate their sampling designs. The “one math lesson” that saves ten hours of debugging is a lesson in humility: sometimes the problem is not in the code, but in the math that underpins it.

Prediction

  • +1 The growing adoption of Model-Based Design (MBD) and automated code generation will increasingly embed anti-aliasing filter design into the development workflow, reducing the incidence of sampling-related bugs.
  • +1 Advances in high-speed ADCs and low-cost microcontrollers will make oversampling a standard practice, pushing Nyquist frequencies higher and simplifying filter requirements.
  • -1 The rise of AI/ML-based control systems may introduce new forms of aliasing, as these models are trained on data that may already contain aliasing artifacts, leading to “garbage in, gospel out” scenarios.
  • -1 Without a cultural shift in engineering education, aliasing will continue to plague industrial automation, particularly in legacy systems where sampling rates are fixed and cannot be easily changed.
  • +1 Open-source tools like Python’s SciPy and Linux’s `rtl_power` are democratizing spectrum analysis, enabling even small teams to detect and mitigate aliasing early in the development cycle.

🎯Let’s Practice For Free:

🎓 Live Courses & Certifications:

Join Undercode Academy for Verified Certifications

🚀 Request a Custom Project:

Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands

IT/Security Reporter URL:

Reported By: Lanceharvie Controlsystems – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow UndercodeTesting & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin | 🦋BlueSky