I want to analyse a trc oscilloscope file, find impulses and envelope them. In the end I want to plot the envelope.

data file (trc): https://ufile.io/z4m4d

Code: (Python)

import matplotlib.pyplot as plt
import pandas as pd
import readTrc
import numpy as np
from scipy.signal import hilbert

#Read trc file
datX, datY, m = readTrc.readTrc('C220180104_ch2_UHF00014.trc')
srx, sry = pd.Series(datX * 1000), pd.Series(datY * 1000)
df = pd.concat([srx, sry], axis = 1)
df.set_index(0, inplace = True)

#Impulse location
x1 = df[1].idxmax() - 0.0005        #numeric used to show area before impulse
x2 = df[1].idxmax() + 0.003         #numeric used to show area after impulse
df2 = df.loc[x1:x2]

#Locate Maximum
print('Maximum at:', round(df[1].idxmax(), 6), 'ms')

#Plot Impulse (abs)
df3 = df2.abs().interpolate()
df3.plot.area(grid = 1,
              linewidth = 0.5)

signal = hilbert(df2)
envelope = np.abs(signal)
df4 = pd.DataFrame(envelope)
df4.plot(color = 'red')

plt.xlabel('Zeit / ms')
plt.ylabel('UHF-Signal / mV')

##plt.savefig('UHF_plot.png', dpi = 600)


The Output does not look like an envelope.


enter image description here

The hilbert function produces this (it does not look like an envelope):

enter image description here

How would I get something like this:

enter image description here

  • $\begingroup$ Have you tried low-pass filtering the signal? It seems that you have high-frequency components in your signal. These will not magically dissapear because you have used the Hilbert transform. $\endgroup$ – Ben Dec 3 '18 at 18:41
  • $\begingroup$ The data file is approximately 190MB of a download, in a format (.trc) that requires external (to MATLAB) code to be installed. Would it be possible to provide a little bit more information about your problem (e.g. sampling frequency (?), what is the signal we are looking at? Where is it coming from, what conditions, what experiment?) or simply isolate the vector you are are trying to recover the envelope from and provide a link to THAT download only please? $\endgroup$ – A_A Dec 4 '18 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.