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.
- Moving Average: Compute the average of the most recent N samples (sliding window).
- 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):
- Clone (or download) this repository.
- Navigate to the project root (where setup.py or pyproject.toml is located).
- 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 formulafiltered_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 theSignalProcessor. - 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!
- Fork the project.
- Create a new branch for your feature or bugfix.
- Commit your changes.
- 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:
- PinkWink from PinkLAB
- GitHub: https://github.com/pinklab-art/signal_processor
- Email: pinkwink@pinklab.art
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pw_signal_processor-0.1.1.tar.gz.
File metadata
- Download URL: pw_signal_processor-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
794476a12832cc8e66ae5c2e57f24e6e0ca0d99dff7a7357233b364115d8a6f1
|
|
| MD5 |
479ad414f6c62d127b3895a2958f79d7
|
|
| BLAKE2b-256 |
7eca482dc663c2f995e4337da00c3426862d4109b135fdf5f8dad34095aed533
|
File details
Details for the file pw_signal_processor-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pw_signal_processor-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9909b7d47df2ac8ba529e0e66d2f55a7c2d5c316945221f0cc00b4d1262dbb5a
|
|
| MD5 |
02e3e8951a8eb3353e8a3966052bf405
|
|
| BLAKE2b-256 |
c006192cba09f0e99bac205760eaf0066fc13a7b2fa404a8d00d396faf45f4e7
|