GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - hexpad/dsp-spectrum-analyzer: Digital Signal Processing project implementing a spectrum analyzer from scratch

BranchesTags
Open more actions menu

Latest commit

 

History

9 Commits
9 Commits

Folders and files

NameName
Last commit message
Last commit date
images
images
 
 
src
src
 
 
.DS_Store
.DS_Store
 
 
README.md
README.md
 
 

Repository files navigation

DSP Spectrum Analyzer

This is a small C++ project I made to practice basic digital signal processing concepts like sampling, filtering and the Fourier transform.

What it does

The program first generates two sine waves, one at 3 Hz with amplitude 1.0 and one at 7 Hz with amplitude 0.5. Both are 1 second long and sampled at 200 Hz. The two signals are added together and then random noise (between -0.2 and +0.2) is added on top, so the result looks more like a real measured signal.

To clean the noise a simple moving average filter with window size 5 is applied. After that the program computes the DFT of both the noisy and the filtered signal to see the frequency content. Finally it searches for the biggest peak in the filtered spectrum and prints the peak frequency, which should come out around 3 Hz since that is the strongest component.

Files

  • main.cpp - runs the whole demo and writes the csv files
  • SignalGenerator.h / .cpp - class with all the signal functions (sine, square, noise, moving average, DFT, peak detection)

Build and run

g++ -std=c++11 main.cpp SignalGenerator.cpp -o spectrum_analyzer
./spectrum_analyzer

Output

The program prints the sample rate, number of samples, peak frequency and peak magnitude to the console. It also creates 4 csv files:

  • signal.csv - the noisy signal (time / amplitude)
  • filtered_signal.csv - the signal after the moving average
  • spectrum.csv - DFT magnitude of the noisy signal (frequency / magnitude)
  • filtered_spectrum.csv - DFT magnitude of the filtered signal

Plots

I plotted the csv files with csvplot.com

Noisy signal:

Noisy signal

Filtered signal, the noise is visibly reduced:

Filtered signal

Spectrum of the noisy signal, you can clearly see the two peaks at 3 Hz and 7 Hz:

Spectrum

Spectrum of the filtered signal:

Filtered spectrum

Source Code

https://github.com/hexpad/dsp-spectrum-analyzer/tree/main/src

About

Digital Signal Processing project implementing a spectrum analyzer from scratch

Topics

cppdftdspfourier-transformmoving-average-filtersignal-generatorsignal-processingspectrum-analyzer

Resources

Readme
Activity

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.