寻找正向过零点和负向过零点

5
我有一个信号,希望在以下情况下进行复制:
1) 从零点开始向上变化
2) 复制一定数量的点(例如8000个)
3) 复制完8000个点后,继续追加点,直到找到一个向下的零交叉部分。
我可以找到零交叉点,但是我无法确定何时有向上或向下的零交叉。此外,我还遇到了在8000个点之后添加下一个点集的问题(所以问题# 1和问题#3粗体字中我遇到了问题)。
请注意:请记住,我使用的信号是音频信号,因此它不会像简单的方程那样好。
我附上了测试代码和图片。我正在使用Matlab / Octave。
clear all, clc, tic, clf;
n=16000
t=linspace(0,2*pi,n);
y=cos(6*t)+sin(4*t);

%find zero crossings
t1=y(1:n-1);
t2=y(2:n);
tt=t1.*t2;
indx=find(tt<0)

%1) start at first zero crossing going positive 
%2) get 8000 pts 
%3) and after the 8000 points continue appending points until a zero crossing going down section is found
new_y=y(indx(1,1):8000); %start at zero section found get 8000 pts
subplot(2,1,1);plot(y);title('Original Signal')
subplot(2,1,2);plot(new_y);title('New signal')

enter image description here

4个回答

15

试试这个:

x = diff(sign(y));
indx_up = find(x>0);
indx_down = find(x<0);

那会给你交点及其方向。在添加样本的循环中,只需测试当前点和上一个点的x值。如果它为零,则继续;如果为正,则加上8000个点并返回测试;如果为负,则停止。

编辑:已更正第一行代码中的拼写错误。


1
在进行此测试之前,您可能还希望过滤信号以消除高频噪声,以避免在通过零点时出现多次交叉。 - craigim
谢谢Craigim的帮助,但是你说的“测试当前点和上一个点的x值”是什么意思?我应该用什么来测试它们? - Rick T
具体如何实现取决于读入数据的细节,但如果您的循环索引是 n,那么您可以这样做:x = sign(t(n-1)) - sign(t(n)); if x>0; add 8000 pts; elseif x==0; append a point; elseif x<0; stop adding points;end - craigim
1
检测零交叉的这种方法唯一的问题是,如果向量中存在一个精确的零,则会出现问题。例如,diff(sign([-2 0 2]))将建议存在两个零交叉点而不是一个。消除这些交叉点的一种方法是对原始向量进行逐个元素的“与”操作 - diff(sign(t)) & t(2:end)或保留交叉点的方向,(diff(sign(t)) & t(2:end)) .* sign(t(2:end)) - Graeme

1
以下是测试代码,以防其他人有类似的问题。
%zero crossing testing  (find zero upward, copy fs 4000, find next zero upward.
clear all, clc, tic, clf;
n=16000
t=linspace(0,2*pi,n);
y=cos (6*t)+sin(4*t);

find_zero = diff(sign(y));
indx_up = find(find_zero>0); %find all upward going zeros
indx_down = find(find_zero<0); %find all downward going zeros
new_y=[];

fs_range_wanted=indx_up(1,1)+4000; %starts from first zero adds sample size wanted
new_y=[y(indx_up(1,1):fs_range_wanted)]; %may have to minus 1
ii=0;
while (find_zero(1,fs_range_wanted+ii)  ~= 2);  %do while not going dwn and append 
    ii=ii+1
    y_pt_loc=fs_range_wanted+ii %what is the location of the point
    new_y = [new_y, y(1,fs_range_wanted+ii)]; %append points
end


subplot(3,1,1);plot(y);title('Original Signal')
subplot(3,1,2);plot(new_y);title('New signal')
subplot(3,1,3);plot(find_zero);title('Zeros-Pos-Neg')

enter image description here


0
function[t,s]=zerocorss(x,m)
    if nargin<2
      m='b';
    end

    s=x>0;

    k=s(2:end)-s(1:end-1)

  if any(m=='p')
      f=find(k>0);
  elseif (m=='n')
      f=find(k<0);
  else
      f=find(k~=0);
  end

  s=x(f+1)-x(f);
  f=f-x(f)./s;

  if ~nargout
      n=length(x);
      subplot(2,1,1),plot(1:n,x,'x',t,zerocorss(length(x)/1),'o');
      subplot(2,1,2),stem(t,s);
  end
end

0

您可以这样做来查找“going-up”或“going-down”的零交叉点:

%find zero crossings
t1=y(1:n-1);
t2=y(2:n);
tt=t1.*t2;
indx=find(tt<0)

dt        = t2-t1;
indx_up   = find( (tt<0) & (dt>0) ) 
indx_down = find( (tt<0) & (dt<0) ) 

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接