How can I tak average of certain intervals on my graph?

5 次查看(过去 30 天)
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 个评论
the cyclist
the cyclist 2013-9-12
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?
Nurlan Mukanov
Nurlan Mukanov 2013-9-12
No. That's the problem. I need to use the Y data in order to capture consistent data.

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-9-12
If you know the x values (indexes), wouldn't it just be
meanInsideInterval = mean(y(index1:index2));
  6 个评论
Nurlan Mukanov
Nurlan Mukanov 2013-9-13
Location of the thick black lines based on the consistency of data. If you look for the first interval stable data starts at the black line and for the second, stable data starts after those large oscillations.
A for the Savitzky-Golay filter I don't what it is and how can I use it?
Image Analyst
Image Analyst 2013-9-13
编辑:Image Analyst 2013-9-13
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by