MATLAB计算信号的过零率

1. 基本原理

由于低压波动或背景噪声的存在,会增加信号的振幅值超过零振幅电平的次数。

为避免低压波动或背景噪声带来的影响,信号振幅实施阈值条件,得到下述公式。

过零率的计算公式如下:
在这里插入图片描述

2.MATLAB代码

function count = zero_crossings(x,thr)
% x是时域信号,必须是1位的行向量或者列向量;
% thr是设定的阈值
% count是该函数计算信号x过零率的值
 
% initial value
count = 0;
 
% error checks
if(length(x) == 1)
    error('ERROR: input signal must have more than one element');
end
 
if((size(x, 2) ~= 1) && (size(x, 1) ~= 1))
    error('ERROR: Input must be one-dimensional');
end
    
% force signal to be a vector oriented in the same direction
x = x(:);
 
num_samples = length(x);
for i=2:num_samples
    % Any time you multiply to adjacent values that have a sign difference
    % the result will always be negative.  When the signs are identical,
    % the product will always be positive.
    if(((x(i)*x(i-1)) < 0)&&(abs(x(i)-x(i-1))>thr))
        count = count + 1;
    end 
end

参考文献

[1]Feature reduction and selection for EMG signal classification.
[2]matlab 计算过零率

如果觉得这篇博客是你需要的,请动动你的手指,点个赞吧,谢谢你的鼓励;如果你对我写的博客感兴趣,欢迎你常来我的主页看看,期待你的关注。

猜你喜欢

转载自blog.csdn.net/weixin_45317919/article/details/109326420