5

活動認識で使用するスライディングウィンドウアルゴリズムを作成したいと思います。

トレーニングデータは<1xN>なので、データを取得してトレーニングするだけでよいと思いwindow_size=3ますwindow_size。また、後でこのアルゴリズムを行列で使用したいと思います。

私はmatlabを初めて使用するので、これを正しく実装する方法についてアドバイスや指示が必要です。

4

1 に答える 1

10

簡単な答え:

%# nx = length(x)
%# nwind = window_size
idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix(nx/nwind)-1))*nwind)-1;

idxサイズはnwind-by-Kの行列になります。ここで、Kはスライディングウィンドウの数です(つまり、各列には1つのスライディングウィンドウのインデックスが含まれます)。

上記のコードでは、最後のウィンドウの長さが目的のウィンドウより短い場合、ドロップされることに注意してください。また、スライディングウィンドウは重複していません。

説明する例:

%# lets create a sin signal
t = linspace(0,1,200);
x = sin(2*pi*5*t);

%# compute indices
nx = length(x);
nwind = 8;
idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix(nx/nwind)-1))*nwind)-1;

%'# loop over sliding windows
for k=1:size(idx,2)
    slidingWindow = x( idx(:,k) );
    %# do something with it ..
end

%# or more concisely as
slidingWindows = x(idx);

編集:

重なり合うウィンドウの場合、次のようにします。

noverlap = number of overlapping elements

次に、上記は単純に次のように変更されます。

idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix((nx-noverlap)/(nwind-noverlap))-1))*(nwind-noverlap))-1;


結果を表示する例:

>> nx = 100; nwind = 10; noverlap = 2;
>> idx = bsxfun(@plus, (1:nwind)', 1+(0:(fix((nx-noverlap)/(nwind-noverlap))-1))*(nwind-noverlap))-1
idx =
     1     9    17    25    33    41    49    57    65    73    81    89
     2    10    18    26    34    42    50    58    66    74    82    90
     3    11    19    27    35    43    51    59    67    75    83    91
     4    12    20    28    36    44    52    60    68    76    84    92
     5    13    21    29    37    45    53    61    69    77    85    93
     6    14    22    30    38    46    54    62    70    78    86    94
     7    15    23    31    39    47    55    63    71    79    87    95
     8    16    24    32    40    48    56    64    72    80    88    96
     9    17    25    33    41    49    57    65    73    81    89    97
    10    18    26    34    42    50    58    66    74    82    90    98
于 2010-02-04T21:24:45.320 に答える