aifourier 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jovan-AIcoder
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: aifourier
3
+ Version: 0.1.0
4
+ Summary: AI-based Fourier Analysis using sinusoidal neural networks
5
+ Author: Jovan
6
+ Requires-Python: >=3.8
7
+ License-File: LICENSE
8
+ Requires-Dist: numpy
9
+ Requires-Dist: pandas
10
+ Requires-Dist: matplotlib
11
+ Requires-Dist: tensorflow
12
+ Requires-Dist: librosa
13
+ Dynamic: author
14
+ Dynamic: license-file
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
@@ -0,0 +1,143 @@
1
+ # AI-Based Fourier Analysis (aifourier)
2
+
3
+ > *“Machines can learn Fourier analysis.”*
4
+
5
+ A Python library that approximates Fourier decomposition using a sinusoidal neural network.
6
+
7
+ Instead of explicitly computing Fourier integrals, this library **learns** the frequency components of a signal through optimization.
8
+
9
+ ---
10
+
11
+ ## ✨ Features
12
+
13
+ * 🔊 Analyze audio signals (`.wav`, `.mp3`, `.flac`, `.ogg`)
14
+ * 🧠 Neural network with sinusoidal activation
15
+ * 📊 Extract:
16
+
17
+ * Angular frequency
18
+ * Phase shift
19
+ * Amplitude
20
+ * ⚡ Simple one-line API
21
+ * 📁 Output as Pandas DataFrame
22
+
23
+ ---
24
+
25
+ ## 📦 Installation
26
+
27
+ ```bash
28
+ pip install aifourier
29
+ ```
30
+
31
+ ---
32
+
33
+ ## 🚀 Usage
34
+
35
+ ```python
36
+ import aifourier as aif
37
+
38
+ df = aif.analyze("audio.mp3", max_modes=128, epochs=300)
39
+
40
+ print(df.head())
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 📊 Output
46
+
47
+ The result is a DataFrame containing:
48
+
49
+ | Column | Description |
50
+ | ----------- | ---------------------------------- |
51
+ | Frequencies | Learned angular frequencies (ω) |
52
+ | Phase shift | Phase of each component |
53
+ | Amplitudes | Contribution strength of each mode |
54
+
55
+ ---
56
+
57
+ ## 🧠 How It Works
58
+
59
+ The signal is approximated as:
60
+
61
+ y(t) ≈ Σ Aᵢ sin(ωᵢ t + φᵢ)
62
+
63
+ Where:
64
+
65
+ * Aᵢ = amplitude
66
+ * ωᵢ = frequency
67
+ * φᵢ = phase
68
+
69
+ These parameters are learned by a neural network instead of computed analytically.
70
+
71
+ ---
72
+
73
+ ## ⚙️ Parameters
74
+
75
+ ```python
76
+ aif.analyze(audio_path, max_modes=128, epochs=64)
77
+ ```
78
+
79
+ * `audio_path` : Path to audio file
80
+ * `max_modes` : Number of sinusoidal components
81
+ * `epochs` : Training iterations (higher = better approximation)
82
+
83
+ ---
84
+
85
+ ## 📁 Example
86
+
87
+ See the `examples/` folder for a complete demo:
88
+
89
+ ```bash
90
+ cd examples
91
+ python example.py
92
+ ```
93
+
94
+ This will:
95
+
96
+ * Analyze `bird.mp3`
97
+ * Generate frequency components
98
+ * Save results
99
+ * Plot the spectrum
100
+
101
+ ---
102
+
103
+ ## ⚖️ Comparison with FFT
104
+
105
+ | Method | Approach |
106
+ | --------- | --------------------------- |
107
+ | FFT | Analytical, deterministic |
108
+ | aifourier | Learning-based, approximate |
109
+
110
+ This project explores whether neural networks can **discover Fourier structure from data**.
111
+
112
+ ---
113
+
114
+ ## 🚧 Limitations
115
+
116
+ * Approximation quality depends on training
117
+ * Slower than FFT
118
+ * Results may vary between runs
119
+
120
+ ---
121
+
122
+ ## 💡 Future Ideas
123
+
124
+ * Signal reconstruction from learned parameters
125
+ * FFT comparison mode
126
+ * Real-time signal analysis (oscilloscope / radio)
127
+ * Complex-valued extensions
128
+
129
+ ---
130
+
131
+ ## 👤 Author
132
+
133
+ Jovan
134
+
135
+ ---
136
+
137
+ ## 📜 License
138
+
139
+ MIT License
140
+
141
+ ---
142
+
143
+ > *“What Fourier derives analytically, neural networks can approximate through learning.”*
@@ -0,0 +1,3 @@
1
+ from .analyzer import analyze
2
+
3
+ __all__ = ["analyze"]
@@ -0,0 +1,45 @@
1
+ import os
2
+ import pandas as pd
3
+ import librosa
4
+ import numpy as np
5
+ from tensorflow import keras
6
+ from tensorflow import math
7
+ def analyze(audio_path,max_modes=128,epochs=64):
8
+ # error handling
9
+ if not isinstance(audio_path, str):
10
+ raise ValueError('Audio path must be a string.')
11
+ if not isinstance(max_modes, int) or max_modes <= 0:
12
+ raise ValueError('Max modes must be a positive integer.')
13
+ if not isinstance(epochs, int) or epochs <= 0:
14
+ raise ValueError('Epochs must be a positive integer.')
15
+ try:
16
+ if not os.path.isfile(audio_path):
17
+ raise ValueError("Audio file not found.")
18
+ except Exception as e:
19
+ raise ValueError(f'Error accessing audio file: {e}')
20
+ if not audio_path.endswith(('.wav', '.mp3', '.flac', '.ogg')):
21
+ raise ValueError('Unsupported audio format. Supported formats are: .wav, .mp3, .flac, .ogg')
22
+ # audio sampling
23
+ print('Sampling the audio signal...')
24
+ a, b = librosa.load(audio_path, mono=True)
25
+ duration = librosa.get_duration(y=a, sr=b)
26
+ time = np.linspace(0, duration, len(a))
27
+ df = pd.DataFrame({'time': time,'amplitude': a})
28
+ t = df['time'] * 1000000 # convert to microseconds
29
+ y = df['amplitude']
30
+ print('Audio signal sampled successfully.')
31
+ # analyze the audio signal
32
+ model = keras.Sequential([
33
+ keras.layers.Dense(max_modes, activation=math.sin, input_shape=(1,)),
34
+ keras.layers.Dense(1,use_bias=False)
35
+ ])
36
+ model.compile(optimizer='adam', loss='mean_squared_error')
37
+ print('Analyzing the audio signal...')
38
+ model.fit(t.values.reshape(-1, 1), y.values, epochs=epochs)
39
+ weights, biases = model.layers[0].get_weights()
40
+ amplitudes = model.layers[1].get_weights()[0]
41
+ weights_flat = weights[0]
42
+ df_freq = pd.DataFrame({'Frequencies': weights_flat,'Phase shift': biases,'Amplitudes': amplitudes.flatten()})
43
+ df_freq.index = [f'Frequency_{i}' for i in range(len(biases))]
44
+ print('Audio signal analyzed successfully.')
45
+ return df_freq
@@ -0,0 +1,17 @@
1
+ Metadata-Version: 2.4
2
+ Name: aifourier
3
+ Version: 0.1.0
4
+ Summary: AI-based Fourier Analysis using sinusoidal neural networks
5
+ Author: Jovan
6
+ Requires-Python: >=3.8
7
+ License-File: LICENSE
8
+ Requires-Dist: numpy
9
+ Requires-Dist: pandas
10
+ Requires-Dist: matplotlib
11
+ Requires-Dist: tensorflow
12
+ Requires-Dist: librosa
13
+ Dynamic: author
14
+ Dynamic: license-file
15
+ Dynamic: requires-dist
16
+ Dynamic: requires-python
17
+ Dynamic: summary
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.py
5
+ aifourier/__init__.py
6
+ aifourier/analyzer.py
7
+ aifourier.egg-info/PKG-INFO
8
+ aifourier.egg-info/SOURCES.txt
9
+ aifourier.egg-info/dependency_links.txt
10
+ aifourier.egg-info/requires.txt
11
+ aifourier.egg-info/top_level.txt
@@ -0,0 +1,5 @@
1
+ numpy
2
+ pandas
3
+ matplotlib
4
+ tensorflow
5
+ librosa
@@ -0,0 +1 @@
1
+ aifourier
@@ -0,0 +1,3 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,17 @@
1
+ from setuptools import setup, find_packages
2
+
3
+ setup(
4
+ name="aifourier",
5
+ version="0.1.0",
6
+ description="AI-based Fourier Analysis using sinusoidal neural networks",
7
+ author="Jovan",
8
+ packages=find_packages(),
9
+ install_requires=[
10
+ "numpy",
11
+ "pandas",
12
+ "matplotlib",
13
+ "tensorflow",
14
+ "librosa"
15
+ ],
16
+ python_requires=">=3.8",
17
+ )