Block Category: Nonlinear
Input: Real scalar.
Description: The crossDetect block monitors its input value and compares it with a user-specified crosspoint. When the input value crosses the crosspoint, the crossDetect block outputs either +1 or -1, depending on whether the crossover occurred with a positive slope or negative slope. If a crossover is not detected, the crossDetect block outputs 0.
Cross Point: Represents the value that, when x crosses it, causes the output signal to go to 1, -1, or 0. The default is 0. You can enter a value in hexadecimal notation or as a C expression.
Label: Indicates a user-defined block label that appears when View > Block Labels is activated.
To obtain correct results from the examples described below, increase the point count for the plot blocks to at least 1,000.
1. Detection of zero crossover of a sinusoid
Consider the equation:
y = 1 if sin(t) = 0, else y = 0
This equation i realized as:
As can be seen from the crossDetect block output, three 0-crossings are detected in the simulation. The first and third 0-crossings occur with negative slope (that is, the value of sin(t) is decreasing, as it approaches 0), while the second 0 crossing occurs with positive slope (that is, the value of sin(t) is increasing as it approaches 0.) Consequently, the first and third 0-crossing events are -1, and the second 0-crossing event is + 1.
However, since y is required to be equal to +1 whenever sin(t) = 0, irrespective of the slope, the output of the crossDetect block is passed through an abs block to extract the absolute value, and this output is defined as the variable y. The bottom plot block shows that y = 1 when sin(t) = 0; otherwise y = 0.
2. Detection of non-zero crossover with externally set crosspoint
Consider the equation:
y = 1 if sin(t) = 0.5, else y = 0
This equation is realized exactly as above by setting the internal crosspoint on the crossDetect block to 0.5. Unfortunately, this may not be acceptable in some cases, particularly when the crosspoint itself is computed as a part of the simulation. In such cases, the crosspoint must be set externally, as shown in the diagram below.
The key difference here is that the output of the sin block is connected to a summingJunction block, which computes the difference between sin(t) and a variable called desired cross point. This difference is connected to the crossDetect block, which has an internal crosspoint of 0.
In effect, a non-zero crossover detection problem is converted to a 0-crossover detection problem. That is, the problem of y = 1 when sin(t) = 0.5 is converted to y = 1 when sin(t) - 0.5 = 0. The rest of the diagram is identical to the previous one.