Unit 3 / 12

Signal Processing: Filters, Sampling and Frequency Analysis

Gains:

  • Ability to correctly construct and apply sampling, Nyquist and aliasing concepts with AI support
  • Ability to translate FFT, filter design and windowing steps into draft code and calculations with AI
  • Ability to verify signal processing results produced by AI with reference signal, unit control and measurement

Signal processing is the heart of electronics and communications engineering: the art of taking a voltage wave, a sound recording, a sensor reading, or a radio signal and extracting the information within it, cleaning up its noise, and transforming it. In this unit, you will see how to use AI to learn signal processing concepts, construct filter and transformation calculations, and perform analysis with Python code. But a warning from the very beginning: a small conceptual error in signal processing (wrong sampling frequency, skipped windowing, interfering unit) will completely and silently distort the result; The graph still looks good, but it is wrong. That's why it's imperative to test every result the AI ​​produces against a known reference signal and unit control.

Sampling and Nyquist: where it all begins

To process an analog signal (continuous wave) in a computer, we measure it at certain intervals and convert it into a number; This is called sampling. It is the sampling frequency (fs, unit Hz) how many samples we take per second. The Nyquist criterion states that to accurately recover a signal, the sampling frequency must be at least twice the highest frequency in the signal. If this condition is not met, high frequencies start to look like low frequencies; This is called aliasing and the data is permanently corrupted because you cannot distinguish between these two situations.

AI explains this concept very well and can demonstrate it with examples. But you decide when choosing your sampling frequency: what is the actual bandwidth of your signal, do you have an anti-aliasing analog filter, what speed does your ADC (Analog-Digital Converter: the chip that converts the analog signal to number) actually operate. AI may “suggest” a sampling frequency, but this suggestion is a guess without measuring the actual spectrum of your signal.

Tip: When asking the AI ​​a sampling question, specify the highest frequency and bandwidth of your signal yourself. "If the highest component of my signal is ~4 kHz, how should I choose fs and where should I put the anti-aliasing filter?" like. Don't make the AI ​​guess the spectrum; measure.

FFT and frequency analysis

FFT (Fast Fourier Transform) is a fast algorithm that converts a signal from the time axis to the frequency axis. So "what frequencies are in this signal and with how much power?" answers the question. AI does very well how to implement FFT, interpret results, and write Python code (numpy/scipy). But there are common errors in FFT, and AI code can silently include them:

  • Frequency axis scaling: The frequency axis of the FFT output depends on the sampling frequency. If fs is entered incorrectly, all frequencies are output incorrectly, but the graph appears normal.
  • Windowing: When a finite piece of signal is received, discontinuity occurs at the edges and pseudo-spreading (spectral leakage) is observed in the spectrum. Windows like Hann and Hamming reduce this. If the AI ​​code skips windowing, the result will be misleading.
  • Amplitude normalization: Scaling and window correction are required to convert the amplitude of the FFT output to the actual physical value. If omitted, the amplitudes will be incorrect.

filter design

A filter is a circuit or algorithm that extracts unwanted frequencies from a signal. There are four basic types: low-pass (passes low frequencies), high-pass, band-pass, and band-pass (notch). There are two large families of digital filters: FIR (finite impulse response, stable and linear phase) and IIR (infinite impulse response, steep transition with less calculation but stability and phase risk).

AI explains the design steps of a filter (cutoff frequency, passband, stopband attenuation, order selection) and writes coefficient generating code with scipy. But the cutoff frequency of the filter you design is given normalized (relative to the Nyquist frequency), and entering fs incorrectly here is a very common mistake. Additionally, stability and phase distortion may be a problem in IIR filters, and latency may be a problem in real-time systems. Be sure to verify the AI-generated filter with a frequency response graph and a known test signal.

three mini cases

Case 1 — Overlapping vibration. An engineer samples the vibration of a motor at 1 kHz and sees a strong peak in the FFT at 300 Hz. This peak, which does not match the engine design, is confusing. There is actually a real component in the engine around 1300 Hz; 1 kHz sampling is insufficient for this (Nyquist 500 Hz) and 1300 Hz overlapped 300 Hz. After discussing with the AI ​​"whether this peak is real or aliasing" and increasing the sampling frequency to 5 kHz, the peak appears in the correct place at 1300 Hz. Lesson: on a questionable hill, first question sampling adequacy.

Case 2 — Skipped window. An intern requests an FFT code from the AI ​​and executes it. He expects a single frequency test tone but sees a wide spread across the spectrum. The problem is that the code does not do windowing (spectral leakage). Tell the AI ​​"add Hann window and apply amplitude correction" and the output returns to the expected sharp peak. Lesson: Test the FFT code with a known single-frequency signal; Check the window if there is a leak.

