Range of values for Flat region of signal near Local maxima
2 views (last 30 days)
Show older comments
I am still learning MATLAB and signal processing so not good at it. I have tried to be as much mature and upto the mark as possible but if there is something left so accept my apology for that.
*• I need to find range of only those Flat areas where I have local maximas like attached in the figure.
• I need to find the range of values where blue signal is flat near local maxims’. I have also make rectangular boxes around flat parts containing local maxima’s to get a clear view what I am expecting.*
Please have a look at the attached figure below.
I have tried to make a signal that replicates exactly my original data but unfortunately remained unable to come up with some good example so I have attached original data under link. I have applied one method on test example but unfortunately it’s not working with my original data.
Link for original Data Values:
Detecting the flat regions in the blue signal
% create a random signal
rng('default');
x = cumsum(rand(200, 1)-0.5);
% construct measured signal
x_measured = x;
x_measured(20:100) = 3.5; % first measured flat region
x_measured(105:135) = 2; % second measured flat region
The flat blue region are characterised by the fact that they have exactly the same value during the whole flat region. Therefore, one can detect the flat region by checking when two consecutive values are the same:
diff(measured_Signal_data)==0
The only problem is that the small flat regions are undesired, but we can remove them using an erosion and dilation step:
SE = strel('cube',20); % remove all flat regions smaller than 20 samples
flat = imdilate(imerode(diff(measured_Signal_data)==0, SE), SE)
The start and end indexes of the flat regions can be calculated by determining the rising/falling edges of flat:
% calculate the start and end of each flat region (rising and falling edge of flat)
startFlat = find(flat(1:end-1) == 0 & flat(2:end) == 1) + 1;
endFlat = find(flat(1:end-1) == 1 & flat(2:end) == 0) + 1;
The result can be visualised as follows:
figure
hold on
plot(x_measured);
plot(flat);
Code to access plausible values of original data from link :
load originalflatenninroughnew t original_signal_data measured_Signal_data
[p l] = findpeaks(measured_Signal_data);
[pn ln] = findpeaks(-measured_Signal_data);
figure(1)
hold on
plot(t,original_signal_data,'g')
plot(t,measured_Signal_data,'b')
plot(t(l),p,'ko','MarkerFaceColor','r');
plot(t(ln),-pn,'ko','MarkerFaceColor','r');
legend ('originalsignal', 'measureddatasignal')
hold off
0 Comments
Answers (0)
See Also
Categories
Find more on Signal Generation and Preprocessing 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!