Zero-Crossing..

Started by s7jid January 4, 2004
All,

Can anyone tell me how to find number of zero crossing (i.e. number
of time signal changes sign) in matlab?

Regards



use the sign command and find the number of transitions.

Mandar

--- s7jid <> wrote:
> All,
>
> Can anyone tell me how to find number of zero crossing (i.e. number
>
> of time signal changes sign) in matlab?
>
> Regards >


=====
-
Its not life that weighs us down,
Its how we carry it. __________________________________



Try this.

count = 0;

thresh = 0;

for(i=0:signal_length){

if(sig[i+1]>thresh && sig[i]<=thresh) count++;

else if(sig[i+1]<thresh&& sig[i]>=thresh)count++;

end;

end;

}

count/=2;
#8216;Count#8217; will have the numberof #8216;zero crossings#8217;.
Bye
Balaji Srinivasan

-----Original Message-----
From: s7jid[mailto:]
Sent: Sunday, January 04, 20047:40 PM
To:
Subject: [matlab] Zero-Crossing..
All,

Can anyone tell me how to find number of zerocrossing (i.e. number
of time signal changes sign) in matlab?

Regards

_____________________________________
Note: If you do a simple "reply" withyour email client, only the author of this
message will receive youranswer. You need to do a "reply all" if you want your
answer tobe distributed to the entire group.

_____________________________________
About this discussion group:

To Join:

To Post:

To Leave:

Archives: http://www.yahoogroups.com/group/matlab

More DSP-Related Groups: http://www.dsprelated.com/groups.php3
--------------------------------- Yahoo!Groups Links

To
---------------------------------





one way is this

function [n] = zc(x)
% ZC number of zero crossings in x
%    [n] = zc(x) calculates the number of zero crossings in x
s=sign(x);
t=filter([1 1],1,s);
n=(length(s)-length(find(t)))/length(s);

or another way is

function zcr=zcr(x,dur)
% function zcr=zcr(x,dur) : compute zero-crossing rate
% x: input data
% dur: duration of the input data

[nf,len]=size(x);
zcr=sum(0.5*abs(sign(x(:,2:len))-sign(x(:,1:len-1))))/dur;

 

best regards

>From: "s7jid"

>To: m...@yahoogroups.com
>Subject: [matlab] Zero-Crossing..
>Date: Sun, 04 Jan 2004 14:10:25 -0000
>MIME-Version: 1.0
>X-Originating-IP: 195.92.168.167
>X-Sender: s...@yahoo.co.uk
>Received: from n2.grp.scd.yahoo.com ([66.218.66.75]) by mc10-f6.hotmail.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 5 Jan 2004 07:41:56 -0800
>Received: from [66.218.66.156] by n2.grp.scd.yahoo.com with NNFMP; 05 Jan 2004 15:41:44 -0000
>Received: (qmail 17136 invoked from network); 5 Jan 2004 15:41:38 -0000
>Received: from unknown (66.218.66.166)  by m16.grp.scd.yahoo.com with QMQP; 5 Jan 2004 15:41:38 -0000
>Received: from unknown (HELO n24.grp.scd.yahoo.com) (66.218.66.80)  by mta5.grp.scd.yahoo.com with SMTP; 5 Jan 2004 15:41:38 -0000
>Received: from [66.218.67.180] by n24.grp.scd.yahoo.com with NNFMP; 05 Jan 2004 15:41:38 -0000
>Received: (qmail 25425 invoked from network); 4 Jan 2004 14:10:25 -0000
>Received: from unknown (66.218.66.217)  by m14.grp.scd.yahoo.com with QMQP; 4 Jan 2004 14:10:25 -0000
>Received: from unknown (HELO n7.grp.scd.yahoo.com) (66.218.66.91)  by mta2.grp.scd.yahoo.com with SMTP; 4 Jan 2004 14:10:25 -0000
>Received: from [66.218.67.178] by n7.grp.scd.yahoo.com with NNFMP; 04 Jan 2004 14:10:25 -0000
>X-Message-Info: JGTYoYF78jE8olZlBuY7iFQJ//URq6b1
>X-eGroups-Return: sentto-1287352-2657-1073317302-ulasbagci=h...@returns.groups.yahoo.com
>X-eGroups-Return: s...@yahoo.co.uk
>X-Apparently-To: m...@yahoogroups.com
>Message-ID:
>User-Agent: eGroups-EW/0.82
>X-Mailer: Yahoo Groups Message Poster
>X-eGroups-Remote-IP: 66.218.66.91
>X-Yahoo-Profile: s7jid
>X-eGroups-Approved-By: s_boucheryah via web; 05 Jan 2004 15:41:37 -0000
>X-eGroups-Remote-IP: 66.218.66.80
>Mailing-List: list m...@yahoogroups.com; contact m...@yahoogroups.com
>Delivered-To: mailing list m...@yahoogroups.com
>Precedence: bulk
>List-Unsubscribe:
>Return-Path: sentto-1287352-2657-1073317302-ulasbagci=h...@returns.groups.yahoo.com
>X-OriginalArrivalTime: 05 Jan 2004 15:41:56.0657 (UTC) FILETIME=[73267A10:01C3D3A2]
>
>All,
>
>Can anyone tell me how to find number of zero crossing (i.e. number
>of time signal changes sign) in matlab?
>
>Regards
>
>


