FFT - How to transform my amplitudes into dB

350 ビュー (過去 30 日間)
Jacques
Jacques 2023 年 6 月 26 日
編集済み: Gabriele Bunkheila 2024 年 12 月 10 日
Hello,
I have done a code to obtain the FFT of an audio recorded with Matlab. I'm getting my result in amplitude but I'd like to get it in dB in the frequency domain... Could someone please help me?
Here is my code and my curves:
Thank you for your help.

採用された回答

Frantz Bouchereau
Frantz Bouchereau 2024 年 12 月 10 日
編集済み: Gabriele Bunkheila 2024 年 12 月 10 日
Here is a popular MATLAB doc page that explains the relationship between FFT and true power spectra: Power Spectral Density Estimates Using FFT. Use this to scale the FFT to obtain true power values.

その他の回答 (1 件)

Diya Tulshan
Diya Tulshan 2023 年 6 月 26 日
Hii Jacques,
I understand you want to plot the data in db.
Kindly look into the code given below, it should solve your problem:-
Fs = 16000; % Sampling rate (Hz)
Channels = 1; % Number of audio channels
bits = 16; % Number of bits per sample
r = audiorecorder(Fs, bits, Channels);
duration = 10;
disp('Recording started');
recordblocking(r, duration);
disp('Recording stopped');
X = getaudiodata(r);
N = length(X);
f = (0:N/2) * (Fs/N);
t = (0:N-1) / Fs;
subplot(2,1,1);
plot(t, X);
xlabel('Time (s)');
ylabel('Amplitude');
title('Time Domain Plot');
Y = fft(X, N);
Y = abs(Y(1:N/2+1));
fftResult_dB = 20 * log10(Y); % covert into dB
subplot(2,1,2);
plot(f, fftResult_dB);
xlabel('Frequency (Hz)');
ylabel('Amplitude (dB)');
title('Frequency Domain Plot');
xlim([0, Fs/2]);
grid on;
Hope this helps!
  2 件のコメント
Jacques
Jacques 2023 年 6 月 26 日
Thank you Diya for your help!
I've tested your code and this is what I get:
Getting negative values for my dBs disturbs me...I don't know how to interpret them
Paul
Paul 2023 年 6 月 26 日
編集済み: Paul 2023 年 6 月 26 日
Converting any number less than 1 and greater than 0 to dB will yield a negative result. db(0) is -Inf.
20*log10([2 1 .5 .1 0])
ans = 1×5
6.0206 0 -6.0206 -20.0000 -Inf
So the negative values in dB tells you that the corresponding absolute amplitude is in the range 0 < amplitude < 1.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by