Skip to main content

SinusoidalNN

logo

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:

  1. Load a signal from CSV
  2. Train a SinusoidalNN model
  3. Save the trained model
  4. Extract the learned spectrum
  5. Plot the spectrum
  6. Reconstruct the signal
  7. 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sinusoidalnn-4.2.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sinusoidalnn-4.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file sinusoidalnn-4.2.0.tar.gz.

File metadata

  • Download URL: sinusoidalnn-4.2.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for sinusoidalnn-4.2.0.tar.gz
Algorithm Hash digest
SHA256 aa1d2d9e64ce71a994da3ad8a522ab46e79551fe899afcf3718f0eb7a90f86dc
MD5 59d6ec226408ef0888488877eda4325e
BLAKE2b-256 9782410495f8ea2701b37715a5d782bba497f0bd35d7b21e76c76cb36005669c

See more details on using hashes here.

Provenance

The following attestation bundles were made for sinusoidalnn-4.2.0.tar.gz:

Publisher: python-publish.yml on jovan-AIcoder/SinusoidalNN

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file sinusoidalnn-4.2.0-py3-none-any.whl.

File metadata

  • Download URL: sinusoidalnn-4.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for sinusoidalnn-4.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44d7c8322f106c32e3461287cdffc7ae13e2ecdde5a67cc7c60a0b7f3844106b
MD5 e33bc77b631878bc681cf140c8e80f23
BLAKE2b-256 2b75f18325b0866547a3af08b00364b797673030c229855fbd5fd2aa3e762758

See more details on using hashes here.

Provenance

The following attestation bundles were made for sinusoidalnn-4.2.0-py3-none-any.whl:

Publisher: python-publish.yml on jovan-AIcoder/SinusoidalNN

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

5.0.0

2 files

This release

4.2.0 This release

2 files

4.1.1

2 files

4.1.0

2 files

4.0.2

2 files

4.0.1

2 files

4.0.0

2 files

3.0.0

2 files

2.0.0

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page