How can I tak average of certain intervals on my graph?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi Guys,
Could you help me write an algorithm that would capture mean values of particular intervals that I'm interested in? Intervals are marked: http://imageshack.us/f/694/mchg.png/
I have a flag that captures the interval of the picture itself from a larger graph and then, I need to capture those smaller intervals.
Thanks a lot, Nurlan
2 commentaires
the cyclist
le 12 Sep 2013
Do you know the exact X values that define the intervals, or do you need to infer those X values from properties of the Y data?
Réponse acceptée
Image Analyst
le 12 Sep 2013
If you know the x values (indexes), wouldn't it just be
meanInsideInterval = mean(y(index1:index2));
6 commentaires
Image Analyst
le 13 Sep 2013
Modifié(e) : Image Analyst
le 13 Sep 2013
The Savitzky-Golay filter is a very simple concept. It's a sliding filter where you slide a window along your signal, say a window of 11 elements or some other odd number. Then, for the center element, you set the output matrix at that element equal to what you'd get if you fit a polynomial to the data in the window. For example, let's say that the window slides along and is now over elements 101 to 111. You take the signal at elements 101 to 111, signal(101:111), and fit those to a quadratic (for example). The center element is 106, so you set element 106 of the output to what you'd get from the estimated, fitted value rather than the actual input value. This has the effect of smoothing the data. It's just like a regular sliding mean filter except that instead of fitting data to a flat line (like the mean is), you're fitting it to a cubic, quadratic, quartic, or whatever. The higher the order you allow, the more it follows the original data and the lower the order, the more smoothed it gets. Does that make sense? sgolay() is in the Signal Processing Toolbox.
However, if you have the Image Processing Toolbox, I think you'd be better off using the sliding standard deviation filter, stdfilt(). That slides along and gives the standard deviation within the window. So high oscillations and steep discontinuities will give a high output while flatter sections of the signal will give a lower output. So then you can threshold that to find areas of high variation or low variation, like this
sdSignal = stdfilt(signal, [1,11]);
stableRegions = sdSignal < 6.123; % Or whatever value defines "stable"
Now, if you want the mean (an order zero Savitky-Golay filter), then you can simply use conv():
smoothedSignal = conv(signal, ones(1,11)/11, 'same');
Now you have the smoothed signal (smooth everywhere), and regions identified where the signal is, or is not, stable. I can do anything with those regions. I can replace stable, or unstable regions with the smoothed signal.
out = signal
out(stableRegions) = smoothedSignal(stableRegions);
% or
out(~stableRegions) = smoothedSignal(stableRegions);
I can zero out either the stable or unstable regions.
out = signal
out(stableRegions) = 0;
% or
out(~stableRegions) = 0;
I can crop out either the stable or unstable regions.
out = signal
out(stableRegions) = [];
% or
out(~stableRegions) = [];
But you haven't made it clear what you want to do once you have the stable or unstable regions identified. Tell me what you want to do and I'll help you.
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!