How to replicate Matlab moving average to Simulink model?

3 ビュー (過去 30 日間)
Desislava Petkova
Desislava Petkova 2022 年 2 月 6 日
コメント済み: Mathieu NOE 2022 年 2 月 7 日
Hi All, i am struggling to figure out how to replicate my Matlab moving average filter results to a simulink model? Pretty new in the Simulink world .... I have tried using the From file block, but this doesn't seem to work. Can someone help guide me in the right derictions, pretty please?
Matlab code below.
sample_window_size=30;
total_no_of_expected_data_samples=24*30;
averaging_vector=(1/sample_window_size)*ones(1,sample_window_size)
norm_y=1
lower_limit=50
upper_limit=2000
original_data=lower_limit+rand(1,total_no_of_expected_data_samples).*(upper_limit-lower_limit)
filtered_data=filter(averaging_vector,norm_y,original_data);
t=1:length(original_data)
plot(t,original_data,'--',t,filtered_data,'-')
legend('Original Data','Filtered Data')
averaging_vector = 1×30
0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333 0.0333
norm_y = 1
lower_limit = 50
upper_limit = 2000
original_data = 1×720
1.0e+03 * 0.3172 0.6796 1.2769 1.0724 0.3673 1.0012 0.8914 0.8614 0.8318 1.3123 0.6702 0.1595 1.3916 0.8729 0.6457 0.0646 1.3070 1.7250 0.8568 1.6881 1.5451 0.3118 0.6545 1.0748 0.7542 0.4284 0.7215 0.8487 1.7624 0.3146
t = 1×720
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

採用された回答

Mathieu NOE
Mathieu NOE 2022 年 2 月 7 日
hello
in terms of signal processing, a moving average filter is a FIR with all coefficients of the numerator equals ( = 1/n if the FIR numerator length = n , your average length)
use the "discrete filter" block
NB : you can design any FIR or IIR low pass filter , they will all do your average work with simply different cut off frequency and different slope , so this will both affect the transient and steady state error.
as alternative you can use a "buffer" block followed by the math function "mean"
see example attached
  2 件のコメント
Desislava Petkova
Desislava Petkova 2022 年 2 月 7 日
Thank you!
Mathieu NOE
Mathieu NOE 2022 年 2 月 7 日
My pleasure !

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with DSP System Toolbox についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by