Fourier filtering removes unwanted repeating patterns and high-frequency noise from spectral data. It changes each row to a frequency description, keeps the chosen frequencies, and changes the row back to its original form. Rows are samples and columns are channels.
The FourierFiltering app lets users draw the frequencies to keep, inspect the filtered result, apply the calculation to all rows, and export the data.
addpath('path/to/FourierFiltering')
FourierFiltering_test
app = FourierFiltering(spectra);The constructor accepts a numeric matrix or a struct with spectra and an
optional wavelengths field. The empty constructor opens the data selector.
If no x-axis is supplied, channel numbers are used.
The frequency axis is measured in cycles per channel, from 0 to 0.5. A supplied
wavelength vector is used for the plot; the filter works on channel positions.
Intervals are inclusive and are represented as an M-by-2 matrix:
intervals = [0.01 0.10; 0.15 0.25];The Frequency Intervals panel can import a finite real M-by-2 interval
matrix from the MATLAB workspace or export the current intervals back to a
workspace variable. Imported intervals are validated against the active
frequency range and overlapping ranges are merged.
In the window, drag on the frequency chart to create intervals, drag their
edges to resize them, and press Delete or Backspace to remove the selected
interval. The text form [0.01:0.10, 0.15:0.25] is also accepted.
The frequency plot shows how strongly each repeating pattern contributes to a row. For each row the calculation:
- mirrors the signal on both sides;
- computes a zero-padded FFT;
- keeps the selected positive-frequency bins and applies the same mask to the matching negative-frequency bins;
- performs the inverse FFT and returns the original-length centre segment.
The mirror extension reduces the jump at the ends of the signal. A transition width of zero gives a hard edge. A positive transition width gives a smooth raised-cosine edge, which can reduce ringing near the selected bands.
The FFT length must be at least three times the signal length because of the two-sided mirror. It is then rounded up to a power of two. The window uses the same length for the displayed frequency axis and the filter.
addpath(fullfile('path/to/FourierFiltering', 'business_logic'))
filter = FourierFilter();
n = size(spectra, 2);
nfft = 2^nextpow2(3*n);
frequency = 0.5 * linspace(0, 1, nfft/2 + 1);
intervals = filter.parseIntervals('[0.01:0.10, 0.15:0.25]');
intervals = filter.mergeRanges(intervals);
[filtered, fftValues] = filter.filter(spectra(1,:), intervals, ...
nfft, frequency, 0);filtered keeps the row or column shape of the input. Empty intervals return
the original signal and an empty FFT.
After Apply, app.getData() returns the filtered matrix, the original
matrix, the x-axis, the selected intervals, and parameter information. The app
shows one selected sample in the signal and frequency previews before applying.
The sample selector makes it possible to inspect different rows. The preview
shows only the selected sample by default to avoid copying a full dataset into
the UI. Show all spectra in the preview chart options loads all input rows on
demand when the dataset is within the safe 500,000-point preview limit. Apply
filters every row, and the result can then be shown as sampled or full result
rows. Display choices do not change the exported data.
FourierFiltering_test.m creates spectra with peaks, baseline drift, periodic
interference, and high-frequency noise. Run it with:
FourierFiltering_test
app = FourierFiltering(spectra);Run Code Analyzer from this folder:
checkcode('FourierFiltering.m', '-id')
checkcode('business_logic/@FourierFilter/FourierFilter.m', '-id')
checkcode('business_logic/@DataValidator/DataValidator.m', '-id')MATLAB R2022a or later is required. No additional toolbox is needed.
Oppenheim, A. V. and Schafer, R. W. (2010). Discrete-Time Signal Processing, 3rd ed. Pearson.
Harris, F. J. (1978). On the use of windows for harmonic analysis with the discrete Fourier transform. Proceedings of the IEEE, 66(1), 51-83.
License: MIT