correlation of 2 signals

조회 수: 5 (최근 30일)
ali hassan
ali hassan 2020년 11월 28일
댓글: Image Analyst 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);

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by