TransWikia.com

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

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP