Extract windows from signals
Ältere Kommentare anzeigen
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 Kommentar
Jan
am 5 Okt. 2011
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"?
Akzeptierte Antwort
Weitere Antworten (1)
Dr. Seis
am 5 Okt. 2011
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 Kommentare
Jean
am 5 Okt. 2011
Jan
am 5 Okt. 2011
And do you need the values for each signal, or is it enough to perform the operations on the separate vectors?
Jean
am 5 Okt. 2011
Dr. Seis
am 5 Okt. 2011
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
am 5 Okt. 2011
preallocating windows would help.
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!