correlation of 2 signals

3 次查看(过去 30 天)
ali hassan
ali hassan 2020-11-28
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)

回答(1 个)

KALYAN ACHARJYA
KALYAN ACHARJYA 2020-11-28
编辑:KALYAN ACHARJYA 2020-11-28
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 个评论
ali hassan
ali hassan 2020-11-28
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 2020-11-28
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);

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by