correlation of 2 signals

4 visualizzazioni (ultimi 30 giorni)
ali hassan
ali hassan il 28 Nov 2020
Commentato: Image Analyst il 28 Nov 2020
Actually I am corelating two signals but my question is that in graph the correlation should be between -1 and 1 but it is not like that code:
t=linspace(0,1000,100001) %in ms xs=randn(1,100001)
grid on
subplot(3,1,1) plot(t,xs) title('SIGNAL RECEIVED AT MASTER')
shift_ms = 10; %SIGNAL RECEIVED AT RECEIVER 1(TIME DELAYING THE DISCRETE SIGNAL) x1=circshift(xs,shift_ms*.1); %signal received at receiver 1
% subplot(3,1,2) plot(t,x1) title('SIGNAL RECEIVED AT RECEIVER#1')
[c,lags]=xcorr(xs,x1);
subplot(3,1,3)
plot(lags,c)
title('CORRELATION OF RECEIVER 1 AND PROCESSING UNIT')
[maxval indx]=max(c) %[xMax,idx] = max(x) returns two outputs.first is max value of x and second is max index value maxval
shiftCalc_ms = (length(t)-indx)/10
t21 = finddelay(xs,x1)

Risposte (1)

KALYAN ACHARJYA
KALYAN ACHARJYA il 28 Nov 2020
Modificato: KALYAN ACHARJYA il 28 Nov 2020
clc; clear;close all;
%%
t=linspace(0,1000,100001); %in ms
xs=randn(1,100001);
subplot(3,1,1),plot(t,xs);
title('SIGNAL RECEIVED AT MASTER')
shift_ms = 10; %SIGNAL RECEIVED AT RECEIVER 1(TIME DELAYING THE DISCRETE SIGNAL)
x1=circshift(xs,shift_ms*.1); %signal received at receiver 1
subplot(3,1,2)
plot(t,x1),title('SIGNAL RECEIVED AT RECEIVER#1')
[c,lags]=xcorr(xs,x1);
subplot(3,1,3),plot(c,lags)
title('CORRELATION OF RECEIVER 1 AND PROCESSING UNIT')
[maxval,indx]=max(c);
[xMax,idx] = max(xs);
shiftCalc_ms=(length(t)-indx)/10;
t21=finddelay(xs,x1);
  2 Commenti
ali hassan
ali hassan il 28 Nov 2020
https://www.mathworks.com/matlabcentral/answers/666543-correlation-of-2-signals#answer_558383 thankyou sir for your kind help. but now the graph is between 10^5 and 10^-5
Image Analyst
Image Analyst il 28 Nov 2020
The correlation is the sum of the products of the overlapped elements, so there is no guarantee that that sum will be between 0 and 1. If you want it to be in that range, then you must call rescale():
scaledSignal = rescale(signal, 0, 1);

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by