How to find correlation between two sine waves for specific intervals and save the value in an array?

喜欢而已 提交于 2019-12-10 12:06:51

问题


I have created two sine wave each with a different frequency. Time period for both waves is 2sec or 2000msecs. Code works well when i find correlation value for whole time period. Buth i want to get correlation values after every 200msec interval. That means i need an array that can store 10 correlation values for the whole 2000msecs. Here's the code how am i calculating correlation for time period of 2000msecs.

delta=0.005; %200 hz Fs 
samples=200;
t=0:delta:delta*(samples-1); % Time Samples 1second
ch1 = sin(2*pi*10*t)';
ch2 = sin(2*pi*20*t)';
cc=corr2{ch1,ch2};
figure; bar(cc)

Please help me how to create an array to commpute correlation value for every 200msec.


回答1:


I am not sure what exactly your corr2{} does but concerning your question this creates your 200ms steps:

related to your comment I added the part with N2 and N3 where N3_array now contains the sum of N3 over a period of 200 ms

clear all
delta=0.005; %200 hz Fs 
samples=200;
t=0:delta:delta*(samples-1); % Time Samples 1second
ch1 = sin(2*pi*10*t)';
ch2 = sin(2*pi*20*t)';
data=[ch1 ch2];

corr_period = 0.2; % in seconds (200 ms)
nsteps = corr_period/delta;
icorr = 1;
cc = zeros(ceil(samples/nsteps),1);
N3_array = zeros(ceil(samples/nsteps),2);
for it = 1:nsteps :samples
   %cc(icorr)=corr2{ch1(it:it+nsteps-1 ),ch2(it:it+nsteps-1 )};
   N2=angle(data(it:it+nsteps-1 ,:)); 
   N3=sum([N2(:,1) N2(:,2)],1);
   N3_array(icorr,:) = N3;
   t_plot(icorr) = mean(t(it:it+nsteps-1 ));
   icorr = icorr+1;
end
figure; plot(t_plot,N3_array)
legend('signal 1', 'signal 2')

you might need to adjust the graph



来源:https://stackoverflow.com/questions/33807655/how-to-find-correlation-between-two-sine-waves-for-specific-intervals-and-save-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!