Designing Filter for Accelerometer
5 ビュー (過去 30 日間)
古いコメントを表示
Hello everyone,
I want to design filter for my accelerometer to get position. The objective is to get the trace in from the X and Y axes. I have tried to code some in matlab but i still cant get it. I have attached the excel data and matlab code that I have prepared. The excel data is a diagonal of approximately 66cm with 50cm and 44cm for X and Y respectively. I really need help for this because this is my first time designing filter for very noisy sensor. Any filter will do.
Thank you in advance!
0 件のコメント
回答 (1 件)
Star Strider
2022 年 6 月 20 日
The data are not regularly-sampled, so in order to do any meaningful signal processing on them, they need to be resampled to a consistent sampling interval. I did this with the resample function, and since the sampling frequency of the original data was about 73 Hz, I chose a sampling frequency of 70 Hz. Choose whatever works best, however it would be better to go with a lower than a higher resampling frequency, since this avoids creating data where none previously existed.
The noise ais actually broadband, and the best way to deal with broadband noise is to use the Savitzky-Golay filter (sgolayfilt function) or wavelet denoising. I will help you with sgolayfilt if that is the direction you want to go. I use a frequency selective filter here to start with.
% opts = weboptions('ContentType','text');
% W = webread('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1038845/Tracking.m', opts)
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1038850/Diagonal66cm.xlsx', 'VariableNamingRule','preserve')
tstr = {'X','Y','Z'};
figure
for k = 1:3
subplot(3,1,k)
plot(T1.Timestamps, T1{:,k})
grid
title(tstr{k})
xlim([min(T1.Timestamps) max(T1.Timestamps)])
end
xlabel('Time')
sgtitle('Original Accelerometer Data')
fse = 1/mean(diff(T1.Timestamps))
Fs = 70;
[Acr,tr] = resample(T1{:,1:3}, T1.Timestamps, Fs)
figure
for k = 1:3
subplot(3,1,k)
plot(tr, Acr(:,k))
grid
title(tstr{k})
xlim([min(tr) max(tr)])
end
xlabel('Time')
sgtitle('Resampled Accelerometer Data')
Fn = Fs/2;
L = numel(tr);
NFFT = 2^nextpow2(L); % For Efficiency
FT_Acr = fft(Acr-mean(Acr),NFFT)/L; % Subtract 'mean' TO See Other Peaks
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector
figure
for k = 1:3
subplot(3,1,k)
plot(Fv, abs(FT_Acr(Iv,k))*2)
grid
title(tstr{k})
xlim([min(Fv) max(Fv)])
end
xlabel('Frequency')
ylabel('Amplitude')
sgtitle('Accelerometer: Fourier Transform')
xlim([min(Fv) max(Fv)])
% return
Wp = [0.00005 12.5]/Fn; % Passband Frequency (Normalised)
Ws = [0.9 1.10].*Wp; % 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); % 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
Acr_filt = filtfilt(sos, g, Acr); % Filter Signal
tstr = {'X','Y','Z'};
figure
for k = 1:3
subplot(3,1,k)
plot(tr, Acr_filt(:,1))
grid
title(tstr{k})
xlim([min(tr) max(tr)])
end
xlabel('Time')
sgtitle('Filtered Accelerometer Data')
.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Signal Generation and Preprocessing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!