给定MATLAB中信号的索引点从左到右提取一定数量的样品



有一个矩阵Idx = [1xM],其索引数的m尺寸要提取。对于每个索引编号,应从从左到右提取一些样本,以形成原始信号的新子信号。例如,左侧的3个样本和索引号右侧的4个样本,请参见下面:

[idx-3:idx+4]

[new_sig]成为一个单行矩阵,而不是从索引矩阵 [Idx]

的索引编号的相同维度
Fs = 500; %Frequency:500
StartIdx = 0.150 * Fs;
EndIdx = 0.500 * Fs;
[Idx] = [.....];
[New_Sig] = [Idx-StartIdx : Idx+EndIdx];

这是的示例>两个索引点从下面的Idx矩阵:

[Idx] = [2 19 23 43 48 52 62 74 78 79 81]
old_sig = [-2 0 1 2 5 6 7 8 10 19 20 21 22 23 24 25 ...]
if # of sample from left = 3, # of sample from right = 4:
a_new_sub = [-2 0 1 **2** 5 6 7 8]
b_new_sub = [7 8 10 **19** 20 21 22 23]
.....

这是我解决此问题的建议:

StartIdx = 3;
EndIdx = 4;
Idx = [2 19 23];
old_sig = [-2 0 1 2 5 6 7 8 10 19 20 21 22 23 24 25 26 27 28 29];
% Get number of "indices".
nIdx = numel(Idx);
% Find actual indices.
idx = ceil(find(repmat(old_sig, nIdx, 1) == repmat(Idx', 1, numel(old_sig))) / nIdx);
% Set up correct (index) ranges to access in old_sig.
idx = repmat(-StartIdx:EndIdx, nIdx, 1) + repmat(idx, 1, (StartIdx + EndIdx + 1));
% Determine output.
new_sig = old_sig(idx)

作为输出,我们得到:

new_sig =
   -2    0    1    2    5    6    7    8
    7    8   10   19   20   21   22   23
   20   21   22   23   24   25   26   27

警告:目前,您的old_sig包含唯一的值。因此,find将找到正确的(唯一(索引。如果信号中的值确实重复,则需要指定应找到哪个值。

另一个警告:取决于信号old_sig的大小以及您在Idx中有多少个索引,此方法可能会得到记忆的密集。

最新更新