Hi,
I'm using a version of daqacquire to acquire a sample of sound data. This program also uses daqdocfft to perform a fourier transform, allowing me to view the frequencies that are present in my data sample.
My problem is that I don't understand how the function is calculating the magnitude of the output values of the fourier transform. The code is as follows:
xfft = abs(fft(data));
% Avoid taking the log of 0.
index = find(xfft == 0);
xfft(index) = 1e-17;
mag = 20*log10(xfft);
mag = mag(1:floor(blocksize/2));
f = (0:length(mag)-1)*Fs/blocksize;
f = f(
;
The line 'mag = 20*log10(xfft);' seems to assign a dB value to the output, referenced to 1. If this was the case, I would expect a plot of the spectrum to have negative magnitudes, since they would all be less than 1. However for the data I'm trying to analyse, the spectrum magnitudes range from -40dB to 80dB.
Ideally what I would like to do is assign a reference value to the peak magnitude in the spectrum, so that it would be set to 0dB, and all other values would be relative to it.
I'd be grateful if anyone could tell me how to do this, or at least explain to me what this code is using as 0dB, and what value is being referenced.
Thanks for any help.