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.
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.
-
Clone the repository:
git clone https://github.com/RoshanGamage01/Discrete-Fourier-transform.git cd Discrete-Fourier-transform
-
Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Place your audio file in the
audio_signal/
directory. -
Run the main script:
python index.py
-
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
.
-
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.
save_as_audio_file(idft_values: np.ndarray, sample_rate: int, file_name: str)
- Saves the IDFT values as an audio file.
numpy
matplotlib
wave
tqdm
This project is licensed under the MIT License. See the LICENSE file for details.