Finding zero crossing that are going positive and zero crossing that are going negative

后端 未结 4 1751
攒了一身酷
攒了一身酷 2021-01-06 01:36

I have a signal that I would like to copy when it:

1) starts at zero crossing going positive

2) copy a set number of points (like 8000)

4条回答
  •  青春惊慌失措
    2021-01-06 02:21

    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
    

提交回复
热议问题