如何根据传感器数据计算速度?

How to calculate speed from sensor data?

我从 'missing tooth' 传感器获得了速度测量数据。有什么办法可以获得速度与时间的瞬态图吗?我可以通过计算传感器齿轮中指示 'missing tooth' 的零交叉数来获得测量的平均速度,但我更感兴趣的是查看时间历史图。 提前致谢。

% I will first generate a example sensor output
Ts = 0.001;
t = 0:Ts:10;
freq = linspace(2, 5, length(t)); % increase the tooth frequency from 2Hz to 5Hz.
theta = cumsum(freq*2*pi*Ts);
x = sin(theta);
figure('Name', 'missing tooth sensor') % plot the sensor output
plot(x)

% Now, I will perform the actual calculations.
iCrossings = find(sign(x(1:end-1)) ~= sign(x(2:end))); % finds the crossings
dtCrossing = diff(t(iCrossings)); % calculate the time between the crossings
figure('Name', 'tooth frequency')
hold on
plot(t, freq, 'g'); % plot the real frequency in green
plot(t(iCrossings(1:end-1)), 1./(2*dtCrossing), 'b'); % plot the measured frequency in blue.

代码生成以下数字:

您可以通过将频率乘以齿距来将齿频率转换为速度。过滤器可能有助于消除(采样)噪声。