Find all the peaks higher than this threshold and save the corresponding range in a variable.

I have two plots on the same graph. The blue one is the MaxPerRangeBin and the red one is CfarThold.
I want to locate the peaks in blue which are higher than the red plot.
I have used islocalmax to locate all the peaks in MaxPerRangeBin , which is the logic I have to apply. Now, I have to just find out all the peaks which are just greater than red plot i.e. CfarThold.
I am sharing the snippet, along with the graph.
TF = islocalmax(data(i).MaxPerRangeBin,2);
aa(num_values,:) = data(i).MaxPerRangeBin(num_values,:);
peakvalue_MPRB = aa(TF(num_values,:));

3 Comments

Can you please share the data and code you used to create the graph?
files = dir('*.mat');
data = struct();
for i = 1:length(files)
result = load([files(i).folder,'\', files(i).name]);
for num_values= 1:length(result.data)
data(i).scanindex(num_values,:) =( result.data(num_values).ScanIndex);
data(i).MaxPerRangeBin(num_values,:) = result.data(num_values).MaxPerRangeBin;
data(i).CfarThold(num_values,:) = result.data(num_values).CfarThold;
% extracting peaks
TF = islocalmax(data(i).MaxPerRangeBin,2);
aa(num_values,:) = data(i).MaxPerRangeBin(num_values,:);
peakvalue_MPRB = aa(TF(num_values,:));
end
plot(data(i).MaxPerRangeBin(1,:)); % Blue plot
hold on;
plot(data(i).CfarThold(1,:)); % Red plot
end
Again, can you attach the data? You forgot to attach any .mat files with the paperclip icon.

Sign in to comment.

 Accepted Answer

Possibly:
idxv = 1:numel(data(i).MaxPerRangeBin(1,:)); % Index Vector
Lv = (data(i).MaxPerRangeBin(1,:)) >= (data(i).CfarThold(1,:)); % Logical Vector
TF = islocalmax(data(i).MaxPerRangeBin(1,Lv)); % Peaks Logical Vector
TFidx = find(TF); % Numeric Indices
PeakIndices{i} = TFidx; % Save Peak Index Values
.

4 Comments

This is what I have done so far. I have the peaks in all_peaks vector as one column but I want it to be 2 dimensional matrix as TF or Thold.
num_values is 399 (means 399 rows).
We can skip saving the arrays in data structure for now :)
[row,col] = find(MaxPerRangeBin > CfarThold);
Thold = nan(num_values,125);
for ii=1:length(row)
Thold(row(ii),col(ii))= MaxPerRangeBin(row(ii),col(ii));
end
TF = islocalmax(Thold,2);
all_peaks= Thold(TF); !!
sorted_peaks= sort(all_peaks,'descend');
Since there may not be the same number of peaks in each field, I would use the code I posted (unless there is a reason it does not work and would need to be changed). Saving the peaks to a cell array is preferable.
If it turns out that there are the same number of peaks in each field, use the cell2mat function on ‘PeakIndices’ to convert it into a matrix. Change the ‘PeakIndices’ assignment to:
PeakIndices{i,:} = TFidx; % Save Peak Index Values
to make that possible.
.
Thank you Star Strider for the help. I was able to save the values in a structure.
all_peaks = uu( TF(num_values,:));
sorted_peaks = sort(all_peaks,'descend');
data(num_values).result = sorted_peaks; % saving to struct
c = ismember(Thold, sorted_peaks); % extracting x-values
[ data(num_values).scan_value, data(num_values).bins] = find(c);

Sign in to comment.

More Answers (0)

Categories

Find more on Images 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!