Find mean of steps in broken signal
3 views (last 30 days)
Show older comments
Konvictus177
on 14 Aug 2023
Commented: Star Strider
on 16 Aug 2023
Hi,
I have a partially broken signal with NaNs and 5 steps as indicated below.
How can I find the mean level of each of the 5 steps?
The signal is attached.
The signal looks like the following:
Thanks.
0 Comments
Accepted Answer
Star Strider
on 14 Aug 2023
One approach —
LD = load('y.mat');
y = LD.y;
x = 0:numel(y)-1;
Lv = islocalmax(y>25, 'FlatSelection','all');
start = strfind(Lv, [0 1]);
stop = strfind(Lv, [1 0]);
for k = 1:numel(start)
ymean(k,:) = mean(y(start(k) : stop(k)), 'omitnan');
xmean(k,:) = mean(x(start(k) : stop(k)), 'omitnan');
end
Flat_Means = table(xmean, ymean, 'VariableNames',{'X Centre','Y Mean'})
figure
plot(x, y)
hold on
plot(x(Lv), y(Lv), '.r')
hold off
grid
ylim([min(ylim) 70])
text(xmean, ymean, compose('\\mu = %.2f \\rightarrow',ymean), 'Horiz','right', 'Vert','middle', 'Rotation',-80)
.
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!