matlab平均降采样

之前的降采样只能用于向量,由于本身的downsample是可以直接对数组进行降采样,所以又改了一下。注意:downsample是将数组的每一列当作序列来降采样的。

function [y] = mean_downsample(x,N)
%UNTITLED 在matlab中实现平均降采样
%   x:原始信号,格式为times*channls的数组
%   y:平均降采样后的信号
%   N:降采样的倍数,即降采样后频率=降采样前频率/N
%   作者:张亦弛       2023/5/31
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   x = [1:1000;1001:2000]';N=4;   % 示例数据
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
downdata = zeros(size(x,1)/N,size(x,2));  % 建立空数组存放降采样后的和
for phase = 0:N-1   % 偏置从0取到N-1
    temp = downsample(x,N,phase);  % N倍降采样,偏移phase个点进行
    downdata = downdata + temp;  % 累加N次降采样后的结果
end
y = downdata/N;  % 平均累加结果,得到平均降采样的值
end

你可能感兴趣的:(matlab,开发语言,数学建模)