• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Frequency detection

a guest Feb 16th, 2016 126 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from scipy.io.wavfile import read
2. from scipy.fftpack import fft, ifft
3. from matplotlib.mlab import specgram
4. import matplotlib.pyplot as plt
5. import numpy as np
6. import wave
7.
8. #https://en.wikipedia.org/wiki/Special_information_tones
9. freq_913 = 913      #low
10. freq_1370 = 1370    #low
11. freq_1776 = 1776    #low
12.
13. short_duration = 0.276          #short duration 276 ms
14. long_duration = 0.380           #long duration 380 ms
15. interval = 0.004                #interval between tones.
16.
17. path_ic = "IC_SIT.wav"
18. path_ro1 = "RO'_SIT.wav"
19. path_rec = "recording.wav"
20.
21. short_duration_window = int(fs * short_duration)
22. long_duration_window = int(fs * long_duration)
23.
24. stop = 0
25.
26. data = data[0:,0]
27. data_ro = data_ro[0:,0]
28. data_rec = data_rec[0:,0]
29.
30. #Checking first frequency.
31. #print all found in the file.
32. for i in range(0,len(data)):
33.     if int(data[i]) == freq_913 or int(data[i])+1 == freq_913 or int(data[i])-1 == freq_913:
34.         print i, data[i]
35.
36. for i in range(stop,short_duration_window):
37.     if data[i] == freq_1370:
38.         print i, data[i]
39.
41. # https://gist.github.com/livibetter/4118062
42. data = data/6
43.
44. fft_data = fft(data)
45. fft_data_ro = fft(data_ro)
46. fft_data_rec = fft(data_rec)
47.
48. ifft_data = ifft(data)
49. ifft_data_ro = ifft(data_ro)
50.
51. t = np.arange(0.,6.,6./len(ifft_data))
52. t_ro = np.arange(0.,6.,6./len(ifft_data_ro))
53.
54. plt.figure(1)
55. plt.subplot(211)
56. plt.plot(t,ifft_data,"ro")
57.
58. plt.subplot(212)
59. plt.plot(t_ro,fft_data_ro,"bo")
60. plt.show()
61.
62. # getting 1ms window based in the audio sample rate and lenght of the file.
63. window = len(data)/fs*1000
64. window_ro = len(data_ro)/fs_ro*1000
65.
66. offset = 0
67. for i in range(offset,len(data)/window):
68.     for i in range(offset+window,window*offset):
69.         print i, data[i]
70.     raw_input("<Enter to continue>")
71.     print offset
72.     offset += 1
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top