The new MSN 8: smart spam protection and 2 months FREE*

If you want to avoid for loop the following code is
equivalent to balaji's code

thresh = 0;
N = length(sig);
zc = (sig >= thresh) - (sig < thresh);
count = sum((zc(1:N-1) - zc(2:N)) ~= 0);

> Date: Mon, 5 Jan 2004 17:42:37 -0800 (PST)
> From: balaji srinivasan <>
> Subject: RE: Zero-Crossing.. > Try this.
>
> count = 0;
>
> thresh = 0;
>
> for(i=0:signal_length){
>
> if(sig[i+1]>thresh &&
> sig[i]<=thresh) count++;
>
> else if(sig[i+1]<thresh&&
> sig[i]>=thresh)count++;
>
> end;
>
> end;
>
> }
>
> count/=2; >
> #8216;Count#8217; will have the numberof #8216;zero
> crossings#8217;. >
> Bye >
> Balaji Srinivasan >
>
> -----Original Message-----
> From: s7jid[mailto:]
> Sent: Sunday, January 04, 20047:40 PM
> To:
> Subject: [matlab] Zero-Crossing.. >
> All,
>
> Can anyone tell me how to find number of
> zerocrossing (i.e. number
> of time signal changes sign) in matlab?
>
> Regards

__________________________________


If you want to avoid for loop the following code is
equivalent to balaji's code

thresh = 0;
N = length(sig);
zc = (sig >= thresh) - (sig < thresh);
count = sum((zc(1:N-1) - zc(2:N)) ~= 0);

> Date: Mon, 5 Jan 2004 17:42:37 -0800 (PST)
> From: balaji srinivasan <>
> Subject: RE: Zero-Crossing.. > Try this.
>
> count = 0;
>
> thresh = 0;
>
> for(i=0:signal_length){
>
> if(sig[i+1]>thresh &&
> sig[i]<=thresh) count++;
>
> else if(sig[i+1]<thresh&&
> sig[i]>=thresh)count++;
>
> end;
>
> end;
>
> }
>
> count/=2; >
> #8216;Count#8217; will have the numberof #8216;zero
> crossings#8217;. >
> Bye >
> Balaji Srinivasan >
>
> -----Original Message-----
> From: s7jid[mailto:]
> Sent: Sunday, January 04, 20047:40 PM
> To:
> Subject: [matlab] Zero-Crossing.. >
> All,
>
> Can anyone tell me how to find number of
> zerocrossing (i.e. number
> of time signal changes sign) in matlab?
>
> Regards

__________________________________




one way is this

function [n] = zc(x)
% ZC number of zero crossings in x
%    [n] = zc(x) calculates the number of zero crossings in x
s=sign(x);
t=filter([1 1],1,s);
n=(length(s)-length(find(t)))/length(s);

or another way is

function zcr=zcr(x,dur)
% function zcr=zcr(x,dur) : compute zero-crossing rate
% x: input data
% dur: duration of the input data

[nf,len]=size(x);
zcr=sum(0.5*abs(sign(x(:,2:len))-sign(x(:,1:len-1))))/dur;

 

best regards

>From: "s7jid"

