我想了解为什么在执行fft时我没有获得数组。我想为每个频率获得一个幅度,但是得到两个幅度。
sample_rate, recording = wav.read("Sample_747.wav")
fft = np.fft.fft(recording)
#print sample_rate,recording
def calculate_normalized_power_spectrum(recording, sample_rate):
fft = np.fft.fft(recording)
number_of_samples = len(recording)
# sample_length is the length of each sample in seconds
sample_length = 1./sample_rate
frequencies = np.fft.fftfreq(number_of_samples, sample_length)
positive_frequency_indices = np.where(frequencies>0)
# positive frequences returned by the fft
frequencies = frequencies[positive_frequency_indices]
# magnitudes of each positive frequency in the recording
magnitudes =abs (fft[positive_frequency_indices])
return frequencies, magnitudes
当我做fft时我得到了
print fft
[[ 1644.+0.j 1642.+0.j]
[ 1642.+0.j 1644.+0.j]
[ 1639.+0.j 1639.+0.j]
...,
[ 1704.+0.j 1702.+0.j]
[ 1703.+0.j 1703.+0.j]
[ 1701.+0.j 1701.+0.j]]
当我用我的函数显示幅度时,我为每个频率获得两个幅度
frq,mag =calculate_normalized_power_spectrum(recording, sample_rate)
print mag
[[ 1642. 1644.]
[ 1639. 1639.]
[ 1638. 1640.]
...,
[ 2676. 2676.]
[ 2674. 2676.]
[ 2671. 2671.]]