SinusoidalNN
A TensorFlow-based Sinusoidal Neural Network (SNN) for signal decomposition, spectral analysis, and signal reconstruction.
Overview
SinusoidalNN is a Python package that represents a signal as a trainable superposition of sinusoidal components.
Instead of using a conventional Fourier Transform, SinusoidalNN learns frequencies, amplitudes, and phase shifts directly through gradient descent using TensorFlow.
Signal representation:
y(t) = Σ Ai sin(2πfi t + φi)
where:
- fi = learned frequency
- Ai = learned amplitude
- φi = learned phase shift
The package provides:
- Signal fitting
- Spectrum extraction
- Signal reconstruction
- Model saving and loading
- Signal preprocessing
- TensorFlow optimizer support
Installation
pip install sinusoidalnn
Try the Demo First
Before writing any code, it is recommended to explore the example project.
Inside the repository:
examples/
├── demo.py
├── signal_value.py
├── signal_original.csv
Run:
python demo.py
The demo will:
- Load a signal from CSV
- Train a SinusoidalNN model
- Save the trained model
- Extract the learned spectrum
- Plot the spectrum
- Reconstruct the signal
- Save the reconstructed signal
Generated files:
model_demo.h5
spectrum.csv
spectrum.png
signal_reconstructed.csv
signal_comparison.png
This is the fastest way to understand how SinusoidalNN works. To demonstrate loading model and print the signal value at arbitrary time, run signal_value.py instead.
Quick Start
Import Package
from sinusoidalnn import SNN
Load Signal
import pandas as pd
df = pd.read_csv("signal.csv")
t = df["Time"]
y = df["Signal"]
Create Model
snn = SNN(
max_modes=10000,
optimizer="adam",
learning_rate=1e-5,
verbose=1
)
Fit Signal
snn.fit_signal(
t,
y,
epochs=200
)
Extract and Plot Spectrum
spectrum = snn.return_spectrum(
show_spectrum = True,
save_spectrum = "examples/spectrum.png")
Example:
Frequencies Phase shift Amplitudes
0 49.99 0.12 0.998
1 120.03 -0.31 0.502
...
Reconstruct Signal
signal = snn.reconstruct_signal(
duration=1.0,
sample_rate=1000
)
Example Output:
Time Signal
0 0.0000 0.0123
1 0.0010 0.5234
...
Save Model
snn.save_model(
"my_model.h5"
)
Load Model
snn.load_SNN_model(
"my_model.h5"
)
Return Signal Value at Arbitrary Time
snn.signal_value(
[[2.5]]
)
Signal Preprocessing
Baseline Removal
from sinusoidalnn import zeroing_baseline
y = zeroing_baseline(y)
Removes DC offset from a signal by subtracting its mean value.
Supported Optimizers
SinusoidalNN supports:
- SGD
- RMSprop
- Adam
- AdamW
- Adagrad
- Adadelta
- Adamax
- Nadam
- FTRL
Example:
snn = SNN(
optimizer="adamw"
)
API Reference
SNN
SNN(
max_modes=10000,
use_phase_shift=True,
optimizer="adam",
learning_rate=1e-4,
verbose=2,
time_scaling=1e6
)
Builds SNN model.
fit_signal
fit_signal(
t,
y,
epochs=256
)
Train the model on a signal.
return_spectrum
return_spectrum(
positive_freqs_only=True,
abs_amplitudes=True,
show_spectrum = False,
save_spectrum = None
)
Extract learned frequencies, amplitudes, and phase shifts. The spectrum plot preview can be plotted if needed (by setting show_spectrum = True and save_spectrum to desired folder path).
reconstruct_signal
reconstruct_signal(
start_time=0.0,
duration=5.0,
sample_rate=44100
)
Generate a reconstructed signal using the learned sinusoidal representation.
save_model
save_model(path)
Save the TensorFlow model.
load_SNN_model
load_SNN_model(path)
Load a previously saved model.
signal_value
snn.signal_value(
[[2.5]]
)
Returns signal value at arbitrary time.
Dependencies
- TensorFlow
- NumPy
- Pandas
- Matplotlib
License
MIT License
Repository
https://github.com/jovan-AIcoder/SinusoidalNN
Author
Jovan
Citation
If you use SinusoidalNN in research, academic work, scientific reports, or publications, please cite the repository and acknowledge the package appropriately.
Metadata
Release files for sinusoidalnn 5.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sinusoidalnn-5.0.0.tar.gz | 10.2 kB | With provenance | Details for sinusoidalnn-5.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sinusoidalnn-5.0.0-py3-none-any.whl | Python 3 | none | any | Details for sinusoidalnn-5.0.0-py3-none-any.whl |
Total release size: 18.5 kB
Release files / sinusoidalnn-5.0.0.tar.gz
| Download URL | sinusoidalnn-5.0.0.tar.gz |
|---|---|
| Size | 10.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b8485195db0c483e28ed5932def1c1f621440654ee150049845c8c2e0795a96
|
|
BLAKE2b-256 checksum How to use checksums |
721442e3546ff27191c00003ed0353fa80ec106d401cddc8d04e63e7c06c0697
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logRelease files / sinusoidalnn-5.0.0-py3-none-any.whl
| Download URL | sinusoidalnn-5.0.0-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c8ca8a2042eb82e5e8c7c4e31c9f07a3fa000fe9fb098a835fd4c2f107d2c4b2
|
|
BLAKE2b-256 checksum How to use checksums |
6e9e4e8078f321fa05a2ed9153502caa597e63f18a6e28f53b8612866a4ae1a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logSecurity for sinusoidalnn 5.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sinusoidalnn-5.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.