Average Moving filter in Simulink

조회 수: 50 (최근 30일)
Achraf
Achraf 2023년 10월 11일
댓글: Kazem 2025년 5월 8일
Hey!
I don't have a DSP System Toolbox / Statistics, and I would like to create an average moving filter, and tune it.
I would appreciate any help, and thank in advance!
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2023년 10월 11일
hello
you can use a FIR filter of length N with 1/N values for all taps
other window are also doable if you want to weight the input data differently (hanning / hamming / kaiser etc...)

댓글을 달려면 로그인하십시오.

채택된 답변

Jon
Jon 2023년 10월 11일
You could do it like this using just the discrete transfer function block included with Simulink>Discrete>Discrete Transfer Fcn, for example for the moving average of last 3 values
  댓글 수: 3
Jon
Jon 2023년 10월 11일
You could also make the numerator polynomial be [1 1 1 0], and include the current sample in the moving average window, this would give you direct feedthrough which you may or may not want.
Jon
Jon 2023년 10월 12일
You could also do the equivalent of what I show above using the Simulink>Discrete>Discrete FIR Filter, as @Mathieu NOE suggests, using coefficients are in terms of z^(-n), rather than a numerator and denominator using z^(n) as I did.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 10월 11일
Why not use MATLAB code, e.g.:
t=linspace(0,2*pi);
S = sin(t); % Signal
R=randn(1,100); % Noise
S = S+R*.5; % Signal noise affected
N = 3; % 3-point moving average
S_ma(1)=S(1);
S_ma(2)=sum(S(1:3))/N;
for ii = 3:numel(R)
S_ma(ii)=(S(ii-2)+S(ii-1)+S(ii))/N;
end
plot(t, S)
hold on
plot(t,S_ma, 'r','LineWidth', 2)
% Compare to the MATLAB's moving average filter from finance toolbox
S_mat = movavg(S.', 'simple', N);
plot(t, S_mat, 'k--*')
legend('Signal', 'Code: moving average', 'Matlab"s movavg fcn', 'location', 'best')
grid on
xlabel('t')
ylabel('Signal: S(t)')
  댓글 수: 2
Jon
Jon 2023년 10월 11일
편집: Jon 2023년 10월 11일
I think the OP was asking how to do it in Simulink, rather than as a MATLAB calculation
Kazem
Kazem 2025년 5월 8일
Use it as MATLAB funciton in Simulink

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with DSP System Toolbox에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by