Smoothing with Gaussian kernel
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello, folks!
I'm trying to create a function which filters raw accelerometer data so that I could use it for Zero crossing. I know that MatLab has built-in functions (gausswin & filter) but I'm willing to create my own because I need it for my Master's thesis.
I found some function named "smooth" here: https://bit.ly/3gsy2cr
I'm trying to modify it the way I mentioned above but my code doesn't as it is supposed to be. I'd appreciate if anybody will take a look at it and give me some tips, thanks in advance!
Attached is the raw data file (.csv)
Here is the code:
clc
clear all
%% Importing raw data
data = readtable('Subject_3_acc_walking_thigh.csv');
%%
Fs = 50; % Sampling frequency
T = 1/Fs; % Sampling period
%% Sitting
X = data.attr_x;
Y = data.attr_y;
Z = data.attr_z;
%Calculate time for sitting
L = length(data.id); % Length of signal
t = (0:L-1)*T; % Time vector
t = t*1000; % Seconds to Miliseconds
% Sum
y = X+Y+Z;
yy = smooth(y1,1,25);
plot(t,y,t,yy)
xlim([4500 10000])
xlabel('t (milliseconds)')
ylabel('Acceleration (m/s2)')
legend('Sum','Smooth')
%% Smoothing
function yy = smooth(y,sig,span)
yy = y;
L = length(y);
for i = 1 : L
if i < span
d = i;
else
d = span;
end
w = d - 1;
p2 = floor(w / 2);
if i > (L - p2)
p2 = L - i;
end
p1 = w - p2;
x_val = i - p1 : i + p2;
kernel = exp(-((x_val-i).^2)/2*sig.^2);
kernel = kernel/sum(kernel);
for j = i - p1 : i + p2
yy1(i) = sum(y(j)*kernel);
end
end
end
0 Commenti
Risposte (0)
Vedere anche
Categorie
Scopri di più su Multirate Signal Processing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!