Metadata-Version: 2.4
Name: aifourier
Version: 3.0.1
Summary: AI-based Fourier Analysis using sinusoidal neural networks
Author: Jovan
License: MIT License
        
        Copyright (c) 2026 Jovan-AIcoder
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/jovan-AIcoder/AI-Based-Fourier-Analysis
Project-URL: Issues, https://github.com/jovan-AIcoder/AI-Based-Fourier-Analysis/issues
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pandas
Requires-Dist: matplotlib
Requires-Dist: tensorflow
Requires-Dist: librosa
Dynamic: license-file

# AI-Based Fourier Analysis (aifourier)

![aifourier_logo](https://raw.githubusercontent.com/jovan-AIcoder/AI-Based-Fourier-Analysis/main/aifourier_logo.png)

> *“Machines can learn Fourier analysis.”*

A Python library that approximates Fourier decomposition using a sinusoidal neural network.

Instead of explicitly computing Fourier integrals, this library **learns** the frequency components of a signal through optimization.

---

## ✨ Features

* 🔊 Analyze audio signals (`.wav`, `.mp3`, `.flac`, `.ogg`)
* 🧠 Neural network with sinusoidal activation
* 📊 Extract:

  * Frequencies in Hz
  * Phase shift
  * Amplitude
* ⚡ Simple one-line API
* 📁 Output as Pandas DataFrame

---

## 📦 Installation

```bash
pip install aifourier
```

---

## 🚀 Usage

```python
import aifourier as aif

df = aif.analyze("audio.mp3")

print(df.head())
```

---

## 📊 Output

The result is a DataFrame containing:

| Column      | Description                        |
| ----------- | ---------------------------------- |
| Frequencies | Learned frequencies (Hz)    |
| Phase shift | Phase of each component            |
| Amplitudes  | Contribution strength of each mode |

---

## 🧠 How It Works

The signal is approximated as:

y(t) ≈ Σ Aᵢ sin(ωᵢ t + φᵢ)

Where:

* Aᵢ = amplitude
* ωᵢ = angular frequency
* φᵢ = phase

These parameters are learned by a neural network instead of computed analytically.

---

## ⚙️ Parameters

```python
aif.analyze(audio_path, max_modes=10000, epochs=256,use_phase_shift=True,learning_rate=0.00001,save_model=None,verbose=2,positive_freqs_only=True,abs_amplitudes=True,optimizer='adam')
```

* `audio_path` : Path to audio file.
* `max_modes`  : Number of sinusoidal components.
* `epochs`     : Training iterations (higher = better approximation).
* `use_phase_shift` : If this set to `False`, all phase shifts are set to zero.
* `learning_rate` : Learning rate of NN.
* `save_model` : Path to save learned model.
* `verbose` : Modes to show training behavior, which can be set to 0,1,2.
* `positive_freqs_only` : If this set to `True`, this will keep the positive frequencies and delete the negative ones.
* `abs_amplitudes` : If this set to `True`, all negative amplitudes will be positive-valued.
* `optimizer` : The optimizer for training.

---

## 📁 Example

See the `examples/` folder for a complete demo:

```bash
cd examples
python example.py
```

This will:

* Analyze `bird.mp3`
* Generate frequency components
* Save results
* Plot the spectrum

The frequency spectrum of `bird.mp3` is shown below:

![Spectrum of bird.mp3](https://raw.githubusercontent.com/jovan-AIcoder/AI-Based-Fourier-Analysis/main/examples/spectrum.png)

---

## ⚖️ Comparison with FFT

| Method    | Approach                    |
| --------- | --------------------------- |
| FFT       | Analytical, deterministic   |
| aifourier | Learning-based, approximate |

This project explores whether neural networks can **discover Fourier structure from data**.

---

## 🚧 Limitations

* Approximation quality depends on training
* Slower than FFT
* Results may vary between runs

---

## 💡 Future Ideas

* Signal reconstruction from learned parameters
* FFT comparison mode
* Real-time signal analysis (oscilloscope / radio)
* Complex-valued extensions

---

## 👤 Author

Jovan, 2026

---

## 📜 License

MIT License

---

> *“What Fourier derives analytically, neural networks can approximate through learning.”*
