Help Segmenting signal processing

4 visualizaciones (últimos 30 días)
Nina Perf
Nina Perf el 15 de Mzo. de 2022
Respondida: Image Analyst el 17 de Abr. de 2022
Hi,
I have data. I have segmented the signal in windows and calculated rms. Can you please help in finding multiple minimum values for this signal?
[v, i] = min(rms);
Thank you!

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 15 de Mzo. de 2022
hello
see my little demo below. I assumed that you would split the rms data in 3 groups corresponding to ranges
  • 0 to 33% of max rms
  • 33 to 66% of max rms
  • above 66% of max rms
the 3 groups are the colored dots
code :
clearvars
% dummy data
n=300;
x=linspace(0,2*pi,n);
data = 0.25*ones(size(x));
data = max(data,-cos(x));
buffer = 10; % nb of samples in one buffer (buffer size)
overlap = 5; % overlap expressed in samples
%%%% main loop %%%%
m = length(data);
shift = buffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,m);
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
rms_data(ci) = my_rms(data(start_index:stop_index)); %
end
x_rms = x(time_index);
figure(1),
plot(x,data,x_rms,rms_data,'r*');
%select index if they belong to ranges : 0 - 33% of max / 33 - 66% of max / above 66% of max
ind1 = find(rms_data<=max(rms_data)/3); % range : 0 - 33% of max
ind2 = find(rms_data>max(rms_data)/3 & rms_data<=max(rms_data)*2/3); % range : 33 - 66% of max
ind3 = find(rms_data>max(rms_data)*2/3); % range : above 66% of max
figure(1),
plot(x,data,'k',x_rms(ind1),rms_data(ind1),'g*',x_rms(ind2),rms_data(ind2),'b*',x_rms(ind3),rms_data(ind3),'r*');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_rms = my_rms(x)
x_rms = sqrt(mean(x.^2));
end

Más respuestas (2)

Mathieu NOE
Mathieu NOE el 17 de Mzo. de 2022
hello Nina
I was about to reply on your other post when it disappeared : did you delete it ?
For your info, this was the demo code I have been preparing for you , maybe still of interest :
clearvars
% dummy data
n=1000;
x=linspace(0,2*pi*3,n);
data = 0.25*ones(size(x));
data = max(data,-cos(x).*(1+x/10));
data(300:303) = 2; % add a spike (for fun)
%% parameters
min_contiguous_samples = 10; % consider "red" segments only if they are at least this length (and contiguous)
% running rms (buffered) parameters :
buffer = 100; % nb of samples in one buffer (buffer size)
overlap = buffer-1; % overlap expressed in samples
%% main loop %%%%
m = length(data);
shift = buffer-overlap; % nb of samples between 2 contiguous buffers
for ci=1:fix((m-buffer)/shift +1)
start_index = 1+(ci-1)*shift;
stop_index = min(start_index+ buffer-1,m);
time_index(ci) = round((start_index+stop_index)/2); % time index expressed as sample unit (dt = 1 in this simulation)
rms_data(ci) = my_rms(data(start_index:stop_index)); %
end
x_rms = x(time_index);
%select index if they belong to ranges : 0 - 33% of max / 33 - 66% of max / above 66% of max
ind1 = (rms_data<=max(rms_data)/2); % range : 0 - 50% of max
% ind2 = find(rms_data>max(rms_data)/2 & rms_data<=max(rms_data)*2/3); % range : 33 - 66% of max
ind2 = (rms_data>max(rms_data)/2); % range : 50 - 100% of max (why limit the upper value ??)
% now define start en end point of "red" segments
[begin2,ends2] = find_start_end_group(ind2);
length_ind2 = ends2 - begin2;
ind22= length_ind2>min_contiguous_samples; % check if their length is valid (above min_contiguous_samples value)
begin2 = begin2(ind22); % selected points
ends2 = ends2(ind22); % selected points
% define for plot the red / green rms data
x1 = x_rms(ind1);
rms_data1 = rms_data(ind1);
x2 = x_rms(ind2);
rms_data2 = rms_data(ind2);
% define the begin / ending x, y values of raw data
x2_begin = x_rms(begin2);
data_begin = interp1(x,data,x2_begin);
x2_ends = x_rms(ends2);
data_ends = interp1(x,data,x2_ends);
figure(1),
plot(x,data,'k',x1,rms_data1,'g.',x2,rms_data2,'r.',x2_begin,data_begin,'dc',x2_ends,data_ends,'dm','MarkerSize',12);
legend('signal','rms below 50%','rms above 50%','begin points','end points');
% store each "red" segment separately (in cell array)
figure(2), hold on
for ci = 1:length(begin2)
ind = (x>=x2_begin(ci) & x<=x2_ends(ci))
xx = x(ind);
yy = data(ind);
data_store{ci} = [xx(:) yy(:)]; % 2 columns : time / data
plot(xx,yy);
end
hold off
%%%% end of main file %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [begin,ends] = find_start_end_group(ind)
% This locates the beginning /ending points of data groups
D = diff([0,ind,0]);
begin = find(D == 1);
ends = find(D == -1) - 1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function x_rms = my_rms(x)
x_rms = sqrt(mean(x.^2));
end

Image Analyst
Image Analyst el 17 de Abr. de 2022
In case you delete again, here is the current version of the question:
---------------------------------------------------------------------------------------------------
Hi,
I have data. I have segmented the signal in windows and calculated rms. Can you please help in finding multiple minimum values for this signal?
[v, i] = min(rms);
Thank you!
---------------------------------------------------------------------------------------------------
So to do that, you can do
[sortedRMS, indexes] = sort(rms, 'ascend');
the indexes will tell you the indexes for the RMS with the smallest rms value first, at indexes(1), and the largest rms value last, at indexes(end).

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by