Less noisy graph and extra humps in python
Question: Here is the data file:

<https://jsfiddle.net/83ygso6u/>

Sorry for posting it in jsfiddle... didn't know where else to host it.

Anyway the second column should be ignored.

Here is the code and graph:

    
    
    import pylab as plb
    import math
    from pylab import *
    import matplotlib.pyplot as plt
    
    data = plb.loadtxt('title_of_datafile.txt')  
    x = data[:,0]*1000
    y= data[:,2]
    
    plt.figure()
    
    plt.title('Some_Title',fontsize=35, y=1.05)
    plt.xlabel('Frequency (Hz)',fontsize=30)
    plt.ylabel('dBu',fontsize=30)
    
    plt.plot(x,y,'k-', label='Data')
    
    plt.xticks(fontsize = 25, y=-0.008)
    plt.yticks(fontsize = 25, x=-0.008)
    plt.show()
    

[![enter image description
here](http://i.stack.imgur.com/coia2.png)](http://i.stack.imgur.com/coia2.png)

So you can see this signal is quite noisy, but it does have two distinct peaks
at around 4500 Hz and 5500 Hz.

I have been searching around the net and havn't really come across anything
that will help me.

How can I extract these peaks and/or clean up the signal in python?


Answer: Well I managed to find a solution. Here is the script with the resulting plot.

Script:

    
    
    import pylab as plb
    import math
    from pylab import *
    import numpy as np
    import scipy as sp
    import matplotlib.pyplot as plt
    from scipy import signal
    import peakutils
    from peakutils.plot import plot as pplot
    
    data = plb.loadtxt('data_file_name')  
    x = data[:,0]*1000
    y= data[:,2]
    
    y1 = sp.signal.medfilt(y,431) # remove noise to the signal
    
    indexes = peakutils.indexes(y1, thres=0.00005, min_dist=1400) #determine peaks
    x_new = x[indexes]
    
    plt.figure()
    plt.subplot(1,2,1)
    
    plt.title('some_title_1',fontsize=35, y=1.05)
    plt.xlabel('Frequency (Hz)',fontsize=30)
    plt.ylabel('Signal (dBu)',fontsize=30)
    plt.plot(x,y,'r-', label='Raw Data')
    plt.plot(x,y1,'b-', label='Cleaned up Signal')
    plt.plot(x_new[3:6],y1[indexes][3:6],'k^',markersize=10, label='Peaks')
    plt.xticks(fontsize = 25, y=-0.008)
    plt.yticks(fontsize = 25, x=-0.008)
    plt.legend(loc=1,prop={'size':30})
    
    plt.subplot(1,2,2)
    for i,j in zip(x_new[3:6], y1[indexes][3:6]):
        plt.annotate(str(i)+ " Hz",xy=(i,j+0.5),fontsize=15)
    plt.title('some_title_2',fontsize=35, y=1.05)
    plt.xlabel('Frequency (Hz)',fontsize=30)
    plt.ylabel('Signal (dBu)',fontsize=30)
    plt.plot(x,y,'r-', label='Data')
    plt.plot(x,y1,'b-')
    plt.plot(x_new[3:6],y1[indexes][3:6],'k^',markersize=10)
    plt.xticks(fontsize = 25, y=-0.008)
    plt.yticks(fontsize = 25, x=-0.008)
    plt.xlim([3000, 6000])
    plt.ylim([-90, -75])
    plt.subplots_adjust(hspace = 0.6)
    plt.show()
    

[![enter image description
here](http://i.stack.imgur.com/iEILd.png)](http://i.stack.imgur.com/iEILd.png)

