I need to obtain an FFT spectrum and Power spectrum in dB for a .wav file with 2s of data. I need to obtain an "averaged power in dB" for the complete time period. I use the following code :
# Read 2s of data from wav file
y, sr = librosa.load('Noise Recorder.wav',sr=None,duration=2)
# Short FFT, no overlap, nfft=8192, Hanning window
S = librosa.stft(y=y,n_fft=8192,window='hann')
# Power in dB
power = librosa.power_to_db(np.abs(S)**2)
# Frequency components
freqs = librosa.fft_frequencies(sr=sr, n_fft=n_fft)Here i see other formulas to calculate power. For ex: D = librosa.amplitude_to_db(np.abs(S), ref=np.max) # Convert to DB and in some cases energy = np.mean(mag**2, axis=1)/(n_fft/2)**2 Which formula should i use to obtain power spectrum for my window averaged over the entire 2s?
Also, I would like to 1) visualize Frequency vs dB (averaged for the entire 2s in a plot) and 2)average of the power spectrum(RMS/Leq) over the entire 2s. Please let me know how to proceed further.
Thanks
7 Related questions 10 power spectrum by numpy.fft.fft 2 Power spectrum of real data with fftpack on log axis 10 Python Spectrum Analysis Related questions 10 power spectrum by numpy.fft.fft 2 Power spectrum of real data with fftpack on log axis 10 Python Spectrum Analysis 1 How to get spectrum for the whole period of time of music signal using librosa? 0 Negative power spectrum 7 python librosa package - How can I extract audio from spectrum 1 Power spectrum of wav file using python 2 How to plot spectrum or frequency vs amplitude of entire audio file using python? 1 Why does librosa STFT show wrong frequencies? 8 Getting the frequencies associated with STFT in Librosa Load 7 more related questions Show fewer related questions Reset to default