Non-uniform Discrete Data Sample Filtering
5 次查看(过去 30 天)
显示 更早的评论
Hello,
I have collected some data from my encoder and IMU and I am trying to come up with a calibration function. However the data is quite noisy (especially IMU). I timestamped then numerized the timestamp using datenum function. I would like to have a spline like output.
D = load('test_Data.mat');
t = D.test_data(:,1);
s = D.test_data(:,2);
Fs = 1; % Sampling Frequency
Ts = 1; % Sampling Interval
[sr,tr] = resample(s, t, Fs); % Resample, Return Resampled Signal & New Time Vector
sre = sr(1:end-2); % Eliminate End Transient
tre = tr(1:end-2); % Eliminate End Transient
figure
plot(t, s)
hold on
plot(tre, sre, '--')
hold off
grid
legend('Original Signal', 'Resampled Signal')
L = numel(t); % Signal Length
Fn = Fs/2; % Nyquist Frequency
sm = sre - mean(sre); % Subtract Mean
FTs = fft(sm)/L; % Scaled Fourier Transform
Fv = linspace(0, 1, fix(L/2)+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
plot(Fv, abs(FTs(Iv))*2)
grid
title('Fourier Transform')
Wp = [0.05]/Fn; % Passband Frequency (Normalised)
Ws = [0.09]/Fn; % Stopband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 60; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp,'low'); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^16, Fs) % Filter Bode Plot
sre_filt = filtfilt(sos, g, sre); % Filter Signal
figure
subplot(2,1,1)
plot(tre, sre)
grid
title('Resampled Signal')
subplot(2,1,2)
plot(tre, sre_filt, '-')
grid
title('Filtered Resampled Signal')
However resampling results singular, a single result; not an array.
3 个评论
回答(1 个)
Maximilian Schönau
2022-10-10
I would reccomend you using the live script task "Smooth Data". There you can graphically try out different filter methods and after that convert your favorite filter to code.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Measurements and Feature Extraction 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!