Metadata-Version: 2.4
Name: aifourier
Version: 4.0.0
Summary: Python library for AI-based Fourier analysis of audio signals, powered by Sinusoidal Neural Networks (SNN).
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
Requires-Dist: sinusoidalnn
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."*

**aifourier** is a Python library for AI-based Fourier analysis of audio signals, powered by **Sinusoidal Neural Networks (SNN)**.

SinusoidalNN repo link (made by Jovan also):
https://github.com/jovan-AIcoder/SinusoidalNN

Built on top of the **SinusoidalNN** python package framework, aifourier learns the frequency components of an audio signal through optimization instead of explicitly computing Fourier integrals.

---

## ✨ Features

- 🔊 Analyze audio files (`.wav`, `.mp3`, `.flac`, `.ogg`)
- 🌊 Built on top of **SinusoidalNN**
- 🧠 Neural Fourier decomposition via optimization
- 📊 Extract:
  - Frequencies (Hz)
  - Phase shifts
  - Amplitudes
- ⚙️ Multiple optimizers
  - SGD
  - RMSprop
  - Adam
  - AdamW
  - Adagrad
  - Adadelta
  - Adamax
  - Nadam
  - Ftrl
- 📈 Training MAE monitoring
- ➕ Optional positive-frequency filtering
- ➕ Optional absolute amplitudes
- 💾 Save trained neural models
- 📁 Pandas DataFrame output
- ⚡ Simple one-line API

---

## 📦 Installation

```bash
pip install aifourier
```

---

## 🚀 Usage

```python
import aifourier as aif

df = aif.analyze(
    "audio.mp3",
    optimizer="adam"
)

print(df.head())
```

---

## 📊 Output

The returned DataFrame contains:

| Column | Description |
|----------|-------------|
| Frequencies | Learned frequencies (Hz) |
| Phase shift | Learned phase shifts |
| Amplitudes | Learned amplitudes |

---

## 🧠 How It Works

Instead of evaluating Fourier coefficients analytically,

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

Where: 

- Aᵢ = amplitude 
- ωᵢ = angular frequency 
- φᵢ = phase shift 

these parameters are learned directly from data using a **Sinusoidal Neural Network**.

---

## ⚙️ Parameters

```python
aif.analyze(
    audio_path,
    max_modes=10000,
    epochs=256,
    use_phase_shift=True,
    learning_rate=1e-5,
    save_model=None,
    verbose=2,
    positive_freqs_only=True,
    abs_amplitudes=True,
    optimizer="adam"
)
```

| Parameter | Description |
|------------|-------------|
| `audio_path` | Audio file path |
| `max_modes` | Maximum number of sinusoidal modes |
| `epochs` | Number of training epochs |
| `use_phase_shift` | Learn phase shifts |
| `learning_rate` | Optimizer learning rate |
| `save_model` | Save trained model |
| `verbose` | Training verbosity (`0`, `1`, `2`) |
| `positive_freqs_only` | Keep only positive frequencies |
| `abs_amplitudes` | Return absolute amplitudes |
| `optimizer` | Training optimizer |

---

## 📁 Example

See the `examples/` folder:

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

Example workflow:

- Analyze `bird.mp3`
- Learn sinusoidal spectrum
- Export frequency table
- Plot the learned spectrum

The learned spectrum is shown below.

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

---




---

## 🌊 Relationship with SinusoidalNN

```
SinusoidalNN
        │
        ▼
   aifourier
```

**SinusoidalNN** provides the neural network engine.

**aifourier** provides an easy-to-use interface for AI-based Fourier analysis of audio signals.

---



## 💡 Future Ideas

- Audio reconstruction
- FFT comparison utilities
- Real-time microphone analysis
- Radio signal analysis
- Oscilloscope support
- Complex-valued SinusoidalNN

---

## 👤 Author

**Jovan**

2026

---

## 📜 License

MIT License

---

> *"What Fourier derives analytically, Sinusoidal Neural Networks can approximate through learning."*
