title: Finding repeated pattern in a series of numbers in C++
body: <p>I am trying to implement an auto grid detection system for an electrocardiogram, ecg, paper see the figure below.The idea behind is to add the pixel values(only considered the red channel) by going through pixel by pixel of the ecg image as shown in the code below.</p>
  <pre><code>QImage image(&quot;C:/Users/.../Desktop/ECGProject/electrocardiogram.jpg&quot;);
  std::vector&lt;int&gt; pixelValues;
  for (int y = 0; y &lt; img.height(); y++)
  {
     int rowSumR = 0, rowSumG = 0, rowSumB = 0;
     for (int x = 0; x &lt; img.width(); x++)
     {
         QRgb rgb = img.pixel(x, y);
         rowSumR += qRed(rgb);
     }
     rowSumR /= img.width();
     const int &amp;value = rowSumR/4;
     pixelValues.push_back(value)
  }
  </code></pre>
  <p>The vector <code>pixelValues</code> contains summed values which has repeated pattern in a y direction. The goal is to detect those repeated pattern (for instance the line drawn in black color on in the ecg image is the interest or what I am looking to identify in a y direction). I also draw the summed pixel value in y direction using matlab(see the figure below) and the red circles are the pattern I am interested in. Any suggestion/algorithm to find these repeated pattern would be appreciated.
  [![Ecg paper][1]][1] [![enter image description here][2]][2]</p>