>To: m...@yahoogroups.com
>Subject: [matlab] Zero-Crossing..
>Date: Sun, 04 Jan 2004 14:10:25 -0000
>MIME-Version: 1.0
>X-Originating-IP: 195.92.168.167
>X-Sender: s...@yahoo.co.uk
>Received: from n2.grp.scd.yahoo.com ([66.218.66.75]) by mc10-f6.hotmail.com with Microsoft SMTPSVC(5.0.2195.6713); Mon, 5 Jan 2004 07:41:56 -0800
>Received: from [66.218.66.156] by n2.grp.scd.yahoo.com with NNFMP; 05 Jan 2004 15:41:44 -0000
>Received: (qmail 17136 invoked from network); 5 Jan 2004 15:41:38 -0000
>Received: from unknown (66.218.66.166)  by m16.grp.scd.yahoo.com with QMQP; 5 Jan 2004 15:41:38 -0000
>Received: from unknown (HELO n24.grp.scd.yahoo.com) (66.218.66.80)  by mta5.grp.scd.yahoo.com with SMTP; 5 Jan 2004 15:41:38 -0000
>Received: from [66.218.67.180] by n24.grp.scd.yahoo.com with NNFMP; 05 Jan 2004 15:41:38 -0000
>Received: (qmail 25425 invoked from network); 4 Jan 2004 14:10:25 -0000
>Received: from unknown (66.218.66.217)  by m14.grp.scd.yahoo.com with QMQP; 4 Jan 2004 14:10:25 -0000
>Received: from unknown (HELO n7.grp.scd.yahoo.com) (66.218.66.91)  by mta2.grp.scd.yahoo.com with SMTP; 4 Jan 2004 14:10:25 -0000
>Received: from [66.218.67.178] by n7.grp.scd.yahoo.com with NNFMP; 04 Jan 2004 14:10:25 -0000
>X-Message-Info: JGTYoYF78jE8olZlBuY7iFQJ//URq6b1
>X-eGroups-Return: sentto-1287352-2657-1073317302-ulasbagci=h...@returns.groups.yahoo.com
>X-eGroups-Return: s...@yahoo.co.uk
>X-Apparently-To: m...@yahoogroups.com
>Message-ID:
>User-Agent: eGroups-EW/0.82
>X-Mailer: Yahoo Groups Message Poster
>X-eGroups-Remote-IP: 66.218.66.91
>X-Yahoo-Profile: s7jid
>X-eGroups-Approved-By: s_boucheryah via web; 05 Jan 2004 15:41:37 -0000
>X-eGroups-Remote-IP: 66.218.66.80
>Mailing-List: list m...@yahoogroups.com; contact m...@yahoogroups.com
>Delivered-To: mailing list m...@yahoogroups.com
>Precedence: bulk
>List-Unsubscribe:
>Return-Path: sentto-1287352-2657-1073317302-ulasbagci=h...@returns.groups.yahoo.com
>X-OriginalArrivalTime: 05 Jan 2004 15:41:56.0657 (UTC) FILETIME=[73267A10:01C3D3A2]
>
>All,
>
>Can anyone tell me how to find number of zero crossing (i.e. number
>of time signal changes sign) in matlab?
>
>Regards
>
>


The new MSN 8: smart spam protection and 2 months FREE*


Try this.

count = 0;

thresh = 0;

for(i=0:signal_length){

if(sig[i+1]>thresh && sig[i]<=thresh) count++;

else if(sig[i+1]<thresh&& sig[i]>=thresh)count++;

end;

end;

}

count/=2;
#8216;Count#8217; will have the numberof #8216;zero crossings#8217;.
Bye
Balaji Srinivasan

-----Original Message-----
From: s7jid[mailto:]
Sent: Sunday, January 04, 20047:40 PM
To:
Subject: [matlab] Zero-Crossing..
All,

Can anyone tell me how to find number of zerocrossing (i.e. number
of time signal changes sign) in matlab?

Regards

_____________________________________
Note: If you do a simple "reply" withyour email client, only the author of this
message will receive youranswer. You need to do a "reply all" if you want your
answer tobe distributed to the entire group.

_____________________________________
About this discussion group:

To Join:

To Post:

To Leave:

Archives: http://www.yahoogroups.com/group/matlab

More DSP-Related Groups: http://www.dsprelated.com/groups.php3
--------------------------------- Yahoo!Groups Links

To
---------------------------------



use the sign command and find the number of transitions.

Mandar

--- s7jid <> wrote:
> All,
>
> Can anyone tell me how to find number of zero crossing (i.e. number
>
> of time signal changes sign) in matlab?
>
> Regards >


=====
-
Its not life that weighs us down,
Its how we carry it. __________________________________


All,

Can anyone tell me how to find number of zero crossing (i.e. number
of time signal changes sign) in matlab?

Regards