Reference value for magnitude of fft output

Click For Summary
SUMMARY

The discussion focuses on calculating the magnitude of Fourier transform output using the daqacquire and daqdocfft tools. The user encounters confusion regarding the dB reference value in the output, specifically when using the code 'mag = 20*log10(xfft)'. It is clarified that this line computes the magnitude in dB referenced to 1, and values less than 1 will yield negative magnitudes. To set a custom reference value for peak magnitude, the user can modify the code to 'mag = 20*log10(xfft/reference>'.

PREREQUISITES
  • Understanding of Fourier transforms and their applications in signal processing.
  • Familiarity with MATLAB or similar programming environments for data analysis.
  • Knowledge of decibel (dB) scale and its significance in audio and signal measurement.
  • Experience with handling and manipulating arrays in programming.
NEXT STEPS
  • Learn how to implement custom reference values in dB calculations for audio signals.
  • Explore the use of MATLAB's FFT functions for advanced signal processing techniques.
  • Investigate the implications of using different reference values in audio analysis.
  • Study the effects of windowing functions on FFT output and magnitude calculations.
USEFUL FOR

Audio engineers, signal processing researchers, and developers working with sound data analysis who seek to understand and manipulate Fourier transform outputs effectively.

Ricicle
Messages
1
Reaction score
0
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 this is not the case.

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.
 
Physics news on Phys.org
There is nothing wrong with that code as far as I can see.
The line 'mag = 20*log10(xfft)' does indeed calculate the magnitude in dB (the 20 comes from the fact that it is calculating the power spectrum 20=2*10) referenced to 1 and if the variable xfft contains values smaller than 1 it will give negative magnitude values.

The only thing you need to do in order to reference your scale to another value is to write 'mag = 20*log10(xfft/reference)'
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
12
Views
6K
Replies
26
Views
6K