How to calculate frequency coherence between two signals.

6 ビュー (過去 30 日間)
dark lion
dark lion 2017 年 12 月 6 日
編集済み: dark lion 2017 年 12 月 6 日
I have two signals of equal length, and I have plotted the power spectral density plots of the two signals, I need to calculate the coherence between the two signals in terms of frequency. (ie., at what frequencies the signals are exhibiting identical behaviour). I need to plot coherence with frequency on x axis. how can we do that . I have added the matlab code , i am attaching (eeginput) and (resampledeegoutput) files which are loaded into matlab 'for reference'.
dataset=xlsread('eeginput.xlsx','sheet1','A1:B769');
t1 = dataset(:,1);
V1 = dataset(:,2);
X1=[t1 V1];
t1_resampled = linspace(min(t1), max(t1), length(t1));
V1_resampled = resample(V1, t1);
Ts = mean(diff(t1_resampled));
Fs = 1/Ts;
L=length(V1_resampled); %length of the signal
NFFT=2^nextpow2(L); %next power of 2 from length y
P1=abs(fft((V1_resampled-mean(V1_resampled)),NFFT)).^2./L;
fc1=Fs/2*linspace(0,1,NFFT/2+1);%frequency
subplot(2,2,1);
plot(fc1,P1(1:length(fc1))*2);
set(gca,'XLim',[0 100]);
xlabel('frequency');
ylabel('power');
title('PSD of input signal');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
dataset=xlsread('resampledeegoutput.xlsx','sheet1','A1:B769');
t2 = dataset(:,1);
V2 = dataset(:,2);
X2=[t2 V2];
t2_resampled = linspace(min(t2), max(t2), length(t2));
V2_resampled = resample(V2, t2);
Ts = mean(diff(t2_resampled));
Fs = 1/Ts;
L=length(V2_resampled); %length of the signal
NFFT=2^nextpow2(L); %next power of 2 from length y
P2=abs(fft((V2_resampled-mean(V2_resampled)),NFFT)).^2./L;
fc2=Fs/2*linspace(0,1,NFFT/2+1);%frequency
subplot(2,2,2);
plot(fc2,P2(1:length(fc2))*2);
set(gca,'XLim',[0 100])
xlabel('frequency');
ylabel('power');
title('PSD of output signal');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by