How to derive the moving average of a time series generated in simulink?
Hi,
I have a dynamics system under excitation and I want to compute the moving average of the quantity "POW" I defined. In my case, the moving window has length 100, the sampling time was 0.01. So I expect to have the moving average "POW" every second.
clear all
clc
m1=0.947; m2=m1; Cp=1.1;
J=0.1*0.15^2/2;
L1=0.125;L2=0.035;
g=9.8;FI0=pi/2;
Kem=0.48; Rc=3.74;Re=5;
Cem=Kem^2/(Rc+Re);
TT=500;dt=1E-2;
tt=[0:dt:TT]’;
fl=0.1;
Ag=9.8*0.4;fg=1;
accg=Ag*sin(2*pi*fg*tt);
sim("buffermovemean.slx")
However, if I run the "questiononbuffer.m", the error message is :
"Error using questiononbuffer
The signal at ‘Output Port 1’ of ‘buffermovemean/Moving Average2’ is a variable-size signal with a nondiscrete sample time. The
sample time for any variable-size signal must be discrete."
So I tried to use buffer to transform the time series "POW" with fixed frame length 100 by the block "signal from workspace" and then apply moving-average, but the error message appears as:
Error using questiononbuffer
Error evaluating parameter ‘X’ in ‘buffermovemean/Signal From Workspace’
Caused by:
Error using questiononbuffer
Unrecognized function or variable ‘POW’.
Error using questiononbuffer
Variable ‘POW’ does not exist.
Suggested Actions:
• Load a file into base workspace. – Fix
• Create a new variable. – Fix
So my question is if the time series is generated in real time in the simulink, how to derive its moving average for a fixed duration like in my case? PS, when I use matlab 2019b, I could directly connect the moving-average block after the time series to get its moving average. But in matlab 2023b, error reports. How to fix it?
@Walter RobersonHi,
I have a dynamics system under excitation and I want to compute the moving average of the quantity "POW" I defined. In my case, the moving window has length 100, the sampling time was 0.01. So I expect to have the moving average "POW" every second.
clear all
clc
m1=0.947; m2=m1; Cp=1.1;
J=0.1*0.15^2/2;
L1=0.125;L2=0.035;
g=9.8;FI0=pi/2;
Kem=0.48; Rc=3.74;Re=5;
Cem=Kem^2/(Rc+Re);
TT=500;dt=1E-2;
tt=[0:dt:TT]’;
fl=0.1;
Ag=9.8*0.4;fg=1;
accg=Ag*sin(2*pi*fg*tt);
sim("buffermovemean.slx")
However, if I run the "questiononbuffer.m", the error message is :
"Error using questiononbuffer
The signal at ‘Output Port 1’ of ‘buffermovemean/Moving Average2’ is a variable-size signal with a nondiscrete sample time. The
sample time for any variable-size signal must be discrete."
So I tried to use buffer to transform the time series "POW" with fixed frame length 100 by the block "signal from workspace" and then apply moving-average, but the error message appears as:
Error using questiononbuffer
Error evaluating parameter ‘X’ in ‘buffermovemean/Signal From Workspace’
Caused by:
Error using questiononbuffer
Unrecognized function or variable ‘POW’.
Error using questiononbuffer
Variable ‘POW’ does not exist.
Suggested Actions:
• Load a file into base workspace. – Fix
• Create a new variable. – Fix
So my question is if the time series is generated in real time in the simulink, how to derive its moving average for a fixed duration like in my case? PS, when I use matlab 2019b, I could directly connect the moving-average block after the time series to get its moving average. But in matlab 2023b, error reports. How to fix it?
@Walter Roberson Hi,
I have a dynamics system under excitation and I want to compute the moving average of the quantity "POW" I defined. In my case, the moving window has length 100, the sampling time was 0.01. So I expect to have the moving average "POW" every second.
clear all
clc
m1=0.947; m2=m1; Cp=1.1;
J=0.1*0.15^2/2;
L1=0.125;L2=0.035;
g=9.8;FI0=pi/2;
Kem=0.48; Rc=3.74;Re=5;
Cem=Kem^2/(Rc+Re);
TT=500;dt=1E-2;
tt=[0:dt:TT]’;
fl=0.1;
Ag=9.8*0.4;fg=1;
accg=Ag*sin(2*pi*fg*tt);
sim("buffermovemean.slx")
However, if I run the "questiononbuffer.m", the error message is :
"Error using questiononbuffer
The signal at ‘Output Port 1’ of ‘buffermovemean/Moving Average2’ is a variable-size signal with a nondiscrete sample time. The
sample time for any variable-size signal must be discrete."
So I tried to use buffer to transform the time series "POW" with fixed frame length 100 by the block "signal from workspace" and then apply moving-average, but the error message appears as:
Error using questiononbuffer
Error evaluating parameter ‘X’ in ‘buffermovemean/Signal From Workspace’
Caused by:
Error using questiononbuffer
Unrecognized function or variable ‘POW’.
Error using questiononbuffer
Variable ‘POW’ does not exist.
Suggested Actions:
• Load a file into base workspace. – Fix
• Create a new variable. – Fix
So my question is if the time series is generated in real time in the simulink, how to derive its moving average for a fixed duration like in my case? PS, when I use matlab 2019b, I could directly connect the moving-average block after the time series to get its moving average. But in matlab 2023b, error reports. How to fix it?
@Walter Roberson buffer moving-average MATLAB Answers — New Questions