Extract windows from signals
古いコメントを表示
Hello to all,
i have a large signal and a vector containing moments of time (in the form of index). The vector represents moments in time where I must extract a window from the signal. I can do it with a for loop, but given the size of the signal (36million points), this takes too long. Here is my code
for i = 1:1:length(vector_index)
windows = signal( vector_index(i):vector_index(i) + window_length);
end
I there a more straightforward (and optimal) piece of code which I can insert?
Best regards,
Jean
1 件のコメント
Jan
2011 年 10 月 5 日
Currently your code does not calculate anything. A better solution can be found depending on the actual calculations, but without knowing the details, the shown code looks optimal. What is "vector_index"?
採用された回答
その他の回答 (1 件)
Dr. Seis
2011 年 10 月 5 日
Are you processing that window of samples inside the loop where you create your "windows" variable. Or are you saving it to do processing elsewhere in your code? If you are using "windows" outside of your for loop, then you should initialize windows before the for loop as:
windows = zeros(length(vector_index),window_length);
Then you would change "windows" inside your for loop to:
windows(i,:) = signal( vector_index(i):vector_index(i) + window_length);
I am not sure if there is a significantly faster way of doing this, how many windows are you extracting from your data and what is the window length?
5 件のコメント
Jean
2011 年 10 月 5 日
Jan
2011 年 10 月 5 日
And do you need the values for each signal, or is it enough to perform the operations on the separate vectors?
Jean
2011 年 10 月 5 日
Dr. Seis
2011 年 10 月 5 日
Oh, actually the "windows" inside your for loop should be:
windows(i,:) = signal( vector_index(i):vector_index(i) + window_length - 1);
so that there are actually (in your case) exactly 3500 points in your window (otherwise you get 3501).
Does pre-allocating help any?
Sean de Wolski
2011 年 10 月 5 日
preallocating windows would help.
カテゴリ
ヘルプ センター および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!