0
$\begingroup$

I have a problem with applying Butterworth High Pass Filter to my data. I would like to print filter for Bx and By matrix. As you can see I have both positive and negative values,

how to apply math.fabs() to Bx and By to get only positive values?

For my high pass filter I have those requirements:

Fc = 2 Hz

I would like to cut off values below 100 pT.

A part of my current code is:

plt.ylabel('Pico Tesle [pT]')
plt.xlabel('Time [ms]')
plt.grid()
plt.plot(time[51:-14], Bx[51:-14], label='Canal 1', color='r', linewidth=0.1, linestyle="-")
plt.plot(time2[1:-14], By[1:-14], label='Canal 3', color='b', linewidth=0.1, linestyle="-")
plt.legend(loc='upper right', frameon=False, )

And a chart:

enter image description here

UPDATE: I have used this function to generate absolute values for Bx and By matrix.

plt.subplot(413)
np.absolute(fft1)
plt.plot(time[51:-14], np.absolute(fft1), color='r', linewidth=0.1, linestyle='-')
plt.grid()

plt.subplot(414)
np.absolute(fft2)
plt.plot(time2[1:-14], np.absolute(fft2), color='b', linewidth=0.1, linestyle='-')
plt.grid()

What I received thanks to that is that all my measurements (here are atmospheric discharges) are only in positive values (pT - picoTesla). First plot shows Canal 1, second plot shows Canal 3, and the third plot shows both Canals (Channels) combined.

enter image description here

No, I need (I guess) use High Pass Filter to cut off all measurements below 100 pT. Any ideas?

$\endgroup$
  • 1
    $\begingroup$ I'm confused. A high pass filter has nothing to do with cutting off low values. On the contrary, all the filter types you normally encounter are linear systems, and cutting something off is pretty much the opposite of linear behavior. So, I think you are confusing things. $\endgroup$ – Marcus Müller Dec 31 '17 at 9:32
  • $\begingroup$ You must be right, I am new to signal processing so I probably wrote something incorrect. So maybe you have idea how to cut off all the data below 100 pT, and leave only those above that value? $\endgroup$ – Hiddenguy Dec 31 '17 at 9:39
2
$\begingroup$

If you just want to do thresholding, then you don't have to use any filter. Just throw away all those samples whose values are below your threshold (in this case, $100 \ \mathrm{pT}$).

In MATLAB, you could do something like this:

data(data < 100) = [];

If you want to keep the array size, then you might consider replacing those values with NaN or 0 instead of [].

| improve this answer | |
$\endgroup$
  • $\begingroup$ I guest it will work, do you know how this operate in python? $\endgroup$ – Hiddenguy Dec 31 '17 at 18:02
  • $\begingroup$ It would be pretty similar. You can do data[(data < 100)] = 0 to replace those values by 0 or data = data[(data >= 100)] to delete them. $\endgroup$ – Tendero Dec 31 '17 at 18:15
  • $\begingroup$ Thanks for your help, I used this formula and it is working. np.clip(np.absolute(fft1),100,1000) $\endgroup$ – Hiddenguy Jan 1 '18 at 12:44
0
$\begingroup$

This code answers my question completely.

fig2 = plt.figure(2)
plt.title('Butterworth High Pass Filter')
Sampling = float(266336)/300
HalfSampling = float(Sampling)/2
Wn = float(1)/HalfSampling
b, a = signal.butter(3, Wn, 'high')
BxHPF = signal.filtfilt(b, a, Bxfft)
ByHPF = signal.filtfilt(b, a, Byfft)
plt.plot(BxTime, BxHPF, label='Canal 1', color='r', linewidth=0.5, linestyle="-")
plt.plot(ByTime, ByHPF, label='Canal 3', color='b', linewidth=0.5, linestyle="-")
| improve this answer | |
$\endgroup$
  • $\begingroup$ I know, but I've got information that I have to wait 2 hours to do so. $\endgroup$ – Hiddenguy Jan 1 '18 at 12:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.