How to remove DC offset from signals in Python using UliEngineering
You can easily remove the DC offset (mean value) from a signal using the UliEngineering Python library:
remove_mean.py
import numpy as np
from UliEngineering.SignalProcessing.Utils import *
# Create a signal with DC offset
signal = np.array([1.0, 2.0, 3.0, 4.0, 5.0]) + 10.0
# Remove the DC offset
signal_centered = remove_mean(signal)
print(f"Original signal mean: {np.mean(signal)}")
print(f"Centered signal mean: {np.mean(signal_centered)}")
print(f"Centered signal: {signal_centered}")Example output
remove_mean_output.txt
Original signal mean: 12.0
Centered signal mean: 0.0
Centered signal: [-2. -1. 0. 1. 2.]The remove_mean() function subtracts the arithmetic mean from the signal, effectively centering it around zero.
Check out similar posts by category:
Signal Processing, Python
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow