我正在建模和干涉测量,想要找到穿过探测器的条纹数量。数据相当密集,它会导致 findpeaks 出现问题,我试图使用 parfor 来加快速度。当然 parfor 不存在于八度音程中,所以我想知道处理这个问题的最佳方法。
这是我最初尝试的;
```
parfor i = 1:N
start = round(((i-1)/N)*length(IT))+1;
stop = round((i/N)*length(IT));
partime = time(start:stop);
[row,col] = findpeaks(IT(start:stop)./max(IT(start:stop))); % Fringe Frequency
pklk = [pklk partime(col)];
end
```
这是使用正则表达式实现
findpeaks
:
findpeaks = @(data) regexp(char(sign(diff(reshape(data, 1, []))) + '1'), '21*0') + 1;
返回峰的位置。将其用作:
col = findpeaks(IT);
pklk = time(col);
findpeaks
的Octave实现使用bsxfun
来扩展需要n^2
内存的索引向量。
更新
添加了两个选项
height
和 dist
。此外,该函数现在有两个输出:pks
局部最大值和locs
峰值位置。
function [pks, locs] = findpeaks(data, height, dist)
% find all peaks
locs = regexp(char(sign(diff(reshape(data, 1, []))) + '1'), '21*0') + 1;
% apply MinPeakHeight
locs = locs(data(locs) > height) ;
% apply MinPeakDistance
[~, isorted] = sort(data(locs), 'descend');
n = numel(data);
idx = false(1, n);
idx(locs) = true;
for s = reshape(isorted, [], 1)
if (idx(s))
idx(max(s - dist, 1):min(s + dist, n)) = 0;
idx(s) = 1;
end
end
locs = find(idx);
pks = data(locs);
end`