performance - 具有重叠的信号分割

标签 performance matlab matrix vectorization

我有一些信号。它们的长度都相同 (N = 1024)。我必须将每个分解成 Ns = 7 个具有 L = 256 点的片段,这样就会有 50% 的重叠。 S = randi(10,[4 N]); 可以被认为是 4 个信号。我正在考虑将断点保存在一个向量中(手动计算它们!)并使用两个循环将新的 4 * Ns = 28 信号保存在一个单元格中,但这不是一个好主意解决方案。那么有没有像reshape这样更快的方法呢?

最佳答案

这可能是一种方法-

%// Parameters
N = 1024
L = 256
num_seg = 2*(N/L)-1

%// Indices for the first signal with each column representing one segment.
%// Thus, there must be 7 columns, representing those 7 segments in a signal.
signal1_idx = bsxfun(@plus,[1:L]',[0:num_seg-1]*L/2);  %//'

%// Indices for the all the signals in a 3D array with each 3D slice
%// representing one signal 
allsignals_idx = bsxfun(@plus,signal1_idx,permute([0:size(S,1)-1]*N,[1 3 2]))

%// Index into the input array to create a 3D array output 
St = S'  %//'
out = St(allsignals_idx)

如何解释输出,out:

  • out 的每个切片中的每一列都是一个信号的一个片段。
  • 每个 3D 切片中的列数就是信号中的段数。
  • out 的每个 3D 切片对应每个信号。

N = 16 & L = 4 的示例运行:

>> S
S =
     6    10     9     2     3     1     8     8     4     5     7    10     5     8    10     9
     8     9     5     4     4     4     7     2     9     4     3     7     4     7     4     9
     5     4     5    10     7    10     7     9     2     7     2     8     9     9     1     4
     7     3     2     1     1    10     3     1     8     3     4    10     4     4     4    10
>> out
out(:,:,1) =
     6     9     3     8     4     7     5
    10     2     1     8     5    10     8
     9     3     8     4     7     5    10
     2     1     8     5    10     8     9
out(:,:,2) =
     8     5     4     7     9     3     4
     9     4     4     2     4     7     7
     5     4     7     9     3     4     4
     4     4     2     4     7     7     9
out(:,:,3) =
     5     5     7     7     2     2     9
     4    10    10     9     7     8     9
     5     7     7     2     2     9     1
    10    10     9     7     8     9     4
out(:,:,4) =
     7     2     1     3     8     4     4
     3     1    10     1     3    10     4
     2     1     3     8     4     4     4
     1    10     1     3    10     4    10

关于performance - 具有重叠的信号分割,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30246198/

相关文章:

mysql - 多表还是单表有多种类型?

matlab - 删除 MATLAB 中具有相同值的所有行

python - 如何绘制应力分布图?

php - 循环矩阵值

python - 对角线相同的矩阵

c# - 连接字符串的最有效方法

c++ - vector访问速度,哪种方法更快?

C++循环展开性能

python - 'matlab.object' 对象无法使用 matlab 引擎调用

c# - 如何在 C# 中绘制二维等高线图?