function [Bisp, freq] = sBistemp(x, y, z, minfreq, maxfreq, samplingrate, freqsamplingrate, T) % Bistemp calculates the bicoherence between three signals x, y, and z % within a given time window T, using the S_transform. % The bicoherence is calculated for frequencies between minfreq and maxfreq, % with a sampling rate of freqsamplingrate. % The sampling rate of the signals is given by samplingrate. % The output Bisp is the bicoherence matrix and freq is the frequency vector. tmin = T(1); tmax = T(end); % Calculate the S_transform for x and y [stx,t,freq] = st(x, minfreq, maxfreq, samplingrate, freqsamplingrate); if isequal(x, y) % if x and y are the same signal, reuse the stx matrix sty = stx; else % otherwise, calculate the S_transform for y [sty,~,~] = st(y, minfreq, maxfreq, samplingrate, freqsamplingrate); end % Calculate the S_transform for z [stz,~,~] = st(z, minfreq, maxfreq, samplingrate, freqsamplingrate); % Find the indices of the time window in the S_transform matrices i1 = max(floor(tmin*freqsamplingrate), 1); i2 = min(floor(tmax*freqsamplingrate), length(freq)); % Cut the S_transform matrices to the appropriate time window stx = stx(:, i1:i2); sty = sty(:, i1:i2); stz = stz(:, i1:i2); nf = length(freq); Bisp = zeros(nf, nf); for i = 1:nf f1 = freq(i); start = 1; if isequal(x, y) start = i; end for j = start:nf f2 = freq(j); f3 = f1 + f2; idx3 = find(freq >= f3, 1); if (idx3 <= nf)&(freq(idx3) > freq(max(i,j))) Bisp(i, j) = mean(stx(i,:) .* sty(j,:) .* conj(stz(idx3,:))); end end end end将这个代码的输出Bisp在f2=0,时进行幅值归一化,给出代码
时间: 2024-01-05 22:02:07 浏览: 116
在f2=0时进行幅值归一化,可以将代码修改为如下形式:
```matlab
function [Bisp, freq] = sBistemp(x, y, z, minfreq, maxfreq, samplingrate, freqsamplingrate, T)
% Bistemp calculates the bicoherence between three signals x, y, and z
% within a given time window T, using the S_transform.
% The bicoherence is calculated for frequencies between minfreq and maxfreq,
% with a sampling rate of freqsamplingrate.
% The sampling rate of the signals is given by samplingrate.
% The output Bisp is the bicoherence matrix and freq is the frequency vector.
tmin = T(1);
tmax = T(end);
% Calculate the S_transform for x and y
[stx,t,freq] = st(x, minfreq, maxfreq, samplingrate, freqsamplingrate);
if isequal(x, y) % if x and y are the same signal, reuse the stx matrix
sty = stx;
else % otherwise, calculate the S_transform for y
[sty,~,~] = st(y, minfreq, maxfreq, samplingrate, freqsamplingrate);
end
% Calculate the S_transform for z
[stz,~,~] = st(z, minfreq, maxfreq, samplingrate, freqsamplingrate);
% Find the indices of the time window in the S_transform matrices
i1 = max(floor(tmin*freqsamplingrate), 1);
i2 = min(floor(tmax*freqsamplingrate), length(freq));
% Cut the S_transform matrices to the appropriate time window
stx = stx(:, i1:i2);
sty = sty(:, i1:i2);
stz = stz(:, i1:i2);
nf = length(freq);
Bisp = zeros(nf, nf);
for i = 1:nf
f1 = freq(i);
start = 1;
if isequal(x, y)
start = i;
end
for j = start:nf
f2 = freq(j);
f3 = f1 + f2;
idx3 = find(freq >= f3, 1);
if (idx3 <= nf)&(freq(idx3) > freq(max(i,j)))
bisp = mean(stx(i,:) .* sty(j,:) .* conj(stz(idx3,:)));
if f2 == 0 % f2=0时进行归一化
bisp = bisp / abs(bisp);
end
Bisp(i, j) = bisp;
end
end
end
end
```
在这个修改后的代码中,当 f2=0 时,我们计算出 bisp = mean(stx(i,:) .* sty(j,:) .* conj(stz(idx3,:))),然后将其进行幅值归一化,即将 bisp 除以 abs(bisp)。最后将得到的归一化结果赋给 Bisp(i, j)。
阅读全文