FFT Spectrum and Error Analysis

GX-TXT DEV112 P011-bis

Compute the FFT spectrum of a two-tone signal and compare the fundamental, harmonics and quality indicators over samples or intervals.

Enable and select the module

Open Configuration → Modules → Analysis & Services. Select FFT Spectrum & Error Analysis (analysis.fft_spectrum). Check that Health shows Available. With CORE / OFF press Enable module. The tested version is 2.3.0 in GX-TXT P011-bis. Open Analysis and enable Run / recalculate now to include the module in the current run.

The available module shows Enable module when it is in the CORE / OFF state.
The available module shows Enable module when it is in the CORE / OFF state.

Generate and acquire the teaching signal

  1. Open Sessions → Session → New Session… → Generate Session…. In GX-TXT Numerical Examples → Signals choose FFT Example (fft_example 1.0.0). Leave Standalone Session, choose the name and press Generate Session. The lab creates raw/fft_example.csv with 1024 samples at 1024 Hz. The synthetic signal adds a 50 Hz tone with amplitude 1 and a 120 Hz tone with amplitude 0.4.
  2. In Acquisition choose the generic CSV module. Add raw/fft_example.csv, use guida.fft.misura for the Dataset ID and timeseries.table as the contract. Check the columns time_s and signal and use Import into Current Session.
  3. In Dataset select and enable guida.fft.misura. In Variables, assign Unit s and Semantic role elapsed_time to time_s. Assign 1 to the column signal. Save and confirm the save. Check in Preview that the source contains 1024 rows.
FFT Example is the two-tone Generator. The Session contains the starting CSV.
FFT Example is the two-tone Generator. The Session contains the starting CSV.
Preview shows the 1024 samples of the synthetic measurement.
Preview shows the 1024 samples of the synthetic measurement.

Choose Dataset, time and signal

In Dataset sources assign guida.fft.misura to the role primary. The row is mandatory and its Remove is disabled. Use Independent (uniform sample axis, e.g. time) primary.time_s and Signal variable / channel to analyse primary.signal. The menu of each field shows auto and the fields of the source. Assign the two roles according to the meaning of the column. auto delegates the resolution to the module. Choose the time axis in seconds explicitly if you want to check the peaks in Hz. The axis must increase with a uniform step and the chosen values must be finite.

Data selection (optional X/time interval) accepts a saved X selection for the same source. None uses the available record. In temporal_set leave this selection at None and use any Parent Selection in the set definition.

Starting configuration with a primary Dataset and explicit bindings.
Starting configuration with a primary Dataset and explicit bindings.

To save a test interval, plot time_s and signal of the source with Scientific Dataset Plot. In Plots select that plot, use Data / Variants → Select data…, choose the series and Draw area in graph. Draw a rectangle between about 0.20 and 0.70 s that covers the height of the curve. Press Save Selection and close the dialog. In the FFT choose sel_001 in Data selection and run full_record. In the test the interval contains 512 samples, from about 0.2002 to 0.6992 s.

A selection on the source plot is saved as a reusable interval.
A selection on the source plot is saved as a reusable interval.

Process all samples, one block or a Temporal Set

Analysis mode
full_record, the default, transforms the whole source or the chosen interval. fixed_block takes a single block. temporal_set publishes an independent spectrum for each member of the set. Each member uses its own frequency grid. Separate regions stay distinct.
FFT length (fixed block; Auto = full record)
auto goes with full_record. For fixed_block choose the number of samples explicitly among 16384, 32768, 65536, 131072, 262144, 524288 or 1048576. The length must fit within the usable samples. In fixed_block, auto causes a run error.
Block position
start starts from the first sample, center centers the block in the selected record and is the default, explicit uses Explicit block start sample. Enter a zero-based index, initially 0. The last sample of the block must fall inside the record or the selection.
Temporal Set
In temporal_set replace None with a Window Set or Segment Set of the same source and the same time variable. The mode requires at least one effective member and at least eight finite samples per member. The FFT button does not create the set.

For the temporal test, enable the source in Dataset → Temporal Sets… → New Window Set…. Set Label to Quattro finestre FFT, Temporal variable to time_s, Parent Selection to None, Basis to Samples, Window size and Step to 256 and Partial window to Drop. Press Save. With Duration, size and step are expressed in the selected Duration unit . Include includes the last incomplete block if there is one. In Analysis choose temporal_set and the saved set. Four 256-sample windows at 1024 Hz give four spectra with a frequency step of 4 Hz.

