Reference value for magnitude of fft output

In summary: B. In summary, the code uses the function 20*log10(xfft) to calculate the magnitude in dB, referenced to 1. To reference the scale to another value, the code can be modified to 'mag = 20*log10(xfft/reference)'. This will set the peak magnitude to 0dB and all other values will be relative to it.
  • #1
Ricicle
1
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
  • #2
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)'
 
  • #3


Hello,

Thank you for your question. The magnitude of the output values of the Fourier transform is calculated using the equation |X(k)| = sqrt(Re(X(k))^2 + Im(X(k))^2), where X(k) is the complex output of the Fourier transform at frequency k. The line 'mag = 20*log10(xfft);' is converting the magnitude values to decibels (dB) using the equation 20*log10(|X(k)|). This is a common way to represent the magnitude of a signal in signal processing, as it allows for a more intuitive understanding of the magnitude values.

In terms of assigning a reference value to the peak magnitude, you can use the peak value of the magnitude spectrum as your reference and subtract it from all other values. This will set the peak value to 0dB and all other values will be relative to it. However, keep in mind that the reference value will depend on the specific data sample you are analyzing, so it may not be a constant value for all datasets.

I hope this helps clarify the code and how to assign a reference value. Let me know if you have any further questions. Best of luck with your data analysis!
 

Related to Reference value for magnitude of fft output

What is a reference value for magnitude of fft output?

A reference value for magnitude of fft output is a measure of the strength or amplitude of a specific frequency component in a signal. It is typically represented as a numerical value and is used to compare the relative strength of different frequency components in a signal.

How is the reference value for magnitude of fft output calculated?

The reference value for magnitude of fft output is calculated by taking the absolute value of the complex output from a Fast Fourier Transform (FFT) and scaling it by the number of samples in the original signal. This results in a value that represents the amplitude of the frequency component at a specific point in time.

Why is a reference value for magnitude of fft output important?

A reference value for magnitude of fft output is important because it allows us to analyze and compare the frequency components of a signal. It can help us identify dominant frequencies, harmonics, and other patterns that may be present in the signal.

What is the relationship between the reference value for magnitude of fft output and the original signal?

The reference value for magnitude of fft output is directly related to the original signal from which it was calculated. It represents the amplitude of a specific frequency component in the signal at a given point in time. By analyzing this relationship, we can gain insight into the characteristics of the original signal.

How is the reference value for magnitude of fft output used in practical applications?

The reference value for magnitude of fft output is used in a variety of practical applications, such as audio and signal processing, image analysis, and vibration analysis. It can help us identify and filter out noise, detect patterns in data, and extract useful information from signals. It is also used in quality control and testing to ensure that signals meet certain specifications.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
400
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
862
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
13K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Electrical Engineering
Replies
4
Views
1K
Replies
26
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
8K
Back
Top