Capsim Block Documentation
This star finds the relative phase of a signal to a reference.
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | x | |
| 1 | float | ref |
| Port | Type | Name | |
|---|---|---|---|
| 0 | float | phi |
| Num | Description | Type | Name | Default Value | |
|---|---|---|---|---|---|
| 0 | int | edge | 1 | ||
| 1 | int | sync | 1 |
| Num | Type | Name | Initial Value | Description |
|---|---|---|---|---|
| 0 | int | ref_count | ||
| 1 | int | x_count | ||
| 2 | float | tau | ||
| 3 | int | counting | ||
| 4 | float | last_phi | ||
| 5 | float | phi_max |
int no_samples; int this_x,last_x,x_falling,x_rising; int this_ref,last_ref,ref_falling,ref_rising; |
|---|
if ((edge >= 0) && (edge >= 1)) ; else return(1); ref_count = 0; x_count = 0; counting = 0; phi_max = 180; tau = 0.0; |
|---|
for(no_samples=MIN_AVAIL();no_samples >0; --no_samples)
{
/* read x and check for edge */
if (x(0) > 0.5)
last_x = 1;
else
last_x = 0;
IT_IN(0);
if (x(0) > 0.5)
this_x = 1;
else
this_x = 0;
if (!this_x && last_x)
x_falling = 1;
else
x_falling = 0;
if (this_x && !last_x)
x_rising = 1;
else
x_rising = 0;
/* read ref and check for falling edge */
if (ref(0) > 0.5)
last_ref = 1;
else
last_ref = 0;
IT_IN(1);
if (ref(0) > 0.5)
this_ref = 1;
else
this_ref = 0;
if (!this_ref && last_ref)
ref_falling = 1;
else
ref_falling = 0;
if (this_ref && !last_ref)
ref_rising = 1;
else
ref_rising = 0;
if ((edge && ref_rising) || (!edge && ref_falling))
{
counting = true;
tau = ref_count + 1.0;
ref_count = 0;
x_count = 0;
}
else
++ref_count;
if ((edge && x_rising) || (!edge && x_falling))
{
if(IT_OUT(0)) {
KrnOverflow("phi_meter",0);
return(99);
}
counting = false;
if (tau > 0)
phi(0) = (x_count * 360.0)/tau;
else
phi(0) = 0.0;
while (phi(0) > 360.0)
phi(0) = phi(0) - 360.0;
if (phi(0) > phi_max)
phi(0) = phi(0) - (2 * phi_max);
last_phi = phi(0);
}
/* else, continue to count and output last phase */
else
{
if (sync)
{
if(IT_OUT(0)) {
KrnOverflow("phi_meter",0);
return(99);
}
phi(0) = last_phi;
}
if (counting)
++x_count;
}
}
return(0);
|
|---|
/* Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
Copyright (C) 1989-2002 XCAD Corporation
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
http://capsimtmk.sourceforge.net
XCAD Corporation
Raleigh, North Carolina */
|
|---|
/* phi_meter.s */ /*************************************************************** phi_meter() **************************************************************** Inputs: x, the signal of interest ref, the reference signal Outputs: phi, the phase difference in degrees Parameters: int edge, the edge to trigger on int sync, specifies if a value is to be output for every input sample **************************************************************** This star finds the relative phase of a signal to a reference. Both signals are assumed to be digital and between 0.0 and 1.0. One parameter specifies the trigger edge (true for rising, false for falling). The other specifies the output rate (synchronous or one per cycle). The output is the phase difference of the chosen edges in degrees. |
|---|