Case 3 — Wrong fs. An engineer analyzes the data from the recorder. The device recorded at 48 kHz, but the default 44.1 kHz was entered in the AI ​​code. All frequencies are shifted by 8%; A 1000 Hz tone appears at 1088 Hz. Error is found when checking the actual fs of the measuring equipment. Lesson: sampling frequency is the single most critical number in the analysis chain; must be verified from the source.

Copiable prompt templates

FFT SETUP TEMPLATE"Write an FFT analysis code in Python (numpy/scipy). Input: samplingfrequency fs=[value] Hz, signal string 'x'. Let the code do THE FOLLOWS: (1) Apply Hann window, (2) Get FFT, (3) accurately scale frequency axis relative to fs, (4) plot one-sided amplitude spectrum with window correction. At each step of the code "Please state in the comment line which assumption you are making so I can verify it."

SAMPLING CONTROL TEMPLATE "The highest significant frequency of my signal is approximately [X] Hz. Explain the Nyquist margin, the need for an anti-aliasing filter, and the practical margin of safety when choosing a sampling frequency. Suggest a range but emphasize that I should verify this by measuring the true spectrum of the signal."

FILTER DESIGN TEMPLATE "Design a [low/high/band] pass digital filter with scipy. Cutoff frequency [X] Hz, sampling frequency fs=[Y] Hz. Compare FIR and IIR options (stability, phase, delay, computational load). Clearly show in the code how the cutoff frequency is normalized to fs. Also include code that validates the filter with a frequency response graph."

RESULT VALIDATION TEMPLATE "Examine the signal processing code below and flag sources of silent errors: wrong fs, skipped windowing, unit crosstalk (Hz/kHz,V/mV), lack of normalization, single/double-sided spectrum crosstalk. Suggest how I should test (with which reference signal) for each. Code: [paste]."

Weak prompt / Strong prompt

WEAK PROMPT: "Find the frequency of this signal."

STRONG PROMPT: "I have a signal array with a sampling frequency of 10 kHz. Write a Python code that finds the dominant frequency components with FFT; use Hann window and amplitude correction, scale the frequency axis according to fs. At the end of the code, add a validation block with a synthetic test signal of 1 kHz fs and see if the scaling is correct."

Weak prompt produces a context-free response and assumes fs; It returns strong prompt parameters and prompts for a self-verifying test block.

Table of units and assumptions in signal processing

concept

frequent error

verification

Sampling frequency (fs)

Default instead of device's actual FS

Confirmation from recorder setting

frequency axis

If fs is wrong the entire axis shifts

Known frequency test tone

Windowing

Spectral leak when skipped

Peak width in monotone signal

Amplitude

Normalization/correction missing

Comparison with known amplitude signal

filter cut

normalize error according to fs

Frequency response graph

Caution: Just because an FFT graph looks smooth and believable does not mean it is accurate. If the frequency axis is scaled incorrectly, all the peaks are in the wrong place but the graph looks perfect. Always calibrate with a known reference.

Common mistakes

  • Not verifying the sampling frequency from the source. Wrong fs shifts all frequencies.
  • Violating Nyquist and not noticing aliasing. On suspicious hills, first question the sampling adequacy.
  • Skipping windowing in FFT. Spectral leakage looks like a real peak.
  • Forgetting amplitude normalization. Amplitudes remain unscaled to physical value.
  • Incorrectly normalizing the filter cutoff frequency to fs. The filter cuts in a different place than expected.

In summary

In this unit, you have positioned AI as a powerful aid in learning signal processing concepts, writing FFT and filter code, and constructing analysis. But in signal processing, the results can be silently distorted: wrong sampling frequency, skipped windowing, interfering volume, or lack of normalization make the graph beautiful but inaccurate. So test every code the AI ​​produces against a known reference signal, verify the sampling frequency from the source, and test each result for unit and physical plausibility. Check the concept of Nyquist and aliasing at the beginning of each analysis.

Application task

Create a synthetic test signal in Python: sum of two known frequencies (e.g. 1 kHz and 3 kHz), fs=10 kHz. Request the analysis code from the AI ​​with the “FFT setup” template and verify that the peaks appear at the correct frequencies. Then deliberately enter the fs incorrectly (e.g. 8 kHz) and observe how the peaks shift. Finally, remove the windowing and see the spectral leakage. Write down the results of each experiment in one sentence.

checklist

  • [ ] I verified the sampling frequency (fs) from the actual setting of the recorder.
  • [ ] I checked the Nyquist criterion and evaluated the risk of aliasing.
  • [ ] I have checked that windowing and amplitude correction are implemented in the FFT code.
  • [ ] I tested the code with a reference signal of known frequency.
  • [ ] I verified by visual response that the filter cutoff frequency was correctly normalized to fs.
  • [ ] I made all units (Hz/kHz, V/mV) consistent.