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

后端 未结 4 1741
攒了一身酷
攒了一身酷 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:16

    Here's the test code in-case someone else has a similar question

    %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

提交回复
热议问题