Gains:
- Ability to accurately establish signal processing parameters such as sampling frequency, filter type and windowing with AI
- Ability to generate Python code for FFT, filter design and noise analysis and check Nyquist and aliasing
- Ability to verify AI-generated spectrum interpretation by comparing it to measurement and physical expectation
Raw data from a sensor, microphone, or power line alone is often meaningless; It is necessary to process and interpret it on the axis of frequency, amplitude and time. Extracting spectrum with FFT, filtering noise, recognizing a vibration signature... These are all signal processing and AI generates fast Python code in this area, explains concepts, calculates filter coefficient. But a small parameter error in signal processing (wrong sampling frequency, wrong window, skipped Nyquist control) silently ruins the entire analysis; The code doesn't give errors, it just gives wrong results. In this unit, we will cover setting the correct parameters with AI, checking the generated code in terms of Nyquist and aliasing, and verifying the spectrum interpretation with physical reality.
Basic Parameters: Sampling, Nyquist, Aliasing
The first rule of digital signal processing is the Nyquist-Shannon theorem: to accurately represent a signal, the sampling frequency must be at least twice the highest frequency component in the signal. Otherwise, high frequencies will appear as low frequencies (aliasing) and this cannot be reversed.
Highest frequency in the signal: f_max = 2 kHzMinimum sampling frequency: f_s ≥ 2 · f_max = 4 kHzTo leave margin in practice: f_s ≈ 5 · f_max = 10 kHz is selectedAlso, an analog anti-aliasing filter is a MUST BEFORE sampling.
Caution: When AI suggests a sampling frequency, be sure to check if it provides Nyquist based on the highest component of your signal. The code runs without errors even at low sampling frequency; but the result is wrong due to aliasing. Additionally, no software can undo this error without an anti-aliasing filter in hardware.
Resolution and Windowing for FFT
The frequency resolution of the FFT depends on the sampling frequency and number of samples: Δf = f_s / N. For finer resolution you either collect more samples or choose lower f_s (without breaking Nyquist). Additionally, the discontinuity between the beginning and end of the signal creates "spectral leakage"; To reduce this, window functions such as Hann and Hamming are applied.
f_s = 10 kHz, N = 1024 samplesFrequency resolution: Δf = 10000 / 1024 ≈ 9.77 HzTotal recording time: T = N / f_s = 1024 / 10000 ≈ 102.4 ms
Generating and Checking FFT and Filter Code
Specify the sampling frequency, window type, and axis scale explicitly when requesting the FFT code from the AI. The following code outputs the one-sided amplitude spectrum of a signal:
import numpy as npfs = 10000 # sampling frequency (Hz) - verify Nyquist!N = 1024t = np.arange(N) / fs# sample signal: 500 Hz + 1500 Hzx = np.sin(2*np.pi*500*t) + 0.5*np.sin(2*np.pi*1500*t)w = np.hanning(N) # windowing: reduces spectral leak normalized by gain# check peak frequenciespeaks = f[np.argsort(mag)[-2:]]print("Dominant frequencies (Hz):", np.sort(peaks))
When checking this code you will be asked: Is the frequency axis really Hz or is the sample index (rfftfreq used)? Is the amplitude normalized to the window gain? Do the expected 500 and 1500 Hz peaks really occur at those points? If you verify the code with a known test signal (single frequency sine), you will confidently confirm the axis and normalization.
Weak Prompt / Strong Prompt
WEAK:"Apply FFT to this data."(Result: sampling frequency, axis scale and windowing are unclear; the graph is most likely plotted on the wrong axis.)STRONG:"Apply FFT to a 10 kHz sampled signal. Provide:- Plot the frequency axis in Hz (use rfftfreq).- Apply Hann window and normalize the amplitude by the window gain.- Print the two dominant frequencies digitally.- Mark the Nyquist limit (5 kHz) on the graph. Note that the axis will shift if the sampling frequency is incorrect."
Filter Design and Noise Analysis
AI can generate low/high/bandpass filter coefficients (FIR/IIR). But the cut-off frequency, order and stability of the filter must be checked. It can cause high order instability and phase distortion, especially in IIR filters. After designing the filter, plot the frequency response (Bode-like) to see that the cutoff is in the right place and there is no unwanted ripple in the passband.
The typical task in noise analysis is to separate the real signal from the noise. Here, evaluate the AI's suggested threshold or filter against the physical bandwidth of the signal: if your real signal is at 0-500 Hz, a component at 2 kHz is most likely noise or interference. AI gives statistics; You make the physical interpretation.
Validating the Spectrum Interpretation with Physical Reality
When interpreting a spectrum, AI makes reasonable but not always accurate inferences such as “There is a peak at 50 Hz, this is grid interference.” Compare these comments with the physical expectation: Does the system really have a 50 Hz mains connection? Are the expected rotation frequency and harmonics nearly there in the vibration spectrum of a motor? If possible, repeat the measurement with a second method (different sensor, different software) and see the same peaks.
Hint: For each spectrum interpretation, "what physical phenomenon does this peak correspond to?" Ask the question. 50/100/150 Hz network and its harmonics, rotation frequency and its multiples in rotating machines, and switching frequency in switching power supplies are known signatures. An unknown peak is either a real event or a measurement/processing error; Research both.
Mini Case
An R&D engineer measures the vibration of a fan and has the AI interpret the spectrum. "There is a dominant peak at 1200 Hz, this may be bearing failure," says AI. The engineer controls the speed of the fan: 1800 rpm = 30 Hz. Bearing and blade transition frequencies are expected to be at certain values compatible with this cycle; 1200 Hz does not correspond to any of these. It controls the sampling frequency: the signal carries content up to 2 kHz, but only 2 kHz is sampled, so a Nyquist violation. The peak at 1200 Hz is a ghost frequency resulting from aliasing. When I increase the sampling frequency to 8 kHz, the false peak disappears. Lesson: always test spectrum interpretation with physical cycle/frequency expectation and correct sampling.
Common Mistakes
- Choosing sampling frequency without checking the Nyquist criterion; Overlooking aliasing.
- Leaving the FFT frequency axis at the sample index instead of Hz.
- Mistaking spectral leakage as a signal without windowing.
- Not normalizing amplitude by number of windows/samples.
- Not checking IIR filter stability and phase distortion.
- Interpreting spectrum peaks without testing them in anticipation of physical rpm/frequency.
In summary
- The sampling frequency must be at least twice the highest component of the signal; Otherwise, aliasing will disrupt the entire analysis.
- FFT resolution Δf = f_s/N; Choose N and f_s according to your need.
- Windowing reduces spectral leakage; normalize the amplitude according to the window gain.
- Verify the AI code with a known test signal to confirm axis and normalization.
- Check the filter stability and frequency response by plotting it.
- Always test spectrum interpretation with expectation of physical frequency.
Application task
Generate a test signal of known frequency (e.g. 500 Hz + 1500 Hz sine). Request FFT and filter code from AI. Then: (1) verify that the Nyquist criterion is met, (2) check that the FFT peaks actually appear at 500 and 1500 Hz, (3) deliberately reduce the sampling frequency below Nyquist and observe how aliasing creates a spurious peak. Note your observations and the parameter you corrected.