Correlation about two neural signals in specific time
5 次查看(过去 30 天)
显示 更早的评论
new_fs = 1000;
window = 1*new_fs; % 1 second of window
start_stop_plot=[872 1016];
start_stop_plot_points_bin = [start_stop_plot(1)*new_fs, start_stop_plot(2)*new_fs];
correlation_bin = zeros(start_stop_plot_points(2)-start_stop_plot_points(1),1);
for t_bin = start_stop_plot_points_bin(1):start_stop_plot_points_bin(2)-window;
spectrum1_t = mean_value_data_smooth_1(t_bin:t_bin+window-1);
spectrum2_t = mean_value_data_smooth_2(t_bin:t_bin+window-1);
correlation(t)=corr(spectrum1_t,spectrum2_t);
end
I attached mean_value_data_smooth_1 e 2.
The problem is the index exceedes the number of arrays. Can you help me??
0 个评论
回答(1 个)
Saarthak Gupta
2023-9-13
编辑:Saarthak Gupta
2023-9-13
Hi,
I understand you are trying to find the rolling correlation between the two signals (‘mean_value_data_smooth_1’ and ‘mean_value_data_smooth_1’).
Both signals have 272 data points. However due to a window size of 1000, you are accessing sub signals of length 1000 which are larger than the signal itself. Moreover, the start and stop points have been incorrectly specified.
Please refer to the following code to obtain the rolling correlation between two signals:
function corrs_list = rollingCorrelation(data1, data2, startIdx, stopIdx, windowSize)
% data1 and data2 must be row vectors
n = min(size(data1,1), size(data2,1));
corrs_list = zeros([stopIdx-startIdx+1 1]);
for i=startIdx:stopIdx
if i+windowSize-1>n
break;
end
sample1 = data1(i:i+windowSize-1);
sample2 = data2(i:i+windowSize-1);
corrs_list(i-startIdx+1) = corr(sample1, sample2);
end
end
The function returns a list of correlations between all sub signals of size ‘windowSize’ in the given data, between start and stop indices (‘startIdx’ and ‘stopIdx’, respectively).
Please refer to the following MATLAB documentation for more details:
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Industrial Statistics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!