I calculated the $R_{xy}$ by cross-correlating $x(n)$ and $y(n)$.

Now, in the MATLAB command window, I wish to construct the Y-axis component of $R_{xy}(n)$. I'm not sure how I'm going to do it. Is there a built-in function that I can use?

  • $\begingroup$ The cross correlation has units that are the product of the units of the input signal. So if you are cross correlating a voltage with a current, the cross correlation would be in Watts (although it's not really a power). If you use the normalized cross correlation, the result is unit less and always confined on the interval $[-1,1]$ $\endgroup$
    – Hilmar
    Dec 7, 2021 at 15:42
  • $\begingroup$ Welcome to SE.SP! This question confuses me. What do you mean by the Y-axis? $R_{xy}(n)$ is a function of $n$, the lag between signals. $\endgroup$
    – Peter K.
    Dec 7, 2021 at 23:14

1 Answer 1


How are you?

So, if I understood appropriately, you computed the cross-correlation between $x(n)$ and $y(n)$ and you're trying to build the Y-axis for your plot. I'm assuming that you have mistook the X-axis for Y-axis since the cross-correlation $R_{xy}(n)$ is the Y-axis. In order words, you already have your Y-axis, it is $R_{xy}(n)$.

In order to define a X-axis for a cross-correlation between 2 signals, it is possible to initialize a vector with a length that is a sum of both $x(t)$ and $y(t)$ lengths. Similar with how convolution algorithm does. Bear in mind that your $R_{xy}(n)$ must have been previously initialized as a vector with the same length as your X_axis. You may do so in MATLAB with the following code

% ...Vectors x and y previously defined

N = length(x);
L = length(y);
Rxy = zeros(1,N+L);
X_axis = 0 : 1 : N + L - 1;

% compute cross-correlation...

The vector above is your X-axis given in the number of samples. If you have a sampling rate $f_s$ defined, you may turn X_axis into seconds by multiplying your X_axis by a factor of $1/f_s$ also known as the sampling period $T_s$.

X_axis = Ts * ( 0 : 1 : N + L - 1 );

We may compute the cross-correlation between x and y by the following:

for i = 1 : 1 : N
    for j = 1 : 1 : L
        Rxy( i + j ) = Rxy( i + j ) + x(i)*y( ( L + 1 ) - j );
% Scale result with total number of points in order... 
% ...to have the appropriate magnitude
Rxy = ( 1 / ( N * L ) ) .* Rxy; 

The algorithm above slides signal $y$ across time unflipped, performing a summation of products with $x$. Thus performing a cross-correlation.

Hope I was able to clarify your issue.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.