Skip to content

electromake/AccelSpectra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AccelSpectra

AccelSpectra is a real-time Three axes USB Accelerometer spectrum analyzer. It reads tri-axis accelerometer samples from a serial device, processes the X/Y/Z vibration data with FFTW, and displays a live frequency spectrum in a Qt 6 desktop interface.

Use AccelSpectra for accelerometer FFT analysis, vibration measurement, motion sensor diagnostics, resonance checks, and embedded sensor development workflows where raw serial accelerometer data needs to become an interactive spectrum plot quickly.

Features

  • Real-time serial accelerometer acquisition over Qt SerialPort.
  • Live X, Y, and Z axis FFT spectrum visualization with Qt Charts.
  • Selectable accelerometer sampling frequency from 0.1 Hz to 3200 Hz.
  • Selectable accelerometer measurement range: 2 g, 4 g, 8 g, or 16 g.
  • Configurable FFT window size: 64, 128, 256, 512, 1024, 2048, or 4096 samples.
  • Window functions: Blackman, Hamming, Hann, and Rectangular.
  • FFT hop size controls: 25%, 50%, 75%, and 100%.
  • Logarithmic magnitude axis and frequency axis scaled to Nyquist frequency.
  • Per-channel visibility toggles for X, Y, and Z spectra.
  • C++20 core library with unit tests for DSP, parsing, buffering, windows, spectrum data, and application control.

Technology Stack

  • C++20
  • CMake 3.28 or newer
  • Qt 6 Core, Widgets, SerialPort, and Charts
  • FFTW3
  • GoogleTest
  • CTest

Application Overview

AccelSpectra is split into a reusable processing core and a Qt desktop executable:

  • src/device handles serial communication and USB accelerometer commands.
  • src/data contains signal buffers, spectrum storage, serial parsing, and circular buffer logic.
  • src/dsp contains FFT processing and signal window implementations.
  • src/services coordinates serial input, DSP configuration, FFT execution, and device commands.
  • src/ui contains the Qt main window and live chart controls.
  • tests contains GoogleTest-based unit tests.

Supported Serial Data Format

The application expects newline-delimited tri-axis integer samples:

x,y,z\n

Example:

12,-4,255
13,-5,251

The serial port is opened with:

  • Baud rate: 115200
  • Data bits: 8
  • Parity: none
  • Stop bits: 1
  • Flow control: none

Parsed raw integer samples are scaled internally with 9.81 / 255.0, DC offset is removed, the selected window function is applied, and FFTW calculates the frequency-domain spectrum for each axis.

Device Commands

When a serial port is opened, AccelSpectra sends the current device configuration to the connected accelerometer. The application supports these command families:

FREQ 3200
FREQ 1600
FREQ 800
FREQ 400
FREQ 200
FREQ 100
FREQ 50
FREQ 25
FREQ 12.5
FREQ 6.25
FREQ 3.13
FREQ 1.56
FREQ 0.78
FREQ 0.39
FREQ 0.20
FREQ 0.10
RANGE 2
RANGE 4
RANGE 8
RANGE 16
START
STOP

Requirements

Ubuntu 24.04

Install the compiler, CMake, Qt 6, FFTW3, and GoogleTest packages:

sudo apt update
sudo apt install \
  build-essential \
  cmake \
  pkg-config \
  qt6-base-dev \
  libqt6serialport6-dev \
  libqt6charts6-dev \
  libfftw3-dev \
  libgtest-dev

For serial hardware access, your user may need membership in the dialout group:

sudo usermod -aG dialout "$USER"

Log out and log back in after changing group membership.

Build

Configure and build a release binary:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j

The application executable is created at:

build/accel_spectra

Run it with:

./build/accel_spectra

Test

Build with tests enabled, then run CTest:

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON
cmake --build build -j
ctest --test-dir build --output-on-failure

You can also run the test executable directly:

./build/accel_spectra_tests

