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


i have signal copy when it:

1) starts @ 0 crossing going positive

2) copy set number of points (like 8000)

3) , after 8000 points copied continue appending points until 0 crossing going down section found.

i can find 0 crossing i'm having issues knowing how tell when there 0 crossing going positive and/or 0 crossing going negative. i'm having trouble adding next section of points after 8000 points @ end (so question #1 , question #3 in bold i'm have issues with)

note: please keep in mind signal i'm using audio signal won't nice simple equation.

i've attached test code along image. i'm using matlab / octave

clear all, clc, tic, clf; n=16000 t=linspace(0,2*pi,n); y=cos(6*t)+sin(4*t);  %find 0 crossings t1=y(1:n-1); t2=y(2:n); tt=t1.*t2; indx=find(tt<0)  %1) start @ first 0 crossing going positive  %2) 8000 pts  %3) , after 8000 points continue appending points until 0 crossing going down section found new_y=y(indx(1,1):8000); %start @ 0 section found 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

try this:

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

that give crossing points , direction. in loop add samples, test x current point , last point. if it's zero, keep going. if it's positive, add on 8000 points , go testing. if it's negative, stop.

edit: corrected typo in first code line.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

java - Are there any classes that implement javax.persistence.Parameter<T>? -

linux - Does gcc have any options to add version info in ELF binary file? -