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?
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It only takes a minute to sign up.
Sign up to join this communityI 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?
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 );
end
end
% 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.
Cheers!