correlation of 2 signals
5 views (last 30 days)
Show older comments
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)
0 Comments
Answers (1)
KALYAN ACHARJYA
on 28 Nov 2020
Edited: KALYAN ACHARJYA
on 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 Comments
Image Analyst
on 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);
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!