segmentation of a signal
8 views (last 30 days)
Show older comments
i have a nx3 matrix of a signal and i want to make small segments of 0.3 ms of this signal. using the following code i can make those segments but i am unable to store all the segments like frame1,frame2...last frame. i dont understand what am i missing in this code. and lastly i get the error"Warning: Integer operands are required for colon operator when used as index" when i use this code. the matrix name is prblm and it is 81920x3
fs=2048;
frame_duration=0.3;
frame_samples_length=(frame_duration*fs);
n= length(prblm);
number_of_frames=floor(n/frame_samples_length);
for k = 1:number_of_frames
frame = prblm((k-1)*frame_samples_length+1:frame_samples_length*k,:);
end
1 Comment
Priyanka Shanmuga Raja
on 9 Jun 2020
frame = prblm((k-1)*frame_samples_length+1:frame_samples_length*k,:);
I guess, here you are trying to index from 1 to a decimal. May be try using floor()
Accepted Answer
Ameer Hamza
on 9 Jun 2020
In your code, 'frame_samples_length' can be a floating-point number. Also, 81920 is not evenly divided by frame_samples_length. You are also not saving the output of loop operations.
Try mat2cell()
prblm = rand(81920, 3); % for example
fs=2048;
frame_duration=0.3;
frame_samples_length = floor(frame_duration*fs);
n = size(prblm, 1);
number_of_frames=floor(n/frame_samples_length);
frame_lengths = [frame_samples_length*ones(1, number_of_frames) n-number_of_frames*frame_samples_length];
parts = mat2cell(prblm, frame_lengths, 3)
'parts' is a cell array. Access it using brace indexing
parts{1} % first portion
parts{2} % second portion
..
..
parts{end} % last portion
0 Comments
More Answers (2)
KSSV
on 9 Jun 2020
fs=2048;
frame_duration=0.3;
frame_samples_length=(frame_duration*fs);
n= length(prblm);
number_of_frames=floor(n/frame_samples_length);
frame = zeros(number_of_frames,3) ;
for k = 1:number_of_frames
frame(k,:) = prblm((k-1)*frame_samples_length+1:frame_samples_length*k,:);
end
0 Comments
See Also
Categories
Find more on Multirate Signal Processing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!