Math Functions Reference
A math function contains an expression that is composed of data, functions, operators, and numerical constants. The output of a math function is accessed through the
submenu. You can place the math function's trace data in a trace window to view the results of the calculation.Math Function syntax
The syntax of a Math Function Expression is similar to what you might use in C/C++ or MATLAB. Here are some examples:
Description | Syntax |
---|---|
Statistics from Channel 2 Spectrum trace data | stats(Data('Spectrum2')) |
Difference of Channel 1 Time and Channel 2 Time | Data('Time1') - Data('Time2') |
Transfer function between channel 1 and 2 | Data('Spectrum2') / Data('Spectrum1') |
Also, see Creating Math Functions.
Constants (fixed)
You can select a fixed constant from the drop-down list:
π |
√2 |
c(speed of light in m/s) |
Constants (numerical)
You can use numerical constants in an expression. Here are some examples:
Real number | -2 |
Complex number | (1 + j1) |
Number with exponential | 3E9 |
Operators
There are several operators available:
x / y | Divide x by y |
x * y | Multiply x by y |
x - y | Subtract y from x |
x + y | Add x to y |
x^y | x to the y exponent |
-x | Negate x |
When x and y are vectors, the operation is performed point by point on the values in the data vectors (e.g. for multiplication, x * y = [ x[0]*y[0], x[1]*y[1], ... ]).
When x is a scalar and y is a vector, the value of x is added to each point in y.
Data
From the Math Functions dialog, you can select an operand to use in the math function's expression. The operand is any valid trace data or the contents of a data register. Only data registers that contain data are listed. For details about data registers, see Saving and Recalling Data Registers.
menu in theFor details about any of the listed trace data, see the Trace Data book in the table of contents for the appropriate measurement type.
Trace windows are used to view a particular trace and transform the data (scaling, trace format, etc.). However, Math Functions operate on the underlying trace data vectors, so the trace data does not need to be shown in a trace window to be used in a Math Function.
The syntax to insert data into a math function Expression is as follows:
Data('dataname')
where dataname is the Data Name of the trace data or register. The Data Name is a unique identifier for a trace and does not match the trace window's title (which is formatted differently and contains other information, such as demod format). You can mouse over a trace window's title to view the tooltip, which will show the Data Name for the trace data shown in that particular trace window.
Functions
There are other functions that you can use to work with the trace data in the math expression. The following table contains information about each of the available functions:
Function | Description | Expected data |
---|---|---|
conj(x) |
Calculate the complex conjugate of the elements in x Re{x} - j*Im{x} |
Doesn't matter |
cos(x) |
Calculate the cosine of the elements in x. |
Doesn't matter |
diff(x) | Calculate the differences of adjacent elements of x. | Doesn't matter |
exp(x) |
Compute the natural antilog of the elements in x. The natural antilog (e^k) of a complex number k = a + jb is defined as e^(a+jb) = e^a * (cos b + j*sin b). |
Doesn't matter |
exp10(x) |
Compute the common antilog of the elements in x. The common antilog (10^k) of a complex number k = a + jb is defined as 10^(a+jb) = 10^a * (cos b*L10 + j*sin b*L10), where L10 is the natural log of 10. |
Doesn't matter |
flat(x) | Apply a flat top window to the vector x. | Time domain |
gauss(x) | Apply a gaussian window to the vector x. | Time domain |
hann(x) | Apply a Hann window to the vector x. | Time domain |
fft(x) |
Perform a Fast Fourier Transform of x. Use the flat(), gauss(), or hann() function to window the time data. |
Time domain |
ifft(x) | Perform an Inverse Fast Fourier Transform of the vector x. | Frequency domain |
imag(x) | Compute the imaginary part of the elements in x. | Doesn't matter |
jw(x) |
This function creates an vector of complex values equal to jω. (where ω = 2π * frequency). The frequency values to use are provided by the input vector x. For example, say that x is a spectrum trace with center = 10 MHz Megahertz: A unit of frequency equal to one million hertz or cycles per second. and span = 5 MHz and has 801 points. Then jw(x) would contain 801 points, with value (j * 2π * 7.5 MHz) at the start of the vector through (j * 2π * 12.5 MHz) at the end of the vector. |
Frequency domain |
log(x) | Compute the natural log (base e) of the elements in x. | Doesn't matter |
log10(x) | Compute the common log (base 10) of the elements in x. | Doesn't matter |
mag(x) | Compute the magnitude of the elements in x. | Doesn't matter |
magsq(x) | Compute the magnitude squared of the elements in x. | Doesn't matter |
neg(x) | Negate the elements of x. | Doesn't matter |
peak(x) |
Compute the peak of the elements in x. If the operand is complex, then the value with the maximum magnitude is calculated. |
Doesn't matter |
phase(x) | Compute the phase of the elements in x. | Doesn't matter |
real(x) | Compute the real part of the elements in x. | Doesn't matter |
sin(x) |
Calculate the sin of the elements in x. |
Doesn't matter |
smoothing(x,y) |
Smooths the response data in x using a triangular moving average filter of length y (in points). |
Doesn't matter |
sqrt(x) | Compute the square root of the elements in x. | Doesn't matter |
square(x) | Compute the square of the elements in x. | Doesn't matter |
stats(x) |
Compute a table of statistics describing the data in the vector x. See section below for more information about the contents of this table. |
Doesn't matter |
tan(x) |
Calculate the tangent of the elements in x. |
Doesn't matter |
unwrap(x) |
Unwrap the phase of x. This assumes the data in x is phase data. Use unwrap(phase(data)) to compute the phase of an operand and then unwrap the phase. |
Phase data |
xcorr(x,y) | Compute the cross-correlation between x and y. | Doesn't matter |
zero(x) | Output is a vector, sized to match the operand, filled with zeros. | Doesn't matter |
Stats() table reference
When the stats() function is applied to a data vector, the following items are calculated:
All calculations work directly on the Y-axis values of the data if the trace is real-valued, or on the magnitude of the Y-axis values when the data is complex. In the table below, "Y values" means either Y or mag(Y) depending on whether the trace is real or complex.
Metric name |
Description |
---|---|
Points |
Total number of Y points in the trace. |
Delta |
X-axis delta between points. |
Length |
If the trace is NOT in the frequency domain, the value is Points * Delta. If the trace is in the frequency domain, the value is usually (Points-1)*Delta. When Show All Frequency Points is selected, then the value may be calculated as is Points * Delta under certain conditions. |
Mean |
Mean of the Y values. 1/Points * sum(y[n], n = 0...Points-1) |
Sum |
Sum of the Y values. sum(y[n], n = 0…Points-1) |
Mean Sqrs |
Mean of the magnitude squared of the Y values. 1/Points * Sum(mag(y[n])^2, n = 0...Points -1) |
Sum Sqrs |
Sum of the magnitude squared of the Y values. Sum(mag(y[n])^2, n = 0…Points-1) |
RMS |
RMS value of the Y values. Sqrt(Mean Sqrs) |
SmSqr/ENBW |
If the trace is frequency domain, this is Sum Sqrs / (ENBW * zeroPaddingRatio). Otherwise, this is just equal to Sum Sqrs. where zeroPaddingRatio = original time-domain points / actual FFT Fast Fourier Transform: A mathematical operation performed on a time-domain signal to yield the individual spectral components that constitute the signal. See Spectrum. points The length of the time data from which the frequency-domain trace was calculated may not have been a power of 2. In this case, the time data is zero-padded to the next power of 2 for the FFT. The zeroPaddingRatio adjusts the SmSqr/ENBW calculation to account for the frequency-domain trace having more points than the original time-domain trace. |
Median |
Median of the Y values. |
Harm Mean |
Harmonic mean of the Y values. Points / sum(1/y[n], n = 0...Points-1) |
Max |
Maximum Y value. |
Min |
Minimum Y value. |
Max Abs |
Y value with maximum absolute value (for complex data, this is the same as Max, because we are operating on magnitudes already). |
Min Abs |
Y value with minimum absolute value (for complex data, this is the same as Min, because we are operating on magnitudes already). |
InterpPeak |
Interpolated peak Y value, calculated by using a quadratic fit between points, and finding the peak of the resulting waveform. |
InterpPkLoc |
The X-axis location of the interpolated peak Y value. This can be between the actual X-axis values of the data. |
Peak/RMS |
Max Y value / RMS |
Slope |
The slope of a line that is fit to the data. A linear regression is done to compute the line. |
Intercept |
The Y-axis intercept of a line that is fit to the data. A linear regression is done to compute the line. |
Correlation |
Correlation value from the linear regression. The value is between -1 and 1. Values with larger absolute value indicate that the linear regression line is a good approximation of the relationship between X and Y. |
Std Dev |
Standard deviation of the Y values. This is the estimated population standard deviation, not the sample standard deviation. sqrt(Variance) |
Variance |
Variance of the Y values. This is the estimated population variance, not the sample variance. Points/(Points - 1) * (Mean(Y^2) - Mean(Y)^2) |
Skew |
Skew of the Y values. Skew is a measure of whether the data has a longer tail towards the left (negative skew) or towards the right (positive skew), and is sort of a third-order equivalent of standard deviation. |
Kurtosis |
Kurtosis of the Y values. Kurtosis is a measure of the "spikiness" of the data, and is sort of a fourght-order equivalent of standard deviation. The kurtosis for Gaussian rand data averages to zero. |
See Also