[SciPy-User] Low pass filter

Kaan AKŞİT kunguz at gmail.com
Fri Sep 18 03:27:26 EDT 2009


Dear Ivo,

Thank you very much for examples and debugging. I had this problem with
tuning of Wn. My sample rate is pretty high f_s = 5000000000. When I
configure it as below:

f_s = 5000000000
[b,a]=butter(4,5./(f_s/2))

It warns me about bad coefficient:

/usr/lib/python2.6/site-packages/scipy/signal/filter_design.py:221:
BadCoefficients: Badly conditionned filter coefficients (numerator): the
results may be meaningless
  "results may be meaningless", BadCoefficients)
/usr/lib/python2.6/site-packages/scipy/signal/filter_design.py:221:
BadCoefficients: Badly conditionned filter coefficients (numerator): the
results may be meaningless
  "results may be meaningless", BadCoefficients)

Best regards,
Kaan


17 Eylül 2009 17:33 tarihinde Ivo Maljevic <ivo.maljevic at gmail.com> yazdı:

> Do you know what is the sampling rate of your data? Your Wn = 5/(f_s/2),
> where f_s is the data sampling rate.
> Also, I meant "I cannot comment on the frequency *content* of the signal
> you are trying to LPF".
>
> Hope this helps.
>
> Ivo
>
>
> 2009/9/17 Ivo Maljevic <ivo.maljevic at gmail.com>
>
>> Kaan,
>> If you have two consecutive plot calls, you need to call figure in
>> between, or you will plot over the first one. See the modified code below
>> (blue). Also, put the time on the proper place (red).
>> I cannot comment on the frequency comment of the signal you are trying to
>> LPF.
>>
>> Notes:
>>
>> 1. Your butterworth filter is too short: N=2?
>> 2. Your Wn should be normalized and < 1, I think.
>>
>> Ivo
>>
>>
>> #!/usr/bin/python
>> # -*- coding: utf-8 -*-
>> import time, array, datetime
>> import matplotlib
>> import matplotlib.pyplot as plt
>> from scipy import *
>> from scipy.signal import butter, lfilter
>>
>> input = 0
>> timing = []
>> voltage  = []
>> values = []
>>
>> input = 0
>> infile = open('measurements/' + "data.csv", "r")
>> for line in infile.readlines():
>>     values = line.split(',')
>>     voltage.insert(input,float(
>>
>>>  values[0]))
>>>     timing.insert(input,float(values[1]))
>>>     input = input + 1
>>> plt.xlabel('Time steps')
>>> plt.ylabel('Voltage')
>>> plt.title('Measurments from Oscilloscope')
>>> plt.grid(True)
>>> plt.plot(timing, voltage)
>>>
>>
>>    plt.figure()
>>
>> [b,a]=butter(2,5)
>> voltagelowp=lfilter(b,a,
>>
>>> voltage)
>>> plt.plot(timing, voltagelowp)
>>> plt.show()
>>> plt.close()
>>>
>>
>>
>>
>> 2009/9/17 Kaan AKŞİT <kunguz at gmail.com>
>>
>>> Thanks Ivo, The problem is after filtering I got the same signal. I
>>> wanted to clear the frequencies higher then 5 Hz. My code is similar to
>>> yours but the output doesn't seem logical:
>>>
>>> #!/usr/bin/python
>>> # -*- coding: utf-8 -*-
>>> import time, array, datetime
>>> import matplotlib
>>> import matplotlib.pyplot as plt
>>> from scipy import *
>>> from scipy.signal import butter, lfilter
>>>
>>> input = 0
>>> timing = []
>>> voltage  = []
>>> values = []
>>>
>>> input = 0
>>> infile = open('measurements/' + "data.csv", "r")
>>> for line in infile.readlines():
>>>     values = line.split(',')
>>>     voltage.insert(input,float(values[0]))
>>>     timing.insert(input,float(values[1]))
>>>     input = input + 1
>>> plt.xlabel('Time steps')
>>> plt.ylabel('Voltage')
>>> plt.title('Measurments from Oscilloscope')
>>> plt.grid(True)
>>> plt.plot(timing, voltage)
>>>
>>
>>    plt.figure()
>>
>>
>>>  [b,a]=butter(2,5)
>>> voltagelowp=lfilter(b,a,voltage)
>>> plt.plot(timing, voltagelowp)
>>>
>>> plt.show()
>>> plt.close()
>>>
>>> 2009/9/17 Ivo Maljevic <ivo.maljevic at gmail.com>
>>>
>>> Does the following:
>>>>
>>>> plt.plot(timing, voltage)
>>>> plt.show()
>>>>
>>>> work before filtering? (Suggestion, you may want to put time on x-axis,
>>>> see the line above)
>>>>
>>>> I just wrote a small test program, and it works:
>>>>
>>>>
>>>> #!/usr/bin/python
>>>>
>>>> # import
>>>> import pylab as plt
>>>> from scipy import *
>>>> from scipy.signal import butter, lfilter
>>>>
>>>> t=linspace(0,1,100)
>>>> v=sin(2*pi*t)
>>>>
>>>> (b,a)=butter(2,5,btype='low')
>>>> v=lfilter(b,a,v)
>>>> plt.plot(t,v)
>>>> plt.show()
>>>>
>>>>
>>>> 2009/9/17 Kaan AKŞİT <kunguz at gmail.com>
>>>>
>>>>>  Hi all,
>>>>>
>>>>> This is my first time that I use Scipy. I have two arrays both of them
>>>>> one dimensional. One of them is filled with voltage values and one of them
>>>>> is filled with time values. I want to apply low pass filter to clear the
>>>>> noise from the data. Can you please help me? I already wrote something but
>>>>> it is not working:
>>>>>
>>>>> (b,a)=butter(2,5,btype='low')
>>>>> voltage=lfilter(b,a,voltage)
>>>>> plt.plot(voltage,timing)
>>>>>
>>>>> Best regards,
>>>>> Kaan
>>>>>
>>>>> _______________________________________________
>>>>> SciPy-User mailing list
>>>>> SciPy-User at scipy.org
>>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>>>
>>>>>
>>>>
>>>> _______________________________________________
>>>> SciPy-User mailing list
>>>> SciPy-User at scipy.org
>>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>>
>>>>
>>>
>>> _______________________________________________
>>> SciPy-User mailing list
>>> SciPy-User at scipy.org
>>> http://mail.scipy.org/mailman/listinfo/scipy-user
>>>
>>>
>>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20090918/dc9e97f3/attachment.html>


More information about the SciPy-User mailing list