[SciPy-User] finding frequency of wav
Fabrice Silva
silva at lma.cnrs-mrs.fr
Thu May 27 09:28:42 EDT 2010
Le jeudi 27 mai 2010 à 10:09 +0200, Linda a écrit :
> Hello all,
> I have a digital signal where the bits in it are encoded with
> frequencies 1300 and 2100 Hz. The message is sent as a wav-file with a
> samplerate of 22050.
> My goal is to find the bits again so I can decode the message in it,
> for that I have chopped the wav up in pieces of 18 samples, which
> would be the bitlength (at 1200 Bit/s > 22050/1200=18.375). So I have
> a list of chunks of length 18. I thought I could just fft each chunks
> and find the max of the chunk-spectrum, to find out the bitfrequency
> in the chunk (and thus the bitvalue)
Correct me if I am wrong. You are cutting your signal into chunks that
you expect to contain at least one period of the lower coding frequency.
You then perform a fft on a very small signal (18 samples) which gives
you (without zero padding) an estimation of the Fourier transform of
your chunk computed on only 18 frequencies, i.e. with a really bad
frequential resolution. It is possible if your coding frequencies are
not too close. A raw Rayleight criteria leads to cut your signal into at
least N=2*Fe/df_min where df_min is the minimal spacing between two
coding frequencies df_min=2100-1300 here thus N=55 (so 64 to have a
power of 2).
>
> But somehow I am stuck in the numbers, I was hopeing you could give me
> a hint. here is what I have:
> chunks[3] #this is one of the wavchunks, there should be a bit hidden in here
> Out[98]:
> array([ 2, -1, 1, -2, 2, -2, 2, -1, 0, 0, 0, 1, -2, 2, -1, 0, 0, 0], dtype=int16)
> test = fft(chunks[3]) # spectrum of the chunk, the peak should give me the value of the bitfrequency 1300 of 2100 Hz?
> test
> Out[100]:
> array([ 1.00000000 +0.00000000e+00j, 1.00000000 +2.37564698e-01j,
> 1.46791111 +4.90375770e-01j, 2.50000000 +8.66025404e-01j,
> 2.65270364 -7.37891832e-01j, 1.00000000 +3.01762603e+00j,
> -0.50000000 -2.59807621e+00j, 1.00000000 -2.41609109e+00j,
> 4.87938524 +1.43601897e+01j, 7.00000000 -6.88706904e-15j,
> 4.87938524 -1.43601897e+01j, 1.00000000 +2.41609109e+00j,
> -0.50000000 +2.59807621e+00j, 1.00000000 -3.01762603e+00j,
> 2.65270364 +7.37891832e-01j, 2.50000000 -8.66025404e-01j,
> 1.46791111 -4.90375770e-01j, 1.00000000 -2.37564698e-01j])
>
>
> I am unsure how to proceed from here, so I would really appreciate any
> tips.. I found fftfreq, but I am not sure how to use it? I read
> fftfreq? but I don't see how the example even uses the 'fourier'
> variable in the fftfreq there?
>
Fftfreq is a function that constructs the frequency vector associated to
the data computed by the fft algorithm. It is aware of how fft orders
the frequency bins, and transform it in a more convenient way (it
'anti-aliases', centering the results on zero frequency).
import numpy as np
import matplotlib.pyplot as plt
chunks[3]=....
test = np.fft.fft(chunks[3])
frequencies = np.fft.fftfreq(len(test), d=1./22050.) # d is the sampling period
plt.plot(frequencies, np.abs(test), 'o')
plt.show()
but you won't see any things on this fft. I am suspicious due to the
fact that the signal to noise ratio seems rather low leading to strong
peak at Fe/2
In chunk[3], what do you expect to be the bit?
Fabricio
More information about the SciPy-User
mailing list