Skip to content

RoshanGamage01/Discrete-Fourier-transform

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Audio Signal Processing

This repository contains Python scripts for performing Discrete Fourier Transform (DFT) and Inverse Discrete Fourier Transform (IDFT) on audio signals. The project includes functionality to visualize the frequency spectrum of an audio signal and save the processed audio back to a file.

Project Structure

  • audio_signal/: Directory containing audio files.
  • dft.py: Contains functions for DFT and IDFT.
  • index.py: Main script to process audio files.
  • util.py: Utility functions for audio file operations.
  • requirements.txt: List of dependencies.

Installation

  1. Clone the repository:

    git clone https://github.com/RoshanGamage01/Discrete-Fourier-transform.git
    cd Discrete-Fourier-transform
  2. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate  # On Windows use `venv\Scripts\activate`
  3. Install the required packages:

    pip install -r requirements.txt

Usage

  1. Place your audio file in the audio_signal/ directory.

  2. Run the main script:

    python index.py
  3. The script will:

    • Read the audio file.
    • Perform DFT to compute the frequency spectrum.
    • Plot the frequency spectrum.
    • Perform IDFT to reconstruct the audio signal.
    • Save the reconstructed audio signal to idft_output.wav.

Functions

dft.py

  • dft(signal_data: np.ndarray, sample_rate: int) -> dict

    • Computes the Discrete Fourier Transform of the input signal.
    • Returns a dictionary containing DFT coefficients and the sample rate.
  • idft(dft_coefficients: np.ndarray, sample_size: int) -> np.ndarray

    • Computes the Inverse Discrete Fourier Transform of the DFT coefficients.
    • Returns the reconstructed time-domain signal.

util.py

  • save_as_audio_file(idft_values: np.ndarray, sample_rate: int, file_name: str)
    • Saves the IDFT values as an audio file.

Dependencies

  • numpy
  • matplotlib
  • wave
  • tqdm

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

Releases

No releases published

Packages

No packages published

Languages