jitter

Capsim Block Documentation

Short Description

This star finds the relative phase of a signal to a reference.

Top
Input Connections
Port Type Name
0 float x
1 float ref
Top
Output Connections
Port Type Name
0 float phi
Top
Parameters
Num Description Type Name Default Value
0 Trigger edge: 1= Rising, 0=Falling int edge 1
1 Output Rate. Synchronous/One per cycle int sync 1
Top
States
Num Type Name Initial Value Description
0 float ref_count
1 float x_count
2 float tau
3 int counting
4 float last_phi
5 float phi_max
6 float this_x
7 float last_x
8 float this_ref
9 float last_ref
Top

Declarations


 

	int no_samples;
	int x_falling,x_rising;
	int ref_falling,ref_rising;
	float delta;



Top

Initialization Code



 

	if ((edge >= 0) && (edge >= 1))
		;
	else
		return(1);
	ref_count = 0.0;
	x_count = 0.0;
	counting = 0;
	phi_max = 180.0;
	tau = 0.0;
	this_x=0.0;
	this_ref=0.0;




Top

Main Code



 

 
	for(no_samples=MIN_AVAIL();no_samples >0; --no_samples) 
 
	{
		/* read x and check for edge		*/
		last_x = this_x;
		IT_IN(0);	
		this_x = x(0);
 
		if ((this_x <= 0.0) && (last_x > 0.0))
			x_falling = 1;
		else
			x_falling = 0;
 
		if ((this_x >= 0.0) && (last_x < 0.0))
			x_rising = 1;
		else
			x_rising = 0;
 
 
		/* read ref and check for falling edge	*/
		last_ref = ref(0);
		IT_IN(1);	
		this_ref = ref(0);
 
		if ((this_ref <= 0.0) && (last_ref > 0.0))
			ref_falling = 1;
		else
			ref_falling = 0;
 
		if ((this_ref >= 0.0) && (last_ref < 0.0))
			ref_rising = 1;
		else
			ref_rising = 0;
 
		if ((edge && ref_rising)||(!edge && ref_falling))
			{
 
			counting = true;
 
			/* find distance from last sample */
			/* to zero crossing		*/
			delta = last_ref/(last_ref - this_ref);
 
 
			tau = ref_count + delta; 
			ref_count = 1.0 - delta;
			x_count = 0.0 - delta;
			}
		else
			{
			ref_count = ref_count + 1.0;
			delta = 0.0;
			}
 
		if (((edge && x_rising) || (!edge && x_falling)) 
			&& counting)
			{
			if(IT_OUT(0)) {
				KrnOverflow("jitter",0);
				return(99);
			}
			counting = false;
 
			/* find distance from last sample to	*/
			/* zero crossing			*/
			if (delta != 0.0)
				{
				delta = last_x/(last_x - this_x) 
					- delta;
				x_count = delta;
				}
			else
				{
				delta = last_x/(last_x - this_x);
				x_count = x_count + delta;
				}
 
 
			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("jitter",0);
					return(99);
				}
				phi(0) = last_phi;
				}
			if (counting)
				x_count = x_count + 1.0;
			}
			
	}

 
	return(0);




Top

Wrapup Code



 





Top

License



/*  Capsim (r) Text Mode Kernel (TMK) Star Library (Blocks)
    Copyright (C) 1989-2017  Silicon DSP 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://www.silicondsp.com
    Silicon DSP  Corporation
    Las Vegas, Nevada
*/


Top

Description



 

/* jitter.s */
/***************************************************************
			jitter() 
****************************************************************
	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.  
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.
The phase is found from a linear interpolation of the values on 
either side of a zero crossing.

jitter


This star finds the relative phase of a signal to a reference.  
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.
The phase is found from a linear interpolation of the values on 
either side of a zero crossing.


Programmer: 	Prayson W. Pate
Date:		February 2, 1988
Modified:	February 22, 1988

*/