How can I fix this code to calculate the running average of my data without using toolbox methods such as movmean or smooth?

4 ビュー (過去 30 日間)
The end goal is to smooth the data in a graph. What I have so far is in the first attachment and the .txt file is in the second. Thank you in advance for your help!
  1 件のコメント
Greg
Greg 2018 年 9 月 6 日
I see your attachments are labeled homework. Is the toolbox limitation a MATLAB license restriction (assumedly you want to save money), or an instruction restriction?
Many of the statistics functions ( movmean ) were moved into core MATLAB in R2016a - no longer requiring toolboxes. If the instructor said not to use pre-built algorithms, you have to do it the hard way. But that doesn't mean you can't check your own work against the built-in movmean, now does it?

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

採用された回答

Pierre845
Pierre845 2018 年 9 月 6 日
function avg = running_avg(signal, avg_window)
avg = zeros(1, length(signal);
for i = avg_window:length(signal)
avg(1, i) = sum( signal(i-avg_window+1:i) ) / avg_window;
end
end
  2 件のコメント
Kh zaa
Kh zaa 2018 年 9 月 16 日
I use level-1 s-function in my simulink model. Measurements of 5 variables are collected in simulink and sent to s-function. In order to filter out some of measurements noise, i need to use the average of the snapshots received over a a time window (i.e. 2 second). how i can do that ? thanks in advance

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by