在Matlab中循环分析信号的循环

用户名

我有一个已知信号x,每10秒要分析一次:

t = 1:1:100;           %time
x = 8*sin(t);          %the signal
a1= 5;                 %known coefficient for the first 10s

对于此信号,我在前10秒钟执行第一次分析:

%analysis 1
x1 = x(1:11);
y1 = x1*a1;
y_mean1 = mean(y1);
a2=y_mean1;            %coefficient necessary for the next 10s

现在,我对接下来的10秒钟进行分析:

%analysis 2
x2 = x(12:22);
y2 = x2*a2;
y_mean2 = mean(y2);
a3 = y_mean2;          %coefficient necessary for the next 10s

并且对于信号的总长度将重复该过程。但是,这种方法并不是我想象的最方便的方法。我该如何循环?

谢谢!

很容易循环:

n=10;
a = 5;
y_mean = [];
for ind = 1:n:100
    y = x(ind:ind+n)*a;
    a = mean(y);
    y_mean(end+1) = a;
end  

但是您可能会找到一种无需循环的方法,这mean(reshape(x, 10, []))是一个好的开始,并查看cumsum样式函数等可以完成它。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章