Reputation:
I have a wav file which contains a recorded chirp sound.
The Frequency sampling 44100 Number of Channels 1 Complete Samplings N 90405 secs 2.05 The chirp sound is only 50ms.
The image of the chirp: [https://i.sstatic.net/kaDJv.jpg
The code I have so far to read the wav file and carry out some basic processing.
fs_rate, signal = wavfile.read("chirp.wav")
print ("Frequency sampling", fs_rate)
l_audio = len(signal.shape)
print ("Channels", l_audio)
if l_audio == 2:
signal = signal.sum(axis=1) / 2
N = signal.shape[0]
print ("Complete Samplings N", N)
secs = N / float(fs_rate)
print ("secs", secs)
Ts = 1.0/fs_rate # sampling interval in time
print ("Timestep between samples Ts", Ts)
t = scipy.arange(0, secs, Ts) # time vector as scipy arange field / numpy.ndarray
FFT = abs(scipy.fft(signal))
FFT_side = FFT[range(N//2)] # one side FFT range
freqs = scipy.fftpack.fftfreq(signal.size, t[1]-t[0])
fft_freqs = np.array(freqs)
freqs_side = freqs[range(N//2)] # one side frequency range
fft_freqs_side = np.array(freqs_side)
plt.subplot(311)
p1 = plt.plot(t, signal, "g") # plotting the signal
plt.xlabel('Time')
plt.ylabel('Amplitude')
plt.savefig('chirp.jpg')
Problem: Using python how do I tell where the first sample point of the chirp is located in the audio file. First point when the chirp was received.
The signal contains background noise. The result I am expecting should say this is where your chirp signal starts at it is at a 2kHz frequency.
PS: This is not a homework problem. I am learning DSP. Sort of self-study.
Upvotes: 0
Views: 199
Reputation: 1032
If you know the chirp sequence, you could correlate against that to get start of chirp in stream.
import scipy.signal as sig
h = sp.array(chirp_sequence)
rxy = sig.correlate(signal, h)
start_idx = arg.max(abs(rxy))
Upvotes: 1