The current test suite covers:

  • Application controller configuration and state changes.
  • FFT pipeline behavior.
  • Signal window operations.
  • Spectrum storage.
  • Serial parser validation.
  • SPSC vector circular buffer behavior.
  • DSP window functions.

CMake Options

AccelSpectra exposes these project-specific CMake options:

Option Default Description
ACCEL_SPECTRA_WARNINGS_AS_ERRORS OFF Treat compiler warnings as errors.
ACCEL_SPECTRA_ENABLE_ASAN OFF Enable AddressSanitizer.
ACCEL_SPECTRA_ENABLE_UBSAN OFF Enable UndefinedBehaviorSanitizer.
ACCEL_SPECTRA_ENABLE_TSAN OFF Enable ThreadSanitizer.

Example sanitizer build:

cmake -S . -B build-asan \
  -DCMAKE_BUILD_TYPE=Debug \
  -DBUILD_TESTING=ON \
  -DACCEL_SPECTRA_ENABLE_ASAN=ON \
  -DACCEL_SPECTRA_ENABLE_UBSAN=ON

cmake --build build-asan -j
ctest --test-dir build-asan --output-on-failure

AddressSanitizer and ThreadSanitizer cannot be enabled together.

AppImage Build

Prebuilt Linux AppImage packages are available from the AccelSpectra GitHub page. Use the AppImage when you want to run the application without compiling it from source.

Create a release build without tests:

cmake -S . -B build-appimage -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=OFF
cmake --build build-appimage -j

Download linuxdeploy and the Qt plugin:

wget -O resources/linuxdeploy-x86_64.AppImage \
  https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage

wget -O resources/linuxdeploy-plugin-qt-x86_64.AppImage \
  https://github.com/linuxdeploy/linuxdeploy-plugin-qt/releases/download/continuous/linuxdeploy-plugin-qt-x86_64.AppImage

chmod +x resources/linuxdeploy-x86_64.AppImage resources/linuxdeploy-plugin-qt-x86_64.AppImage

Prepare the AppDir:

rm -rf AppDir
mkdir -p AppDir/usr/bin
mkdir -p AppDir/usr/share/applications
mkdir -p AppDir/usr/share/icons/hicolor/256x256/apps

cp build-appimage/accel_spectra AppDir/usr/bin/
cp resources/accel_spectra.desktop AppDir/usr/share/applications/accel_spectra.desktop
cp resources/accel_spectra.png AppDir/usr/share/icons/hicolor/256x256/apps/accel_spectra.png

Build the AppImage:

QMAKE=/usr/lib/qt6/bin/qmake6 resources/linuxdeploy-x86_64.AppImage \
  --appdir AppDir \
  --desktop-file AppDir/usr/share/applications/accel_spectra.desktop \
  --icon-file AppDir/usr/share/icons/hicolor/256x256/apps/accel_spectra.png \
  --plugin qt \
  --output appimage

Usage

  1. Connect a compatible USB accelerometer or serial device.

  2. Start AccelSpectra:

    ./build/accel_spectra
  3. Select the serial port and click Open.

  4. Choose the accelerometer sampling frequency and range.

  5. Select the FFT window type, window size, and hop size.

  6. Use the X, Y, and Z checkboxes to show or hide individual spectrum channels.

  7. Use Start and Stop to control streaming on supported firmware.

Keywords

accelerometer spectrum analyzer, accelerometer FFT, vibration spectrum analyzer, real-time FFT Qt, USB accelerometer software, serial accelerometer plotter, C++ Qt FFTW, motion sensor frequency analysis, tri-axis accelerometer visualization, Linux vibration analysis tool.

License

AccelSpectra is licensed under the GNU General Public License v3.0. See LICENSE for details.

Copyright (C) 2026 Electromake

About

AccelSpectra is a real-time USB accelerometer spectrum analyzer. It reads tri-axis accelerometer samples from a serial device, processes the X/Y/Z vibration data with FFTW, and displays a live frequency spectrum in a Qt 6 desktop interface.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Packages

 
 
 

Contributors