2013-05-03 48 views
5

我有,我想一個信號時,它來複制:尋找過零點即會積極和零交叉所要負

1)開始於過零點會積極

2)複製設定數量的點(如8000)

3)複製8000點後繼續附加點,直到找到零交叉下降部分。

我能找到的零交叉,但我有與知道如何告訴時,有一個過零點會積極和/或過零變負的一些問題。我也有在末尾加上8000點後點的下一個部分的麻煩(所以質疑#1和質疑#3大膽我有問題

注意:請記住我使用的信號是音頻信號,因此它不會像簡單的公式那麼好。

我附上了測試代碼以及​​圖像。我使用MATLAB /八度

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

回答

14

試試這個:

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

這會給你過關點和他們的方向。在添加樣本的循環中,只需爲當前點和最後一點測試x。如果它是零,繼續。如果它是積極的,請添加8000點並返回測試。如果是負值,請停止。

編輯:更正第一個代碼行中的拼寫錯誤。

+1

您也可能要篩選你的信號做這個測試之前去除高頻噪聲當你通過零時避免多次交叉。 – craigim 2013-05-03 20:49:04

+0

感謝Craigim的幫助,但是你是什麼意思「測試x當前點和最後一點」。我應該對他們進行測試? – 2013-05-03 22:28:32

+0

你究竟是怎麼做的,取決於你在數據中閱讀的細節,但是如果你的循環索引是'n',那麼你可以做一些像'x = sign(t(n-1)) - sign (T(N));如果x> 0;加8000分; elseif x == 0;附加一個點; elseif x <0;停止添加點;結束。 – craigim 2013-05-03 22:38:30

0

你可以這樣做,以找到 「走出向上」 或 「走出向下」 過零點:

%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)) 
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