MATLAB calculates the zero-crossing rate of a signal

1. Basic Principles

Due to the presence of low-voltage fluctuations or background noise, the number of times the signal amplitude exceeds the zero amplitude level will increase.

In order to avoid the influence of low-voltage fluctuation or background noise, the signal amplitude implements the threshold condition, and the following formula is obtained.

The formula for calculating the zero-crossing rate is as follows:
Insert picture description here

2.MATLAB code

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

references

[1]Feature reduction and selection for EMG signal classification.
[2]matlab calculates zero crossing rate

If you think this blog is what you need, please move your finger and click like, thank you for your encouragement; if you are interested in the blog I wrote, you are welcome to visit my homepage often and look forward to your attention.

Guess you like

Origin blog.csdn.net/weixin_45317919/article/details/109326420