0

i am new in python and i want to extract the spectrogram of the magnitude in a text file

Here is my code

dataset = np.loadtxt("trainingdataset.txt", delimiter=",", dtype = np.int32)

fake_size = 1415684
time = np.arange(fake_size)/1415684 # 1kHz
base_freq = 2 * np.pi * 100

x = dataset[:,2]
y = dataset[:,3]
z = dataset[:,4]

xyz_magnitude = x**2 + y**2 + z**2

to_plot = [('x', x), ('y', y), ('z', z), ('xyz', xyz_magnitude)]

for chl, data in to_plot:
    plt.figure(); plt.title(chl)
    d = plt.specgram(data, Fs=1000)
    plt.xlabel('Time [s]'); plt.ylabel('Frequency [Hz]')
    plt.show() 

and there is a sample of my dataset, the dataset headers is a as follows (patient number, time/millisecond, X-axis, Y-axis, Z-axis, label

1,15,70,39,-970,0
1,31,70,39,-970,0
1,46,60,49,-960,0
1,62,60,49,-960,0
1,78,50,39,-960,0
1,93,50,39,-960,0
1,109,60,39,-990,0 

Edit from comments:

there is warning in that code Warning (from warnings module): File "C:\Users******\AppData\Local\Programs\Python\Pytho‌​n36\lib\site-package‌​s\matplotlib\axes_ax‌​es.py", line 7221 Z = 10. * np.log10(spec) RuntimeWarning: divide by zero encountered in log10 –

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Hadeer El-Zayat
  • 281
  • 5
  • 20
  • Where ist the context in respect to programming problems? I see a how-to-so-smth question and some code, but It is not clear to me where your code gives you problems or the result derivate from what you thought youd get out of it. Explain please - edit your question. – Patrick Artner Dec 09 '17 at 08:23
  • i just want to know how to extract the features in a text file!! – Hadeer El-Zayat Dec 09 '17 at 08:27
  • So you dont know the algorythm to implement? wikipedia, google, Scientific papers? Generally SO answers problems related to programming and errors, Here mingle lots of ppl - some might not know what you mean with "extract the spectrogram of the magnitude in a text " so explain it. Maybe you want this: https://stackoverflow.com/questions/14921436/python-finding-word-frequencies-of-list-of-words-in-text-file – Patrick Artner Dec 09 '17 at 08:35
  • thank you.. there is warning in that code Warning (from warnings module): File "C:\Users\hadeer.elziaat\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 7221 Z = 10. * np.log10(spec) RuntimeWarning: divide by zero encountered in log10 – Hadeer El-Zayat Dec 09 '17 at 08:44
  • could u help me with this warning – Hadeer El-Zayat Dec 09 '17 at 08:45
  • Possible duplicate of [RuntimeWarning: divide by zero encountered in log](https://stackoverflow.com/questions/21610198/runtimewarning-divide-by-zero-encountered-in-log) – Patrick Artner Dec 09 '17 at 08:56
  • Search SO for numpy and your error: https://stackoverflow.com/search?q=runtimewarning-divide-by-zero+numpy - lots of hits with lots of answers that explain to you why it happens and how to fix it if you want. – Patrick Artner Dec 09 '17 at 08:58

0 Answers0