When I used the fft for both numpy and scipy to generate an audio frequency spectrum ,I don't get the same result as an audacity one. I get positive dBm, I must have negative ones.
Here is my code
import numpy as np
from numpy import fft
from scipy.io import wavfile
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
rate,audData = wavfile.read("test.wav")
n = len(audData)
fourier=fft.fft(audData)
fourier = fourier / float(n)
freqArray = np.arange(0, (n/2), 1.0) * (rate*1.0/n);
freq = freqArray/1000
power = 10*np.log10(fo
power = np.abs(power)
plt.plot(freq, power, color='#ff7f00', linewidth=0.02)
plt.xlabel('Frequency (kHz)')
plt.ylabel('(dBm)')
plt.show()
And I tried in another way to use periodogram from scipy.signal
from scipy import signal
freqs, Pxx = signal.periodogram(audio, fs=rate, window='hanning',
detrend=False, scaling='density')
freqs=freqs / 1000
Pxx = 10 * np.log10(Pxx)
plt.plot(freqs, Pxx, color='#ff7f00', linewidth=0.02)
plt.xlabel('Frequency (kHz)')
plt.ylabel('Power (dB)')
plt.show()
I expected to have a plot like this for audacity with negative dBm
but what I got is a range of dBm from negative to positive:
And this by sending values and plotting them from javascript: