# Calculating the Running Corrleation of two signals in Matlab

Electrical Engineering Asked on December 5, 2020

I am currently using https://www.eecs.umich.edu/courses/eecs206/public/lab/ 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?

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.';
end


## Related Questions

### Is there such a thing as an automatic variable resistor

2  Asked on December 15, 2021

### 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

### Determining AXI4-stream Data FIFO size, understanding Packet Mode?

1  Asked on December 15, 2021 by comc-cmoc

### Standards Compliant High DC Load Safety Interlock System

0  Asked on December 15, 2021 by buttercup

### Button short press and long press without using microcontroller

2  Asked on December 15, 2021 by spockshr

### read negative voltage with mcp3008

1  Asked on December 15, 2021

### How to learn PID Control?

6  Asked on December 12, 2021

### Using car charger for small sealed-type lead-acid batteries

6  Asked on December 12, 2021

### Why does only the fermi level shift in a semiconductor under an external electric field?

1  Asked on December 12, 2021

### Variation of Fermi level in doped semiconductor with applied voltage

2  Asked on December 12, 2021 by tvv

### Solving circuit design problem with two approaches

1  Asked on December 12, 2021

### L-C-L vs Pi network

1  Asked on December 12, 2021

### What is the “DanTherm” model in the SOATherm library in LTSpice?

0  Asked on December 12, 2021 by spice_rack

### Is there any limitation in how quickly/often I can change a 6V DC motor direction of rotation?

1  Asked on December 12, 2021

### How to light LEDs with Arduino without having any resistors

6  Asked on December 12, 2021

### How do I connect this crane machine motherboard to my power supply? What connectors do I need for the power supply header pins?

1  Asked on December 12, 2021 by sam-jacka

### Magnetic vector potential and displacement current

2  Asked on December 12, 2021 by pr871