#wav #plot #fft #spectrum #rust

app fft-analyzer

A Rust program that reads a .wav file, performs an FFT, and generates a PNG plot of the frequency spectrum

4 releases

0.1.3 Nov 21, 2024
0.1.2 Nov 18, 2024
0.1.1 Nov 18, 2024
0.1.0 Nov 18, 2024

#98 in Math

Download history 420/week @ 2024-11-18 56/week @ 2024-12-02 161/week @ 2024-12-09

637 downloads per month

MIT license

1.5MB
55 lines

FFT Analyzer

Overview

This Rust program reads a .wav audio file, performs a Fast Fourier Transform (FFT) on the audio data, and generates a .png plot of the frequency spectrum. The included audio file, waves.wav, is a recording of ocean waves, which is rich in diverse frequencies. The resulting FFT plot helps visualize the frequency content of the audio.

Features

Reads .wav files and extracts audio samples. Performs FFT to analyze the frequency spectrum. Plots the magnitude of frequencies in decibels (dB) using the plotters crate. Saves the plot as an image (fft_output.png).

##Prerequisites To run this project, you'll need: Rust (latest stable version). If you don't have Rust installed, you can download it from rust-lang.org. The following Rust crates: hound for reading .wav files. rustfft for performing the FFT. plotters for generating plots.

Installation & Setup

Clone the repository and navigate into the project directory:

git clone <repository-url>
cd fft-analyzer

Install the required dependencies:

cargo build

Once the dependencies are installed, run the program using:

cargo run

The program will:

  • Read the included waves.wav file
  • Perform an FFT on the audio samples
  • Generate a plot of the frequency spectrum in fft_output.png

Customizing the Input

If you wish to analyze a different .wav file, replace the existing waves.wav file in the project directory with your own. Ensure that the new file has the same name (waves.wav) or modify the source code to use a different file name.

Dependencies

The Cargo.toml file includes the following dependencies:

[dependencies]
hound = "3.4"
rustfft = "6.1"
plotters = "0.3.1"

License

This project is licensed under the MIT License

Acknowledgments

Rust community and documentation Crate maintainers for hound, rustfft, and plotters

Author

bensatlantik

Dependencies

~9.5MB
~165K SLoC