Skip to main content

A simple library for moving average and 1st order low-pass filter

Project description

PinkLAB Signal Processor

A simple Python package providing a moving average and a first-order low-pass filter. This project is brought to you by PinkWink from PinkLAB, aiming to help everyone easily integrate low-pass filtering and moving average functionality in their applications or data processing workflows.

  1. Moving Average: Compute the average of the most recent N samples (sliding window).
  2. First-Order Low-Pass Filter: Smooth out noisy data with an exponential moving average.

Both methods are simple to configure and use, reducing the complexity for those who want quick results in signal processing or time-series data smoothing.


Installation

From PyPI (recommended)

If you have uploaded (or plan to upload) your package to PyPI, users can install directly via:

pip install pw-signal-processor

From source

If you are distributing the source code through GitHub (or another repository):

  1. Clone (or download) this repository.
  2. Navigate to the project root (where setup.py or pyproject.toml is located).
  3. Install locally with:
pip install -e .

Usage

Once installed, simply import and create an instance of the SignalProcessor class. Configure the window_size and alpha parameters as needed:

from signal_processor import SignalProcessor

# Create a processor with a window size of 5 and alpha=0.2 for the low-pass filter
sp = SignalProcessor(window_size=5, alpha=0.2)

# Example data sequence
data = [10, 12, 13, 20, 22, 21, 18, 15, 10, 5, 8, 10]

for val in data:
    ma_val = sp.moving_average(val)
    lp_val = sp.low_pass_filter(val)
    print(f"Input: {val} | Moving Avg: {ma_val:.2f} | Low Pass: {lp_val:.2f}")
  • moving_average(): Returns the average of the most recent window_size samples.
  • low_pass_filter(): Returns an exponentially-weighted value based on the formula filtered_value = alpha * current_value + (1 - alpha) * previous_filtered_value.

Example

import numpy as np
import matplotlib.pyplot as plt
from signal_processor import SignalProcessor

# Generate some noisy sinusoidal data
time = np.linspace(0, 10, 100)
noise = np.random.normal(0, 0.5, size=time.shape)
signal = np.sin(time) + noise

# Initialize the SignalProcessor
sp = SignalProcessor(window_size=5, alpha=0.1)

ma_output = []
lp_output = []

for val in signal:
    ma_output.append(sp.moving_average(val))
    lp_output.append(sp.low_pass_filter(val))

# Plot the results
plt.figure(figsize=(10,6))
plt.plot(time, signal, label='Noisy Signal', alpha=0.5)
plt.plot(time, ma_output, label='Moving Average', linewidth=2)
plt.plot(time, lp_output, label='Low Pass Filter', linewidth=2)
plt.legend()
plt.title('My-Signal-Processor Demo')
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.show()

In this example:

  • We create a noisy sine wave (signal) and feed it into the SignalProcessor.
  • We store the outputs of both the moving average filter (ma_output) and the low-pass filter (lp_output).
  • Finally, we visualize the differences.

Contributing

Contributions, bug reports, and feature requests are welcome!

  1. Fork the project.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes.
  4. Submit a Pull Request back to the main repository.

We will review your PR as soon as possible.

License

This project is licensed under the MIT License - feel free to modify and use it as you see fit.

Contact

If you have any questions or feedback, feel free to reach out:

We hope this package helps streamline your signal processing needs!

Happy filtering! — PinkWink @ PinkLAB

Project details


Download files

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

Source Distribution

pw_signal_processor-0.1.0.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

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

pw_signal_processor-0.1.0-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file pw_signal_processor-0.1.0.tar.gz.

File metadata

  • Download URL: pw_signal_processor-0.1.0.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for pw_signal_processor-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed7f081f799dd93f91901d6229de64bdb557f9274f7a074d84571b66b54d1810
MD5 e0630c24b870eed9516ca529c93d8ae7
BLAKE2b-256 19d9d76b2d0b4c946e78af3d891fb7ba4ac2537f5f87d090bac09b7ae7624294

See more details on using hashes here.

File details

Details for the file pw_signal_processor-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pw_signal_processor-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d51dc5a5f35a03eafed4043a3b81ab25602ee2ff25b2778684e4a06d82b99d17
MD5 e42a9d52f23e63aa6448d31c1306fbce
BLAKE2b-256 6cab9505577b12c439852e404f070b0cbd79fdd80e581e2ee2f037fa7de2c633

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page