Calculating the Running Corrleation of two signals in Matlab

Electrical Engineering Asked on December 5, 2020

I am currently using to advance my matlab skills. Sadly I am stuck at lab2 task 2. First, i cant run the pcode file to get the proper solution because matlab always complains about Warning: Skipping argument 'run_corr_demo', no MATLAB code found.> In pcode (line 211)

and my second problem is the output of the correlation, which should be zero because there is no correlation between these signals right?
enter image description here
Running Correlation of Code1 and Code 3
Maybe anyone has an idea of what I am doing wrong?
Here my code:

function out = run_corr(x,y);
%function out = run_corr(x,y);
% RUN_CORR -- This function implements the "real-time" running
% correlation algorithm.
% Input Parameters:
% x -- the signal to correlate with (i.e., the transmitted signal)
% y -- the signal to correlate against (i.e., the received signal)
% Output Parameters:
% out -- the resulting correlation signal with size equal to
% length(x) + length(y) - 1
% Written by Mark Bartsch, Winter 2002
% Modification History:
% 8/16/02 -- Added modification history (MB)
% Initialize the output vector to all zeros. It should have
% length(x) + length(y) - 1 elements.
out = zeros(1,length(x)+length(y)-1);
% Make x and y column vectors, regardless of incoming size
x = x(:);
y = y(:);
x = x.';
% Beyond the end of the signal y, the input is zero
y(end+1:end+length(x)) = 0;
% Buffer is just a column vector. We initialize it to
% all zeros (with the same size as x) to begin with.
buffer = zeros(size(x));
for n = 1:length(out)
% current_sample is the single-sample input to our "correlation box"
current_sample = y(n);
% Update the buffer. Discard the first sample in the buffer, and put
% current_sample at the end of the buffer.
buffer = ([buffer(2:end), current_sample]);
% From x and the contents of buffer, we can calculate
% the next output sample
out(n) = x*buffer.';

Add your own answers!

Related Questions

Constant current source with bypass option

2  Asked on December 15, 2021 by david-cutting


Automation – Stealing a signal from a circuit

1  Asked on December 15, 2021 by craig-monyhan


Clock usage in the always block and in the event

2  Asked on December 15, 2021 by animesh-srivastava


Standards Compliant High DC Load Safety Interlock System

0  Asked on December 15, 2021 by buttercup


Difference between LVDS SerDes and FPD-Link III SerDes?

1  Asked on December 15, 2021 by stephbadger


read negative voltage with mcp3008

1  Asked on December 15, 2021


L-C-L vs Pi network

1  Asked on December 12, 2021


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir