How can I get the mean data from under the graphs?

4 vues (au cours des 30 derniers jours)
Carmen Brouwers
Carmen Brouwers le 30 Juin 2022
Commenté : Star Strider le 1 Juil 2022
Hi,
I am struggeling with getting the mean values from my data.
When plotted my data looks like this (this is only a small sample of the whole thing). I want to get the mean values of the signal from everything above 0. But not the noise you see around the 0 yline, the data is already filtered at the frequency it needs to be. I have tried it with manually looking up the range of the data which I needed and then:
data = [all_data(39:111) all_data(150:171)]
meandata = mean(data(data>0))
But this would take me years to manually look up every data point I need. I thought maybe a loop could help by telling MATLAB if the value is >0 for a period of 10 or more sample then sum/mean but I can't figure out how to do this?
Hope anyone can help me, thanks in advance!

Réponse acceptée

Star Strider
Star Strider le 30 Juin 2022
To isolate the regions around the peaks, do something like this —
x = linspace(0, 150, 500); % Create Data (Row)
y = @(v) sinc((x+v)-mean((x+v))/5); % Create Data (Rows)
v = (0:10:1500).';
x = x(:); % Convert To Column
y = sum(y(v)).'; % Convert To Column
y = y + rand(size(y))*0.2; % Add Noise
figure
plot(x, y)
grid
xlabel('X')
ylabel('Y')
title('Original Data')
[pks,plocs] = findpeaks(y, 'MinPeakProminence',1); % Desired Peak & Index
for k = 1:numel(pks)
[vys,vlocs] = findpeaks(-y, 'MinPeakProminence',0.1); % Valleys & Indices
[vlc,ixv] = mink(abs(vlocs-plocs(k)),2); % Choose Two Closest Valleys To Desired Peak
vlcs(:,k) = plocs(k) + [-1; 1].*vlc; % Calculate Indices
end
% vlcs
figure
plot(x, y)
hold on
for k = 1:size(vlcs,2)
idxr = vlcs(1,k) : vlcs(2,k); % Initial Index Range
xv = x(idxr);
yv = y(idxr);
Apos(k,:) = trapz(x(yv>=0),yv(yv>=0)); % Calculate Positive Peak Areas
Mpos(k,:) = mean(yv(yv>=0)); % Calculate Mean Value
plot(x(idxr), y(idxr), '-r') % Plot Desired Peak Region
end
hold off
grid
xlabel('X')
ylabel('Y')
title('Original Data With Selected Regions Higlighted')
PeakAreas = table(x(plocs),Apos,Mpos, 'VariableNames',{'Peak X Location','Peak Area','Peak Mean'})
PeakAreas = 11×3 table
Peak X Location Peak Area Peak Mean _______________ _________ _________ 12.625 1.7361 0.58128 25.251 1.9327 0.6023 37.575 1.7997 0.60411 50.2 1.7286 0.58274 62.826 1.6858 0.57318 75.15 1.7205 0.65916 87.475 1.7189 0.58363 100.1 1.6778 0.63264 112.42 1.753 0.53994 125.05 1.7449 0.59364 137.37 1.9823 0.45056
The regions in red in the second plot are the segments used for the ‘Apos’ area and ‘Mpos’ mean calculations.
.
  2 commentaires
Carmen Brouwers
Carmen Brouwers le 1 Juil 2022
Thank you so much! This works :)
Star Strider
Star Strider le 1 Juil 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Jonas
Jonas le 30 Juin 2022
what about a general threshold like 10 here?
mean(all_data(all_data>10))
  2 commentaires
Carmen Brouwers
Carmen Brouwers le 30 Juin 2022
yeah thought about that aswell, but I still need the points between 0-10 under the graphs if a want an accurate mean value right?
Jonas
Jonas le 30 Juin 2022
but you wrote you want to ignore the noise around the 0 value?

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by