Triangular-weighted moving average filter

14 ビュー (過去 30 日間)
Mateusz Rzeszowski
Mateusz Rzeszowski 2023 年 4 月 13 日
回答済み: Meg Noah 2025 年 8 月 9 日 15:13
Hi,
I`m looking for function or source code for Triangular-weighted moving average filter to apply it and make my data processing.
High-frequency noise shall be removed from the measured signals using a triangular-weighted moving average with a smoothing width of 100 ms.
can someone share the experience ?
  2 件のコメント
Jon
Jon 2023 年 4 月 13 日
Mateusz Rzeszowski
Mateusz Rzeszowski 2023 年 4 月 13 日
nope

サインインしてコメントする。

回答 (2 件)

Image Analyst
Image Analyst 2023 年 4 月 13 日
Use conv and set up your kernel to be a triangle shape.
  1 件のコメント
Dan
Dan 2025 年 7 月 30 日
Try:
tri_weights = triang('sz');
filtered_data = conv('data', tri_weights, "same") / sum(tri_weights);

サインインしてコメントする。


Meg Noah
Meg Noah 2025 年 8 月 9 日 15:13
Here's an example of high frequency noise being removed with a triangular filter, if by width you mean the base of the triangle:
signal = repmat([zeros(1,500) ones(1,2000) zeros(1,500)],1,10);
time_ms = 0.1*(1:numel(signal));
dt_ms = time_ms(2)-time_ms(1);
filter = triang(round(100/dt_ms))/sum(triang(round(100/dt_ms)));
fprintf(1,'Sum of energy conserving filter should be 1 = %f\n', sum(filter(:)));
Sum of energy conserving filter should be 1 = 1.000000
fprintf(1,'Filter width = %d samples = %f ms',numel(filter),numel(filter)*dt_ms);
Filter width = 1000 samples = 100.000000 ms
smooth_signal = conv(signal,filter,'same');
plot(time_ms,signal,'b','DisplayName','Signal');
hold on
plot(time_ms,smooth_signal,'r','DisplayName','Smoothed Signal');
legend('location','best');
xlabel('Time [ms]');
ylabel('Signal');
You can also apply the convolution theorem to do it with Fourier transforms.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by