15 views (last 30 days)

Show older comments

It seems the signal power is 3dB higher than actual power. Does anyone can explain me why?

For example, I have f(t)=A*sin(2*pi*f*t), its power is f(t)^2 integrated over a cycle then divide the cycle period, (1/T*int(f(t)^2)) which is equal to A^2/2 as expected. (match with RMS calculation as well =(A/sqrt(2))^2)

However, both Cadence Virtuoso dft and Matlab FFT give me signal power = A^2.

The way how I calculate the power is as below: I assume the amplitude of the single tone in one bin of FFT results (coherent sampling) is magx. I calculate the power as magx^2.

I have to calculate the power in this way instead of (magx/sqrt(2))^2 because the noise from all other bins are calculated as sum squared. Otherwise, my SNR will be wrong.

From another perspective, it means the noise is also 3dB higher than actual gaussion noise variance value. So the final SNR is correct if I calculate the signal power as magx^2, which is 3dB higher than actual signal power.

I just wonder why there is 3dB difference in fft results compared with actual power, especially for noise? It seems to me the FFT report peak magnitude instead of rms magnitude.

I have the code attached.

%%whether fft give noise in rms or peak, what is the correct snr?

%%SNR/FFT/SFDR/SNDR/noise simulation

%%https://www.mathworks.com/help/signal/ref/snr.html#bt3er4n

%%https://www.mathworks.com/help/matlab/ref/fft.html

clear;close all;

rng default

%rng(1);

FlagTwoTone = false;

tone1 = 53/128*800e6;

Amp = 0.532 * 10^(1.37/20); %input amplitude * PGA gain = 0.623

fs = 800e6;

N = 128;

t = (0:N-1)*1/fs;

freq = fs*(0:(N/2))/N;

noisestd = 300e-6; % assume noise std = 300 uV

sig = Amp*sin(2*pi*tone1*t);

noise = noisestd*randn(size(sig)); %zero mean, variance = noisestd^2

myx = sig + noise;

Tone1dB = 20*log10(Amp/sqrt(2))

noisedB = 20*log10(noisestd)

%deltadB= Tone1dB - noisedB

mySNRviasnr = snr(sig, noise)

Y = fft(myx, N); %length(myx) = N

P2 = abs(Y/N); %double sided fft spectrum, convert complex to mag and then divided by N=128, why divide 128?

P1 = P2(1:N/2+1); %matlab starts with 1

P1(2:end-1) = 2*P1(2:end-1);

modP1 = P1;

figure(1);

plot(freq,P1)

title('Single-Sided Amplitude Spectrum of myx(t)')

xlabel('f (Hz)')

ylabel('|P1(f)|')

grid on;

simTone1amp = 0;

simTone1index = 0;

simTone1freq = 0;

for i = 1:length(modP1)

if simTone1amp < modP1(i)

simTone1amp = modP1(i);

simTone1index = i;

end

end

%simTone1index

%simTone1amp =P1(simTone1index)

simTone1freq = freq(simTone1index);

modP1(simTone1index) = 0;

simTone1dB = 20*log10(simTone1amp)

if FlagTwoTone %two tones only

simTone2amp = 0;

simTone2index = 0;

simTone2freq = 0;

for i = 1:length(modP1)

if simTone2amp < modP1(i)

simTone2amp = modP1(i);

simTone2index = i;

end

end

simTone2freq = freq(simTone2index);

modP1(simTone2index) = 0;

end

simHarmonicAmp = 0;

simHarmonicIndex = 0;

simHarmonicFreq = 0;

%test = 0;

for i = 1:length(modP1)

%test = test + modP1(i)^2;

if simHarmonicAmp < modP1(i)

simHarmonicAmp = modP1(i);

simHarmonicIndex = i;

end

end

simHarmonicFreq = freq(simHarmonicIndex);

fftTotalNoise = sum(modP1.^2);%sum squared total noises

simNoisedB = 10*log10(fftTotalNoise)

%test

if FlagTwoTone

else

SNDR = 10*log10(simTone1amp^2/fftTotalNoise)

end

dpb
on 19 May 2018

Edited: dpb
on 19 May 2018

The normalization is all in your code--

P2 = abs(Y/N);

P1 = P2(1:N/2+1);

P1(2:end-1) = 2*P1(2:end-1);

This is the way to normalize a one-sided PSD such that the peak amplitude for a pure signal matches the peak of the signal in time domain; if you want RMS, then that's up to you.

NB: However, this normalization for a single bin works(*) only if the frequency sampling is such the tone of the input signal exactly matches a frequency bin; otherwise the energy will be spread over adjacent bins...discussion/illustration just a few days ago at Answer_319928

(*) That is, the normalization is correct; the maximum amplitude of a single bin in the PSD only matches the time domain peak if the energy is all at the precise bin frequency.

dpb
on 25 May 2018

Misunderstood what I was driving at I think; the FFT doesn't know or care about what the input is; which is why there's no 1/R term in the ML version. The instruments are developed "for purpose".

That there needs be a RMS() term for your purpose I'm not disagreeing.

Jesús Lucio
on 14 Sep 2020

Hi (2 years late, I know!, but the topic is interesting forever, isn't it?)

Note that 3dB approximately equals 10log10(2), so in "normal" (not dB) units, we are talking of just a factor 2 (instead of a term 3dB). I'm pretty sure it's because actual power is that of two peaks (as the signal is real, then the FFT is symmetric) and possibly you are considering only one (for positive frequencies typically) peak. Can it be that?

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

Start Hunting!