MATLAB: How to to filter non-uniformly sampled data

filtering non-uniformly sampling

I've a series of force sensor data acquired by an industrial robot controller. Sadly the data has to be read out in a background task, so the sampling time differs between 1m and 20ms. Due to high oscillation in the process, I have to low-pass filter these force values.
What is the best way to filter this data? Right now, I'm interpolating linear between the data points and than resample with a sampling rate of 1kHz (1ms sampling time). Then I'm using a moving average filter to smooth and filter these data.
But I'm not happy with this method because I neither know how this is changing the validity of my data.
Help is highly appreciated. Thank you.

Best Answer

Your approach is correct. Rather than using interp1, use the Signal Processing Toolbox resample (link) function. It incorporates an anti-aliasing filter, and is preferred for signal processing purposes.
A useful lowpass filter design prototype is:
Fs = 360; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = 100/Fn; % Passband Frequency (Normalised)
Ws = 101/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 150; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[soslp,glp] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(3)
freqz(soslp, 2^16, Fs) % Filter Bode Plot
filtered_signal = filtfilt(soslp, glp, original_signal); % Filter Signal
Make appropriate changes for your signal.