I am facing the following problem in signal processing and I have run into a wall. I am trying to detect abrupt changes (step changes) in a constantly decreasing signal by convolving the signal with a step vector as described here. Well, for some data it works pretty well and I get what I want, but for other data the global minimum for convolution is not exactly in the sharpest step decrease.
I have the following signal:
Please consider the following code in python:
data = np.array([2552.383,2533,2512.785,2505.835,2498.144,2492.904,2490.824,2491.17,2489.076,2488.754,2489.492,2489.637,2484.845,2485.153,2482.884,2483.377,2482.48,2480.992,2481.135,2481.02,2480.875,2482.429,2482.586,2478.335,2478.791,2476.027,2476.181,2474.266,2472.585,2472.57,2465.272,2462.276,2463.182,2460.26,2460.086,2458.686,2459.263,2458.362,2459.85,2460.511,2460.883,2460.894,2459.156,2457.852,2456.573,2454.618,2455.423,2453.795,2454.308,2453.456,2455.077,2454.447,2454.796,2454.661,2455.67,2455.604,2455.32,2454.672,2453.575,2455.439,2454.765,2454.279,2453.462,2452.719,2453.266,2453.335,2453.922,2453.718,2451.978,2452.146,2451.312,2449.922,2451.884,2452.195,2455.087,2455.947,2453.482,2453.778,2454.079,2453.161,2451.45,2451.514,2450.818,2448.218,2449.552,2450.858,2449.074,2449.117,2447.158,2448.129,2445.928,2444.146,2444.035,2443.087,2443.816,2443.724,2442.22,2440.469,2441.847,2439.29,2440.787,2438.112,2438.1,2438.153,2436.317,2436.73,2437.417,2438.561,2437.497,2437.053,2438.275,2437.304,2437.167,2437.224,2436.918,2435.958,2437.291,2436,2436.789,2435.765,2435.677,2436.059,2433.686,2433.267,2432.362,2432.327,2432.471,2432.168,2431.224,2431.455,2431.549,2431.11,2431.63,2430.477,2429.273,2429.37,2428.899,2428.237,2428.338,2429.739,2428.185,2428.507,2427.824,2428.438,2428.392,2426.866,2425.904,2426.358,2426.402,2424.027,2424.275,2423.895,2424.784,2423.387,2421.91,2421.275,2420.155,2421.51,2420.626,2421.804,2421.177,2420.709,2420.724,2421.772,2421.316,2422.46,2421.533,2421.549,2420.343,2419.448,2417.633,2419.048,2418.364,2418.102,2420.596,2418.146,2417.698,2417.415,2417.711,2417.5,2416.718,2416.659,2416.367,2416.969,2416.927,2417.535,2416.462,2416.788,2415.222,2415.546,2413.905,2413.144,2413.458,2411.089,2411.885,2413.441,2414.224,2412.226,2412.325,2412.968,2412.432,2412.701,2412.935,2412.307,2410.914,2411.679,2409.948,2410.183,2408.195,2408.483,2408.291,2409.159,2409.039,2409.737,2409.326,2409.59,2410.319,2409.114,2411.156,2410.435,2410.301,2409.22,2408.924,2409.565,2406.818,2405.279,2403.655,2402.802,2402.376,2402.549,2400.891,2401.071,2402.39,2404.487,2403.803,2400.887,2402.126,2400.903,2402.923,2403.25,2402.192,2404.178,2403.35,2404.225,2404.663,2404.421,2402.578,2404.285,2403.047,2402.022,2403.193,2403.421,2402.553,2402.548,2401.046,2402.582,2403.312,2402.985,2401.324,2402.549,2400.778,2401.236,2400.076,2398.233,2398.563,2399.605,2397.709,2396.398,2396.097,2396.092,2395.2,2396.483,2394.492,2393.631,2394.388,2394.669,2394.888,2394.796,2396.243,2396.511,2396.741,2396.933,2395.218,2394.762,2393.999,2393.459,2393.356,2395.052,2396.326,2395.928,2395.162,2394.845,2396.828,2396.48,2396.529,2397.219,2396.717,2421.174,2444.515,2443.901,2441.366,2441.376,2442.651,2442.386,2442.768,2440.275,2439.931,2439.859,2439.151,2439.615,2438.146,2438.609,2438.881,2437.965,2440.585,2438.629,2439.035,2436.483,2435.401,2435.336,2433.901,2434.87,2435.097,2434.354,2434.57,2434.681,2436.593,2434.711,2433.714,2434.358,2431.679,2431.39,2430.755,2429.723,2428.768,2428.454,2428.217,2428.482,2431.484,2431.065,2431.438,2430.683,2431.999,2433.359,2433.301,2436.013,2437.772,2438,2438.118,2438.344,2438.46,2438.886,2438.406,2439.229,2436.564,2436.061,2435.702,2434.741,2434.914,2435.434,2434.88,2431.759,2430.931,2431.667,2429.7,2427.981,2430.134,2429.399,2428.233,2422.489,2402.696,2393.837,2394.126,2393.986,2395.045,2394.646,2393.536,2393.697,2392.883,2393.872,2395.433,2396.336,2396.617,2398.339,2399.688,2398.376,2398.741,2399.67,2400.557,2398.513,2398.399,2400.873,2400.139,2401.728,2397.714,2398.09,2400.215,2402.811,2398.542,2398.087,2398.392,2395.38,2396.412,2396.955,2400.04,2405.318,2409.042,2409.569,2412.886,2412.241,2412.621,2413.166,2410.725,2409.179,2410.933,2412.75,2413.401,2410.015,2408.624,2398.271,2391.316,2389.448,2388.595,2389.89,2390.366,2388.503,2388.108,2386.952,2386.406,2386.028,2386.645,2385.111,2386.476,2385.852,2387.16,2385.841,2386.429,2384.949,2387.114,2387.079,2387.69,2385.778,2388.918,2386.337,2386.533,2386.166,2384.974,2383.482,2382.909,2381.655,2382.113,2382.933,2383.188,2382.516,2383.13,2381.872,2381.739,2379.679,2381.023,2381.934,2380.319,2381.507,2380.813,2379.93,2380.836,2378.954,2379.423,2378.878,2379.135,2379.857,2379.479,2380.386,2380.279,2378.081,2379.569,2379.93,2379.23,2378.6,2379.726,2379.519,2380.329,2377.909,2378.958,2377.397,2376.668,2377.105,2376.443,2375.269,2374.802,2374.983,2376.848,2375.36,2376.776,2376.725,2379.745,2378.386,2375.139,2375.699,2373.927,2371.723,2369.607,2369.907,2369.429,2346.799,2325.709,2321.728,2320.692,2321.042,2321.774,2324.059,2323.781,2321.083,2319.11,2321.371,2319.58,2319.107,2317.477,2319.309,2322.519,2321.024,2317.864,2317.199,2317.607,2317.426,2317.422,2316.513,2316.034,2314.987,2314.765,2315.772,2316.912,2317.327,2315.694,2316.549,2316.63,2315.23,2313.714,2316.918,2316.539,2313.414,2311.5,2310.257,2310.327,2311.671,2313.817,2314.547,2311.626,2312.016,2311.331,2310.696,2309.197,2307.876,2307.598,2307.918,2307.76,2307.004,2309.188,2306.37,2306.023,2306.449,2307.454,2306.468,2306.374,2307.681,2307.237,2305.644,2308.332,2309.074,2309.264,2308.412,2308.555,2308.538,2307.129,2308.476,2310.625,2317.301,2321.472,2320.058,2319.19,2319.887,2321.195,2319.891,2318.771,2320.059,2320.22,2319.817,2320.968,2320.566,2320.496,2319.862,2321.163,2318.919,2318.993,2318.59,2316.315,2317.306,2316.55,2316.524,2316.365,2315.405,2314.061,2313.973,2313.116,2313.044,2311.863,2312.558,2312.833,2312.715,2311.932,2311.628,2310.462,2310.838,2310.359,2311.761,2310.896,2310.729,2309.675,2311.531,2309.635,2311.367,2311.066,2309.896,2309.336,2310.532,2309.223,2310.293,2309.175,2306.113,2306.766,2306.648,2305.325,2307.965,2305.008,2304,2303.327,2302.695,2303.22,2302.146,2301.34,2300.09,2298.591,2300.963,2302.087,2302.808,2304.36,2305.452,2304.392,2305.972,2304.572,2304.371,2304.663,2303.206,2301.989,2302.332,2301.879,2300.426,2301.484,2301.355,2300.781,2301.766,2302.315,2300.793,2300.807,2303.153,2305.228,2305.759,2305.957,2304.757,2304.947,2303.058,2301.755,2300.454,2300.531,2300.086,2299.883,2300.436,2299.762,2299.5,2300.194,2299.669,2299.987,2300.597,2299.407,2301.786,2300.641,2299.427,2299.901,2299.206,2297.835,2299.286,2297.927,2298.936,2300.247,2299.914,2297.428,2298.875,2297.884,2297.397,2297.505,2299.013,2297.141,2297.556,2261.052,2174.194,2144.265,2139.092,2140.045,2138.205,2134.398,2174.204,2216.299,2222.273,2222.617,2222.783,2223.843,2221.935,2220.548,2221.673,2223.228,2225.092,2224.927,2226.326,2225.407,2226.045,2227.624,2227.679,2226.901,2225.636,2227.776,2227.414,2225.22,2225.187,2222.502,2222.712,2220.972,2221.971,2223.256,2223.337,2223.259,2224.152,2226.812,2225.064,2227.569,2227.66,2226.796,2226.822,2221.437,2222.177,2228.442,2227.887,2227.467,2226.872,2226.062,2226.675,2227.711,2226.777,2229.137,2228.625,2228.942,2225.18,2225.194,2226.556,2226.951,2227.364,2226.544,2226.452,2226.652,2226.788,2226.624,2227.299,2227.312,2225.876,2226.913,2226.923,2227.555,2225.475,2225.676,2226.186,2223.825,2223.961,2224.543,2224.562,2223.901,2222.704,2221.478,2222.664,2221.099,2221.156,2220.819,2221.06,2220.411,2220.166,2219.264,2218.047,2217.084,2217.755,2216.895,2218.578,2218.653,2219.962,2220.763,2219.585,2220.373,2219.154,2217.424,2216.413,2215.285,2214.177,2213.374,2214.135,2214.062,2212.873,2212.276,2212.89,2214.888,2214.476,2214.753,2212.539,2213.442,2213.476,2213.195,2210.912,2211.417,2212.778,2211.662,2213.192,2211.765,2212.233,2210.723,2209.77,2210.493,2211.539,2211.378,2209.376,2211.404,2210.983,2211.716,2211.516,2212.333,2210.117,2210.977,2210.01,2208.925,2208.781,2209.8,2210.28,2209.519,2208.891,2211.042,2210.136,2208.873,2210.878,2210.428,2207.443,2209.231,2207.94,2208.077,2209.375,2208.967,2211.573,2211.641,2209.715,2209.815,2209.775,2209.072,2209.785,2208.577,2207.106,2206.234,2204.173,2204.935,2203.967,2204.276,2204.811,2205.531,2201.065,2200.959,2198.603,2197.01,2196.309,2197.763,2204.15,2213.048,2202.145,2190.921,2190.493,2187.651,2187.585,2187.082,2188.787,2209.966,2256.634,2249.265,2200.336,2182.499,2180.698,2180.983,2182.314,2182.058,2188.344,2220.965,2232.318,2198.435,2180.46,2176.925,2175.67,2175.852,2175.724,2175.767,2179.581,2204.886,2234.494,2225.77,2192.729,2172.831,2167.159,2167.059,2167.462,2167.043,2175.975,2196.307,2185.558,2168.731,2165.41,2162.823,2162.743,2165.26,2175.704,2196.712,2205.837,2193.48,2169.204,2158.048,2156.12,2155.813,2155.16,2156.485,2157.747,2170.614,2175.152,2161.817,2152.26,2150.891,2149.578,2148.913,2148.564,2149.883,2159.312,2171.508,2161.927,2146.162,2141.285,2141.18,2139.532,2139.863,2139.745,2140.28,2144.014,2157.223,2159.414,2145.452,2135.443,2133.234,2134.06,2133.793,2132.161,2134.228,2144.462,2142.849,2120.349,2107.338,2106.463,2104.815,2105.835,2106.106,2106.885,2107.772,2110.292,2124.853,2124.661,2109.459,2104.316,2101.961,2100.838,2101.244,2100.276,2102.217,2105.306,2113.594,2102.691,2094.031,2091.855,2092.596,2089.849,2090.482,2090.056,2092.267,2104.667,2105.026,2089.526,2077.575,2073.954,2072.571,2072.239,2071.703,2071.103,2074.141,2084.603,2087.429,2075.19,2067.627,2064.006,2062.646,2062.063,2064.501,2065.566,2065.507,2073.805,2083.216,2075.832,2063.879,2058.502,2057.568,2055.96,2055.781,2055.994,2055.139,2060.772,2072.926,2065.357,2052.515,2047.636,2045.611,2046.421,2045.035,2045.976,2046.052,2049.398,2063.049,2062.134,2046.519,2042.385,2042.736,2041.55,2040.654,2041.643,2041.122,2039.521,2049.49,2057.726,2043.788,2030.504,2028.995,2027.531,2026.406,2026.442,2027.506,2030.032,2052.082,2062.178,2048.68,2029.964,2025.046,2023.828,2025.617,2032.993,2034.864,2022.818,2017.647,2016.761,2018.065,2016.578,2017.025,2017.36,2017.554,2018.429,2015.83,2013.873,2014.364,2013.397,2018.459,2032.098,2031.192,2016.175,2011.535,2010.701,2008.615,2009.407,2009.663,2010.679,2011.742,2012.052,2010.624,2012.387,2014.944,2022.238,2016.038,2009.03,2008.425,2009.386,2009.361,2009.078,2008.358,2010.065,2019.315,2026.521,2012.396,2005.582,2004.146,2003.112,2003.728,2004.244,2003.217,2003.893,2004.485,2003.83,2005,2016.806,2028.391,2014.168,
2004.616,2001.217,2001.319,2001.442,1999.986,2001.704,2010.37,2023.059,2009.015,1997.36,1996.476,1995.06,1995.578,1996.319,1994.642,1996.055,1996.075,1997.632,2013.895,2016.854,2000.154,1992.929,1990.02,1990.876,1990.392,1989.75,1989.967,1991.788,2000.864,2003.943,1994.358,1988.908,1987.505,1988.105,1986.674,1987.71,1990.62,2008.825,1986.747,1948.42,1935.159,1931.714,1931.843,1932.096,1930.567,1932.587,1931.501,1927.214,1928.064,1925.905,1924.989,1925.089,1931.057,1943.771,1909.599,1880.821,1876.299,1874.568,1873.529,1873.842,1873.438,1872.317,1875.566,1897.765,1907.182,1882.02,1872.582,1872.414,1870.557,1869.32,1869.794,1869.156,1875.223,1878.858,1870.734,1868.269,1867.294,1866.763,1866.702,1865.132,1866.272,1879.197,1897.201,1885.012,1868.686,1865.642,1864.789,1864.178,1863.979,1862.987,1862.666,1865.802,1877.683,1865.709,1852.05,1848.949,1848.842,1849.229,1849.847,1849.397,1848.686,1863.782,1879.036,1864.996,1852.811,1848.528,1846.982,1848.373,1848.068,1847.059,1847.128,1859.299,1863.283,1839.746,1826.482,1825.733,1823.752,1822.764,1822.571,1823.326,1824.785,1829.858,1848.586,1848.373,1824.363,1814.12,1811.17,1812.271,1813.259,1810.671,1811.061,1810.194,1815.172,1823.712,1816.046,1811.09,1810.56,1810.789,1810.007,1809.966,1810.731,1809.603,1809.439,1821.146,1825.915,1815.628,1807.457,1808.141,1806.122,1807.408,1807.452,1807.882,1817.861,1826.219,1813.658,1806.049,1805.331,1804.158,1803.763,1802.987,1801.48,1806.395,1820.611,1820.203,1807.664,1802.058,1801.033,1800.265,1801.676,1800.582,1801.038,1806.885,1816.26,1800.203,1784.13,1778.975,1778.243,1776.464,1778.401,1778.177,1777.082,1783.436,1805.978,1810.581,1786.507,1769.541,1767.12,1766.319,1766.901,1767.5,1767.089,1767.851,1772.053,1776.499,1767.258,1763.544,1762.884,1763.859,1763.518,1761.657,1763.333,1779.668,1808.854,1804.542,1775.137,1762.568,1761.701,1761.98,1772.862,1797.598,1800.958,1776.432,1761.905,1759.726,1760.123,1759.566,1760.446,1765.356,1787.975,1813.474,1801.762,1770.404,1759.595,1757.187,1758.739,1756.696,1755.718,1758.015,1773.113,1796.177,1778.397,1757.794,1755.263,1755.062,1753.551,1753.721,1754.592,1756.42,1772.979,1776.895,1757.351,1752.411,1748.36,1748.605,1749.214,1749.515,1750.901,1750.178,1762.454,1791.888,1800.386,1772.936,1752.663,1750.326,1748.336,1746.692,1747.69,1746.155,1748.372,1761.529,1785.862,1777.946,1753.081,1746.235,1746.258,1745.321,1745.648,1746.195,1750.012,1774.695,1795.802,1777.153,1753.172,1746.541,1745.982,1744.294,1744.607,1744.68,1761.999,1784.856,1774.88,1751.648,1743.677,1744.284,1743.409,1740.854,1741.406,1741.254,1749.242,1757.775,1746.398,1740.317,1740.268,1740.361,1739.574,1740.188,1741.423,1742.307,1751.503,1763.38,1755.713,1743.137,1741.356,1739.228,1741.143,1740.862,1748.293,1765.984,1763.066,1746.237,1738.256,1735.824,1735.584,1733.884,1735.366,1734.889,1734.351,1734.978,1734.735,1734.732,1735.828,1734.427,1733.076,1730.955,1732.378,1731.412,1731.419,1733.053,1733.617,1731.968,1732.714,1733.371,1734.239,1734.685,1733.752,1735.457,1732.242,1732.606,1732.155,1730.518,1730.496,1730.894,1731.338,1731.766,1731.626,1730.765,1732.022,1726.538,1705.546,1697.4,1696.905,1696.126,1696.625,1695.262,1696.265,1694.781,1694.759,1696.112,1695.341,1692.973,1691.418,1686.073,1677.547,1673.775,1675.206,1673.12,1672.943,1673.555,1684.188,1695.552,1680.722,1668.78,1664.679,1664.438,1666.622,1666.035,1667.35,1666.214,1667.651,1680.968,1670.077,1612.164,1582.969,1578.396,1577.48,1576.356,1576.049,1577.046,1575.771,1585.355,1573.422,1545.733,1538.438,1537.926,1538.212,1537.879,1537.939,1537.769,1536.834,1536.022,1537.13,1537.641,1549.449,1568.462,1561.591,1536.461,1519.68,1517.584,1518.522,1516.533,1516.977,1517.251,1515.656,1514.774,1508.972,1491.539,1485.749,1468.766,1448.417,1437.295,1434.225,1434.609,1433.978,1432.402,1435.096,1440.141,1452.577,1456.449,1438.138,1424.724,1290.245,578.368,147.853,102.207,94.503,94.332,92.56,89.889,87.344,86.208,86.485,86.241,86.336,85.359,85.277,86.047,82.986,79.776,78.325,78.613,78.355,77.566,76.68,77.242,74.702,72.271,69.11,70.621,70.843,70.657,69.569,68.89,69.17,67.086,66.427,66.951,67.283,67.067,67.135,66.297,67.037,64.458,64.811,65.097,63.994,64.312,64.22,64.256,65.212,64.068,63.614,62.51,62.257,63.428,62.489,63.473,62.775,63.821,62.056,61.602,61.059,61.874,62.519,60.908,61.121,61.895,61.487,59.656,59.364,59.885,59.448,59.485,58.739,58.169,58.549,56.357,56.912,56.45,57.402,57.661,55.709,56.558,56.871,54.479,55.483,54.887,55.126,55.076,55.396,55.444,55.78,55.953,54.025,55.703,52.934,52.592,51.508,52.493,51.376,52.179,52.311,52.46,52.2,51.53,51.198,51.327,51.296,50.591,49.896,50.513,50.561,47.804,41.299,40.392,38.662,39.943,39.913,40,39.676,38.59,38.982,38.912,39.219,38.495,38.921,39.429,39.015,39.45,38.891,38.311,37.902,38.403,39.023,38.532,38.822,39.781,38.865,37.697,38.438,37.041,38.106,37.613,37.509,38.994,38.738,36.437,37.515,37.873,38.12,37.278,37.884,37.278,38.108,37.955,37.992,36.706,37.342,37.349,37.302,38.513,37.499,42.065,35.111,5.133])
data -= np.average(data)
steps = np.hstack((np.ones(len(data)), -1*np.ones(len(data))))
convolution = np.convolve(data, steps, mode='valid')
globalMinIndex = np.argmin(convolution)
plt.figure()
plt.plot(data)
plt.plot(convolution/10)
The (incorrect) result:
As you can see, the global minimum is reached at a place, where the signal after standarization revolves around zero. But I would rather expect it to be at the sharpest step in the signal.
Please consider, the following data, where this algorithm works exactly as expected:
The (correct) result:
My questions are:
Do you know the name of this method for step detection? I have been searching but couldn't find anything specific/formal regarding this method.
Why does it fail for the first data set? Is there a better way to standardize this data or use a different convolution filter so that it yields the correct result consistently?
I have been trying to find the reason why it fails but have run out of ideas. Thank you.