Reputation: 31
i have sample csv files, one is with unfiltered data and the other one is filtered with butterworth filter from the Software where the csv comes from. I wanna filter the unfiltered data myself and then compare the results. I use the butter Filter from scipy. I plot both data but the results from the scipy butter filter are a little bit different then the filtered data from the original Software. On an first look it seems good but when you zoom in there are small differences.
The filtered data is filtered with CFC180. Perhaps someone can help me what is going wrong? Thanks!
Col0 = Time, Col1 = X-Axle. I only use col0 and col1, so ignore the others.
Sample rate from Software is 20000Hz. There is an field with Hardware AA Filter (-3db) and the value for this is 4000 for col1 if this is relevant.
Here is my python code so far.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import signal
c_data = {}
xmin = -5.00005
xmax = 5
c_filt = 'black'
g = 9.81
# Butterworth Filter
cfc60 = signal.butter(4, 100, output='sos', fs=20000)
cfc180 = signal.butter(4, 300, output='sos', fs=20000)
cfc600 = signal.butter(4, 1000, output='sos', fs=20000)
cfc1000 = signal.butter(4, 1650, output='sos', fs=20000)
def Acceleration(Axis_name, Axis_data, ymin, ymax, nofilter=False):
if nofilter is True:
print("Filtered from Software", Axis_data)
plt.plot(
c_data["t"], Axis_data/g, c_filt,
label=f"{Axis_name}"
)
else:
# CFC180
Axis_data_filtered = signal.sosfilt(cfc180, Axis_data)
print("Filtered scipy butter", Axis_data_filtered)
plt.plot(
c_data["t"], Axis_data_filtered/g, c_filt,
label=f"{Axis_name}"
)
plt.legend(loc="upper right")
plt.grid(True)
plt.axis([xmin, xmax, ymin, ymax])
plt.tick_params(which='minor', width=1, length=3, color='black')
plt.minorticks_on()
plt.xlabel("time [s]")
plt.ylabel(f"{Axis_name} axle")
plt.show(block=True)
def GetData(File, filtering=False):
dataframe = pd.read_csv(File, sep=';', skiprows=0, header=None)
dfvalues = dataframe.values
c_data["t"] = dfvalues[:, 0] # time
c_data["x_acc"] = dfvalues[:, 1] # x axle
Acceleration('X', c_data["x_acc"], -25, 20, filtering)
return
GetData("unfiltered.csv", False)
# GetData("filtered.csv", True)
So i have it on pastebin the two sample csv data. Unfiltered Data Filtered Data
Upvotes: 0
Views: 375