# Approximate the data to a single curve

The question might be simple, but I am not able to find the answer. Hence I am asking here. I did search google but didn't get an answer.

I have a continuous stream of data coming from an API in the form of a sine curve (not exactly sine curve) as shown below.

My problem is to generate a single curve which approximates whole data. One problem I am facing is with outlier curves as similar to the middle one.

I am not finding any good leads for my problem. I just need suitable terms so that I can search answer properly for the problem.

Since you have a continuous curve in time, have you considering taking the Fourier Transform of your signal? In this way you can filter it by frequency and eliminate noise such as the lower peak curve, and then transform again to time-domain.

I am in hurry, but I think you will get the idea with this:

You have two curves, as below:

In some way you want to differentiate them, taking the fourier transform:

Now in the domain frequency you can see that you can filter some components to take away you yellow signal. Then you can just transform again your signal to time-domain.

Code to generate time domain curve:

import matplotlib.pylab as plt
import numpy as np

%matplotlib inline

x = np.linspace(-np.pi, np.pi, 20)
plt.plot(x, np.sin(x))
plt.plot(x, np.sin(x*np.pi))
plt.ylabel('sin(x)')
plt.axis('tight')
plt.show()


Code to the transformed domain:

plt.plot(x, np.abs(np.fft.fft(np.sin(x))))
plt.plot(x, np.abs(np.fft.fft(np.sin(x*np.pi))))

• Nice. I have edited my answer, please let me know if the answer is better now. Also, I think this is the path, you have some things to study right now, let me know if you have any question. – Victor Oliveira Mar 6 at 12:46
• Yes, but that is the point. The noise can be considered as another singla, then when using the frequency domain you can 'split' them. – Victor Oliveira Mar 6 at 12:57
• The sample data clearly do not follow a regular wave-like pattern: the interruption by the small "outlier" curve shifts the phase. This will cause any Fourier-like analysis to fail. – whuber Mar 6 at 13:08
• @whuber yes that's the main problem, I am facing. – Rudresha Parameshappa Mar 6 at 13:22
• DTW may offer a solution. – whuber Mar 6 at 13:28