segmentation of a signal

8 views (last 30 days)
Rida Alfonso
Rida Alfonso on 9 Jun 2020
Answered: Rida Alfonso on 9 Jun 2020
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
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()

Sign in to comment.

Accepted Answer

Ameer Hamza
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

More Answers (2)

KSSV
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

Rida Alfonso
Rida Alfonso on 9 Jun 2020
clc
clear
fs=2048;
windowSize = fs*0.3; % Number of samples required for 200ms window
stepSize = fs*0.05; % Number of samples required for 50ms overlap
Nwind = floor((size(prblm,1) - windowSize) / stepSize + 1);
for i = 1:Nwind
startsample = 1+(i-1)*stepSize; % Start sample of window
endsample = (i-1)*stepSize + windowSize; %End sample of window
iterations = prblm(startsample:endsample, :) % but i get errors in this one
%store values of each iterations
end
Thank you very much for all your replies, i really appreciate your help. The earlier part was disjoint segmentation and you people solved that, but my actual problem is to perform overlapping segmentation , like the next window should start from 0.05 seconds overlap of 1st window and then go on... i was able to create a loop for this but i am again stuck in saving the iterations as i would need them in the later step of feature extraction.

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!