【发布时间】:2017-11-06 07:05:00
【问题描述】:
我需要实现移动平均数字滤波器来进行一些后期处理 在 Scilab 中记录示波器波形。我准备了一个脚本 下面给出的代码(具有包含 256 个样本的平均窗口的递归实现)
// number of samples
N = 350000;
// vector of voltage samples
voltage = M(1:N, 2)';
// filtered values
filt_voltage = zeros(1:N);
// window length
L = 256;
// sum of the samples in the averaging window
sum = 0
for i = 1:N_01
// averaging window full?
if i > L
// remove the oldest sample in the averaging window
sum = sum - voltage(i - L);
end
// add the newest sample into the averaging window
sum = sum + voltage(i);
// average of the samples in the averaging window
filt_voltage(i) = sum/L;
end
脚本输出如下(蓝色波形 - 记录数据,红色波形 - 过滤数据)
问题是我不确定我是否执行移动平均 是正确的(我发现了很多主要基于卷积的实现)。输出似乎以某种方式过滤,但它会有所帮助 对我来说,如果有人可以向我确认它是正确的。提前致谢。
【问题讨论】:
-
看起来不错。似乎是什么问题?
-
感谢 NickJH 的反应。问题是我不确定我的实现是否正确(到目前为止我发现的每个实现都与我的实现不同)。根据这一发现,我预计会有问题。
-
您可以通过综合测试用例让自己放心(或发现错误!),例如,高度为 10L 的单个脉冲应该产生宽度为 L 和高度为 10 的脉冲;恒定输入应保持不变(在初始从零开始上升之后)。如果这两个都有效,那么就不会出错。
-
NickJH 感谢您提供的测试建议。
标签: filter signal-processing scilab oscilloscope