DSPRelated.com
Forums

Computed Power Range Does Not Match Spectrum Analyzer

Started by allendm2001 January 5, 2006
I'm new to DSP and am attempting to use an FFT to approximate in software
the output of a hardware spectrum analyzer.  Using MATLAB, I calculate the
power as follows:

fftOut = fft(samples,512);
magnitude = fftOut. * conj(fftOut);
scaled = magnitude. / 512;
power = 10 * log10(scaled);

The resultant power spectrum looks like the signal displayed on the
spectrum analyzer, however the range is much different.  Power values from
the Matlab power spectrum range between +90 and +150dB, whereas power
values on the spectrum analyzer range from -40 to -100dB.  Am I doing
something wrong in my calculation, or do I have to adjust my output by
some constant.  If I do have to adjust, why?

Thank you,

Doug Allen
Praxis Engineering Technologies, Inc.
dmallen@praxiseng.com

allendm2001 wrote:
> I'm new to DSP and am attempting to use an FFT to approximate in software > the output of a hardware spectrum analyzer. Using MATLAB, I calculate the > power as follows: > > fftOut = fft(samples,512); > magnitude = fftOut. * conj(fftOut); > scaled = magnitude. / 512; > power = 10 * log10(scaled); > > The resultant power spectrum looks like the signal displayed on the > spectrum analyzer, however the range is much different. Power values from > the Matlab power spectrum range between +90 and +150dB, whereas power > values on the spectrum analyzer range from -40 to -100dB. Am I doing > something wrong in my calculation, or do I have to adjust my output by > some constant. If I do have to adjust, why?
The computations look fine. The dynamic range is the same, 60 dB, in the two cases, which is good. You say the curves look the same, which also is good. My guess is that there is some internal calibration in the HW spectrum analyzer. You don't say what type of data this is, but let's assume it is sound you have recorded with a microphone. In that case, the spectrum analyzer scale the output with some constant in order to relate the measurements to some reference pressure. This is something you will have to do yourself in matlab, if you find it necessary. Do you have to scale? It depends entirely what the purpose of the measurement is. If, for instance, you do the sound measurement in order to see if some house complies to some building code, then yes, you have to scale. It is not only the shape, but the magnitude of the spectrum that matters. If you are just curious about the spectrum structure of some data, you don't necessarily need to scale. It depends on the application. Rune
"allendm2001" <allendm2001@yahoo.com> wrote in message
news:6uKdnfHS15In5iDenZ2dnUVZ_v6dnZ2d@giganews.com...
> I'm new to DSP and am attempting to use an FFT to approximate in software > the output of a hardware spectrum analyzer. Using MATLAB, I calculate the > power as follows: > > fftOut = fft(samples,512); > magnitude = fftOut. * conj(fftOut); > scaled = magnitude. / 512; > power = 10 * log10(scaled); > > The resultant power spectrum looks like the signal displayed on the > spectrum analyzer, however the range is much different. Power values from > the Matlab power spectrum range between +90 and +150dB, whereas power > values on the spectrum analyzer range from -40 to -100dB. Am I doing > something wrong in my calculation, or do I have to adjust my output by > some constant. If I do have to adjust, why?
Power values on the spectrum analyzer are probably in dBm (not dB). This means they are absolute amplitude measurements (not relative...which would be dB). dBm is a power value reference to 1 milliwatt of power. A spectrum analyzer is a calibrated receiver and can apply the appropriate offsets and scaling based on it's internal gain and attenuation settings. When you make power spectrum measurements in Matlab, you are going to need some information about your sampled data to apply similar corrections. Without this, the best you can do is to normalize your fft output to the largest signal. That'll give a 0dB (not dBm) output for your largest signal and you can look at other signals relative to this. So I'd do something like scaled = magnitude/max(magnitude). (BTW, what you have isn't magnitude but power here). At this point you should only be off by a single offset value between the spectrum analyzer and your matlab output. Cheers Bhaskar
> Thank you, > > Doug Allen > Praxis Engineering Technologies, Inc. > dmallen@praxiseng.com >
"Bhaskar Thiagarajan" <bhaskart@deja.com> wrote in message 
news:43bd83a7$0$15782$14726298@news.sunsite.dk...
> "allendm2001" <allendm2001@yahoo.com> wrote in message > news:6uKdnfHS15In5iDenZ2dnUVZ_v6dnZ2d@giganews.com...
<snip>
> At this point you should only be off by a single offset value between the > spectrum analyzer and your matlab output. >
But you might want to treat it as two offset values so you can separately account for scaling the amplitude representation of your input signal and the difference between your ffts resolution bandwidth and that set on your spectrum analyser. Best of Luck - Mike
Bhaskar Thiagarajan wrote:
> "allendm2001" <allendm2001@yahoo.com> wrote in message > news:6uKdnfHS15In5iDenZ2dnUVZ_v6dnZ2d@giganews.com... > > I'm new to DSP and am attempting to use an FFT to approximate in software > > the output of a hardware spectrum analyzer. Using MATLAB, I calculate the > > power as follows: > > > > fftOut = fft(samples,512); > > magnitude = fftOut. * conj(fftOut); > > scaled = magnitude. / 512; > > power = 10 * log10(scaled); > > > > The resultant power spectrum looks like the signal displayed on the > > spectrum analyzer, however the range is much different. Power values from > > the Matlab power spectrum range between +90 and +150dB, whereas power > > values on the spectrum analyzer range from -40 to -100dB. Am I doing > > something wrong in my calculation, or do I have to adjust my output by > > some constant. If I do have to adjust, why? > > Power values on the spectrum analyzer are probably in dBm (not dB). This > means they are absolute amplitude measurements (not relative...which would > be dB). dBm is a power value reference to 1 milliwatt of power. A spectrum > analyzer is a calibrated receiver and can apply the appropriate offsets and > scaling based on it's internal gain and attenuation settings. > > When you make power spectrum measurements in Matlab, you are going to need > some information about your sampled data to apply similar corrections. > Without this, the best you can do is to normalize your fft output to the > largest signal. That'll give a 0dB (not dBm) output for your largest signal > and you can look at other signals relative to this. > > So I'd do something like > scaled = magnitude/max(magnitude). (BTW, what you have isn't magnitude but > power here). > > At this point you should only be off by a single offset value between the > spectrum analyzer and your matlab output. > > Cheers > Bhaskar > > > Thank you, > > > > Doug Allen > > Praxis Engineering Technologies, Inc. > > dmallen@praxiseng.com > >
This is something I've dealt with many times, and it can be tricky. It also depends on whether your input signal is noise or tones. Here is one approach for tones. Start by feeding a maximum value, Fs/4 sequence into the FFT. For example if you have a 16 bit ADC, feed in 32767,0,-32768,0,etc. After you convert your FFT bin magnitudes into decibels (10log10(I^2+Q^2)), add a scale factor to adjust the center bin up to zero dB. This factor will vary with the window. After the factor is applied, your FFT is producing data in units of dBFS, or dB relative to ADC full scale. The next step is to figure out how much input signal produces peak value samples from your ADC. You can do this by looking at some of your ADC values as feed a sine wave into it from a signal generator. Try a sinewave with a low digital frequency and adjust the level until the peaks get close to the maximum and minimum values, 32767 and -32768. Then record the power of the signal generator, typically in dBm. A typical value might be -10 dBm, but it depends on what is in front of the ADC, the ADC itself, as well as the output impededance of your generator. You can work this out from the schematic and data sheet but you will want to test it anyway. If you know that -10 dBm produces full scale ADC values, then you can just add 10 dB to the scaled FFT output to convert those values into to dBm at the generator output. If you have RF and IF gain in front of the ADC, then you can subtract that gain directly to get dBm at the antenna input. John
>Bhaskar Thiagarajan wrote: >> "allendm2001" <allendm2001@yahoo.com> wrote in message >> news:6uKdnfHS15In5iDenZ2dnUVZ_v6dnZ2d@giganews.com... >> > I'm new to DSP and am attempting to use an FFT to approximate in
software
>> > the output of a hardware spectrum analyzer. Using MATLAB, I
calculate the
>> > power as follows: >> > >> > fftOut = fft(samples,512); >> > magnitude = fftOut. * conj(fftOut); >> > scaled = magnitude. / 512; >> > power = 10 * log10(scaled); >> > >> > The resultant power spectrum looks like the signal displayed on the >> > spectrum analyzer, however the range is much different. Power values
from
>> > the Matlab power spectrum range between +90 and +150dB, whereas
power
>> > values on the spectrum analyzer range from -40 to -100dB. Am I
doing
>> > something wrong in my calculation, or do I have to adjust my output
by
>> > some constant. If I do have to adjust, why? >> >> Power values on the spectrum analyzer are probably in dBm (not dB).
This
>> means they are absolute amplitude measurements (not relative...which
would
>> be dB). dBm is a power value reference to 1 milliwatt of power. A
spectrum
>> analyzer is a calibrated receiver and can apply the appropriate offsets
and
>> scaling based on it's internal gain and attenuation settings. >> >> When you make power spectrum measurements in Matlab, you are going to
need
>> some information about your sampled data to apply similar corrections. >> Without this, the best you can do is to normalize your fft output to
the
>> largest signal. That'll give a 0dB (not dBm) output for your largest
signal
>> and you can look at other signals relative to this. >> >> So I'd do something like >> scaled = magnitude/max(magnitude). (BTW, what you have isn't magnitude
but
>> power here). >> >> At this point you should only be off by a single offset value between
the
>> spectrum analyzer and your matlab output. >> >> Cheers >> Bhaskar >> >> > Thank you, >> > >> > Doug Allen >> > Praxis Engineering Technologies, Inc. >> > dmallen@praxiseng.com >> > > >This is something I've dealt with many times, and it can be tricky. It >also depends on whether your input signal is noise or tones. Here is >one approach for tones. Start by feeding a maximum value, Fs/4 sequence >into the FFT. For example if you have a 16 bit ADC, feed in >32767,0,-32768,0,etc. After you convert your FFT bin magnitudes into >decibels (10log10(I^2+Q^2)), add a scale factor to adjust the center >bin up to zero dB. This factor will vary with the window. After the >factor is applied, your FFT is producing data in units of dBFS, or dB >relative to ADC full scale. > >The next step is to figure out how much input signal produces peak >value samples from your ADC. You can do this by looking at some of your >ADC values as feed a sine wave into it from a signal generator. Try a >sinewave with a low digital frequency and adjust the level until the >peaks get close to the maximum and minimum values, 32767 and -32768. >Then record the power of the signal generator, typically in dBm. A >typical value might be -10 dBm, but it depends on what is in front of >the ADC, the ADC itself, as well as the output impededance of your >generator. You can work this out from the schematic and data sheet but >you will want to test it anyway. > >If you know that -10 dBm produces full scale ADC values, then you can >just add 10 dB to the scaled FFT output to convert those values into to >dBm at the generator output. If you have RF and IF gain in front of the >ADC, then you can subtract that gain directly to get dBm at the antenna >input. > >John > >
Thank you all for taking the time and being so incredibly responsive to my questions. Doug