I again need your help. You were already nicely able to help with predicting the signal I'm dealing with. Thanks a lot. (Forecasting of a periodic movement based on sensor data)
Now I need to remove to effects from the sampling. Unfortunately I don't really have back ground in signal processing
The signal is sampled motion data from a rotating, periodic movement. Once setup the speed of the movement does not change much. I did a time domain auto correlation to find the periodicity/frequency of the signal.
Now I've the problem that this signal is used to render an animation. The sampling artifacts from the hall sensor cause the rendering not being fully smooth.
The data file and the Octave script to process it are in this folder.
What would be good approach in Octave? A few (max 5 ms) of delay caused by the filter should be acceptable.
The filters I tried unfortunately didn't have an effect or resulted in distorted data. Over all signal:
The data from the sensor is read at the highest possible rate and subject to jitter, resulting in not evenly spaced samples, largely around 1 ms. Also this will not be the "true" sampling rate of the sensor. In many cases the same value is read multiple times. Getting the full E2E sampling rate may not be straight forward. Here is histogram of the sample duration as read from the sensor.
Now I also looked into the time it takes to actually "see" a new (i.e. different) sensor reading. I think this will resemble more the true E2E sampling rate. At the moment is not reflected in the actual data, there are in average 2 - 4 samples in between with the same values.
This is around 4 to 5 ms. Do I need to resample to 5 ms before applying filter to cater to this or can I directly configure a filter to consider this?
The cycle time of periodic movement of the system is between 2 and 8 seconds, i.e. much lower frequency than these noise problems. Can I somehow exploit this difference?
Before applying filter I had interpolated this to evenly spaced 1 ms samples to not confuse the filter algorithms.
I researched a bit also worked with ChatGPT on this. Unfortunately this completely off. Here w/o resampling. But that does not change the behavior.
``
% Load time series data
data = load('data.txt');
% Extract timestamp and angle
timestamp = data(:, 1);
angle = data(:, 2);
% Find the timestamp corresponding to the last 60 seconds
last_60_sec = max(timestamp) - 60 * 1e9; % Convert 60 seconds to nanoseconds
% Extract the data within the last 60 seconds
indices_last_60_sec = timestamp >= last_60_sec;
timestamp_last_60_sec = timestamp(indices_last_60_sec);
angle_last_60_sec = angle(indices_last_60_sec);
% Define sampling artifacts range (1 - 5 ms)
artifact_start = 1e6; % 1 ms in nanoseconds
artifact_end = 5e6; % 5 ms in nanoseconds
% Apply low-pass filter within the last 60 seconds
fs = 1e3; % Sampling frequency in milliseconds (1 sample per millisecond)
f_cutoff = 1 / 10;
[b, a] = butter(4, f_cutoff / (fs/2), 'low'); % Butterworth low-pass filter
% Filter the angle data within the last 60 seconds
filtered_angle = filtfilt(b, a, angle_last_60_sec);
% Plot both the original and filtered signals within the last 60 seconds
plot(timestamp_last_60_sec * 1e-6, angle_last_60_sec, 'b',
timestamp_last_60_sec * 1e-6, filtered_angle, 'r');
xlabel('Time (ms)');
ylabel('Angle');
title('Original and Filtered Data within Last 60 Seconds');
legend('Unfiltered', 'Filtered');