How to find the local MINs and local MAXs of graphs with "noise"?

I'm currently working on a project and I'm running into two issues that I can't seem to solve. They revolve around finding the local MINs and local MAXs of a data set with noise in c++. I have two vectors, one of them holds the data points for the x-axis and the other hold the y-axis's data points. I want to try to eliminate/limit the noise in my graphs and was told by my professor that there is a way to go about this in c++. However, I'm finding it hard to find ways to go about eliminating the noise from my graphs, and was hoping that someone here on the forms could point me in the right direction. My professor also told me that my way of finding local MINs and local MAXs was unreliable and could easily return incorrect data and that I should start over. If anyone could also point me in the right direction for finding the local MINS and local MAXs of graphs that are truly random (Can have up 6 local maxs and three local mins) that would be much appreciated. Thank you in advance!
Two things:

1. Please show your incorrect solution.

2. Please explain "noise" and "local". An example would help.

3. Why the asymmetry? If a curve zigzags up and down, how can it go up twice as often as down?

4. Why two vectors rather than one vector of (x,y) pairs?
1. I don't have the old solution anymore, but I can give an example of how I went about getting the Mins and Maxs.

1
2
3
4
5
6
7
8
9
//Can easily mess/add a peak depending on the graph
    for(int i=0;i<graphY.size();++i)
    {
        double dataY=graphY[i];
        if(dataY>10 && dataY>graphY[i+5] && dataY>graphY[i-5])
        {
            //add x and y to new vector
        }
    }


2. What I mean by noise is that the graph isn't smooth at all. I want to try to get the graph to be smooth so that I can get a more accurate number for my y-axis values. In the data’s current state, it has a bunch of jagged lines that are giving me false values for the y-axis and I what to eliminate this or limit the noise. As for local Mins and Maxs, I just referring to the peaks and dips in the graph. If you want an example, go to this website https://www.astro.uni-bonn.de/hisurvey/profile/index.php (Just a database of objects in radio astronomy) and enter 7 for L and 3 for B. It will give you a graph that represents my data without any noise. In this graph, there are 3 peaks and 2 dips that I need to find.

3. The data is from radio astronomy, so it can get pretty odd looking with signals overlapping with one another and all the noise in space causes the graphs to look wired with low powered radio telescopes.

4. No real reason just thought it would be easy to just have two vectors instead of one.
Could you eliminate some noise by smoothing?
1
2
3
4
std::vector<double> smoothY( graphY.size(), 0 );
for ( size_t pos = 2; pos < graphY.size(); ++pos ) {
  smoothY[ pos - 1 ] = (graphY[ pos - 2 ] + graphY[ pos - 1 ] + graphY[ pos ]) / 3.0;
}

That one calculates average for three consecutive points, assuming that the x are evenly spaced. You can use longer fragments. You can optimize the code.


When you find an extreme value at smoothY[x], you can retrieve the real observation from graphY[x].
That will definitely lessen the effects of the noise, and give me a much smooth graph. Thanks!

Do you have any ideas about how to find the peaks and dips in the graph? That's the major part of my project and I can't find a way to guarantee that my program will return the right number of dips and peaks with the right (x,y) coordinates.
Topic archived. No new replies allowed.