Window Set defined on the same time variable used by the FFT.
Window Set defined on the same time variable used by the FFT.

The original lab has fewer samples than the minimum block. For a fixed_blocktest, start from the Generator CSV (ZIP) and download extend_fft_example.py (ZIP). Run the command below. The resulting file repeats the Generator waveform 20 times, keeping the 1024 Hz grid. Import it as guida.fft.estesa and assign the same units.

python3 extend_fft_example.py fft_example.csv fft_example_20s.csv

Choose fixed_block, length 16384, and try start, center and explicit with index 1024. On 20,480 samples the report gives 0–16,383, 2048–18,431 and 1024–17,407 respectively. The frequency step is 0.0625 Hz.

In P011-bis, when you move from a Dataset with a Temporal Set selected to another source, the field can show None and the Run can still reject the old set as incompatible. Go back to the previous source, choose None explicitly and then select the new one. The block computation succeeded after this step.

Explicit 16,384-sample block with starting sample 1024.
Explicit 16,384-sample block with starting sample 1024.

Set the window, fundamental and quality measures

Control
FFT window
Choices and effect
rectangular weights the samples uniformly and uses a narrow lobe. hann, the default, tapers the ends of the block. hamming uses a weighting with residual ends. blackman_harris attenuates the side lobes more strongly. flat_top favors the amplitude estimate over a wider lobe. The report gives the window and the estimate used.
Control
Pre-FFT detrend
Choices and effect
none keeps the signal, mean subtracts the mean and is the default, linear subtracts the estimated linear trend before windowing.
Control
Fundamental frequency
Choices and effect
auto_peak, the default, searches for the reference peak. With explicit enter in Explicit fundamental [Hz] the expected frequency within the domain. The field is empty by default and becomes required in explicit. In the lab use 50 Hz.
Control
Harmonics to track for THD (2..K)
Choices and effect
Maximum order number K, initially 10. The module searches for multiples starting from the second within the usable FFT range. Changing K can change the THD.
Control
SFDR spur search
Choices and effect
all_nonfundamental, the default, also counts the harmonics among the admitted spurs. nonharmonic_only removes the regions of the tracked harmonics from the search. The 120 Hz tone of the lab is distinct from the multiples of 50 Hz.
Control
Guard bins excluded around each tracked line
Choices and effect
Number of guard bins around each line. Start from 2. It changes the width of the neighborhood used or excluded in the measurements. One bin is fs/N Hz.
Run with a rectangular window, an explicit fundamental and a search for non-harmonic spurs.
Run with a rectangular window, an explicit fundamental and a search for non-harmonic spurs.

Run and read the spectrum, metadata and report

  1. In Analysis configure full_record, hann and the lab bindings. In Run reread the plan and start the analysis. Completion is indicated by the message Selective analysis completed. After an error, check the date and origin of the output, because a previous Dataset may still be visible.
  2. In Dataset select guida.fft.misura.spectrum, contract spectrum.table. Preview identifies the result. Use Open Dataset → Canonical table to read frequency_Hz, amplitude and magnitude_dBc. In Metadata read analysis.statistical_results. Technical details shows the payload identity and the provenance. In temporal_set open instead each variant .spectrum.tset_001.win_….
  3. In Results open fft_report.txt for steps, sampling frequency, resolved fundamental and results. The report gives a 1 Hz step on the 1024-sample record. The lines at 50 and 120 Hz are the two expected tones. THD uses the tracked harmonics, SFDR uses the largest admitted spur and SINAD includes the power remaining after the declared exclusions. The effective number of bits estimated from SINAD uses the ideal full-scale quantizer convention.

This module publishes a numerical spectrum and a report. In the test the panel Plots did not add an automatic plot. To display them, use the separate module Scientific Dataset Plot with the source guida.fft.misura.spectrum. In Scientific dataset 2D → Series… choose frequency_Hz for X and amplitude for Y, save the series and start the module. In Plots select Scientific dataset 2D. The two peaks match the components of the Generator.

Scientific Dataset Plot shows the peaks of the already published FFT spectrum.
Scientific Dataset Plot shows the peaks of the already published FFT spectrum.
513-row canonical table of the FFT result on the 1024-sample record.
513-row canonical table of the FFT result on the 1024-sample record.
The published Dataset exposes the statistical metadata of the computation.
The published Dataset exposes the statistical metadata of the computation.