如何找到特定的时间间隔两个正弦波之间的相关性,并保存在一个数组的价值呢? [英] How to find correlation between two sine waves for specific intervals and save the value in an array?

查看:129
本文介绍了如何找到特定的时间间隔两个正弦波之间的相关性,并保存在一个数组的价值呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了两台正弦波不同的频率。这两个波的时间是2秒或2000msecs。 code效果很好,当我找到整个时间段的相关值。 Buth我想每200毫秒的时间间隔后得到的相关值。这意味着我需要可以存储10个相关值对整个2000msecs的数组。这里的code我如何计算2000msecs一段时间的相关性。

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)

请帮我如何创建一个数组来commpute每200毫秒相关值。

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

推荐答案

我不知道究竟你的 corr2 {} 做,但关于你的问题这将创建您的200ms的步骤

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

我添加了N2和N3部分,其中N3_array现在包含了一段200毫秒

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')

您可能需要调整图

这篇关于如何找到特定的时间间隔两个正弦波之间的相关性,并保存在一个数组的价值呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