0

我有一个关于 findpeaks 的问题。我想用它来检测我的信号时间序列(信号 1)中的峰值。这很好用,但我也有替代数据,作为重要性阈值,长度相等(信号 2)。我现在想在信号 1 上使用 findpeaks,但前提是信号 1 在那个时间点大于信号 2。我尝试使用 findpeaks 的常规属性,但到目前为止没有任何效果......这是我现在所拥有的:

GPDC是 9x9x512 双倍。Dim 1 包含通过多变量自回归模型在方向 xi - xj 上估计的部分定向相干值, Dim 2 包含与 xj -xi 相同的值,并且 Dim 3 表示频率区间的数量。eEPDCsth是一个 9x9x512 双精度值,包含相应的代理数据。f是一个 1x512 双精度值,包含频率值。我认为现在, >= 参考不起作用,因为它不是特定时间的,即它不会逐点比较信号,而是总体比较。这是我认为的主要问题...

Sz=9;
for i=1:Sz
    for j=1:Sz
    if squeeze(GPDC(i,j,:)) >= squeeze(eEPDCsth(i,j,:))
       [pks_1{i,j},locs_1{i,j}] = findpeaks(squeeze(GPDC(i,j,:)),f,'npeaks',5,'MinPeakHeight', .1);
    end
    end
end
4

2 回答 2

1

这是一个应该完成您所描述的示例。您没有指定 'f' 向量的实际内容,因此在本示例中我将其设置为 1:512

% data for testing
GPDC = rand(9,9,512);
eEPDCsth = rand(9,9,512);
f = 1:512; % the value of the 'f' vector wasn't specified in question

Sz=9;
for i=1:Sz
    for j=1:Sz
        % find the 'raw' peaks below thresholding
        [peak_val_raw, peak_indices_raw] = findpeaks(squeeze(GPDC(i,j,:)),'npeaks',5,'MinPeakHeight', .1);

        % only keep peaks that are above the corresponding threshold value
        peaks_above_threshold = squeeze(GPDC(i,j,peak_indices_raw)) > squeeze(eEPDCsth(i,j,peak_indices_raw));
        peak_values_thresholded = peak_val_raw(peaks_above_threshold);
        peak_indices_thresholded = peak_indices_raw(peaks_above_threshold);

        pks_1{i,j} = peak_values_thresholded;
        % index into 'f' vector to match code in original question
        locs_1{i,j} = f(peak_indices_thresholded); 

    end
end
于 2018-10-14T16:18:19.197 回答
1

不确定我是否正确理解了这个问题。从您的代码中可以清楚地看出,您有峰值数据和这些峰值出现的坐标。

如果您只想要第二个时间序列具有较低值的峰值,“只需遍历所有峰值 - 检查 peak(i) 值是否低于 locs(i) 处的第二个序列的值 - 删除较低的峰值比相同位置的第二个系列的值”

希望这可以帮助。

于 2018-10-14T15:47:10.527 回答