Hi, I was thinking that the peak value observed at the power spectrum for a single tone signal will be the same as its power, but I did not see that when I coded it in matlab when verification. In the matlab code, I was expecting to see the peak power value of -3dB but what I observed is -9dB when using matlab function 'periodogram', and -11.8dB when I later coded the periodogram function. Please advise if my understanding is wrongly or if I code it wrongly. Thanks. The matlab codes is as follows: clear all; Fs=1000; T=0:1/Fs:0.3; x=cos(2*pi*200*t); % First, observe the peak value using Matlab function figure;periodogram(x,[],'onesided',512,Fs) % peak value observed is -9dB pow=var(x); disp(['Power is ',num2str(10*log10(pow)),'dB']) % power of x is -3dB % Try coding PSD: N=length(x); n=(0:N-1); PSD=zeros(1,N); for k=0:N-1 fk=k/N; X=sum(x.*exp(-j*2*pi*n*fk)); PSD(k+1)=(abs(X)^2)/(N*Fs); end PSD_dB=10*log10(PSD); fk=(0:N-1)*Fs/N; figure;plot(fx,PSD_dB) xlim([min(fk),max(fk)]) % peak value observed is -11.8dB

# Power value of signal estimated in Spectrum

Started by ●November 28, 2013

Reply by ●December 5, 20132013-12-05

On Thu, 28 Nov 2013 00:15:18 -0800 (PST), yweesoon@gmail.com wrote:>Hi, > >I was thinking that the peak value observed at the power spectrum for a single tone signal will be the same as its power, but I did not see that when I coded it in matlab when verification. In the matlab code, I was expecting to see the peak power value of -3dB but what I observed is -9dB when using matlab function 'periodogram', and -11.8dB when I later coded the periodogram function. Please advise if my understanding is wrongly or if I code it wrongly. > >Thanks. > >The matlab codes is as follows: >clear all; >Fs=1000; >T=0:1/Fs:0.3; >x=cos(2*pi*200*t); >% First, observe the peak value using Matlab function >figure;periodogram(x,[],'onesided',512,Fs) % peak value observed is -9dB >pow=var(x); >disp(['Power is ',num2str(10*log10(pow)),'dB']) % power of x is -3dB > >% Try coding PSD: >N=length(x); >n=(0:N-1); >PSD=zeros(1,N); >for k=0:N-1 > fk=k/N; > X=sum(x.*exp(-j*2*pi*n*fk)); > PSD(k+1)=(abs(X)^2)/(N*Fs); >end > >PSD_dB=10*log10(PSD); >fk=(0:N-1)*Fs/N; >figure;plot(fx,PSD_dB) xlim([min(fk),max(fk)]) % peak value observed is -11.8dBHello yweesoon, First, you used an uppercase "T" and a lowercase "t" to represent the same variable. That's not good practice. Second, your "plot(fx,PSD_dB)" line is incorrect. With that said, I think you don't need to use all sorts of complicated Matlab code to measure the power of your sine wave signal. (Matlab's 'periodogram()' command windows the time samples, and I don't think you want that complication.) The discrete version of Parseval's theorem (for real-valued signals) states that the sum of the squared times samples is equal to 1/N times the sum of the DFT's freq magnitude samples squared. In Matlab, try this: N = length(x); Spec = fft(x); Left_side_of_Pars_Eq_over_N = sum(abs(x).^2)/N Right_side_of_Pars_Eq_over_N = sum(abs(Spec).^2)/N^2 Time_domain_RMS = sqrt(sum(abs(x).^2)/N) Freq_domain_RMS = sqrt(sum(abs(Spec).^2)/N^2) and see what happens. Also, search the web for "Parseval's theorem" and learn about that equality. By the way, your freq plots exhibit spectral leakage because your sine wave's freq is not at an FFT's bin center. To change this replace your 'T=0:1/Fs:0.3;' line with T=0:1/Fs:0.3-1/Fs; to generate an integer number of sine wave cycles, and add this code N = length(x) figure(4) plot(x, '-bo') axis([1, N + 20, -1, 1.2]) figure(5) plot(abs(fft(x)), '-ro') Good Luck, [-Rick-]

Reply by ●December 17, 20132013-12-17

On Thursday, November 28, 2013 4:15:18 PM UTC+8, ywee...@gmail.com wrote:> Hi, > > > > I was thinking that the peak value observed at the power spectrum for a single tone signal will be the same as its power, but I did not see that when I coded it in matlab when verification. In the matlab code, I was expecting to see the peak power value of -3dB but what I observed is -9dB when using matlab function 'periodogram', and -11.8dB when I later coded the periodogram function. Please advise if my understanding is wrongly or if I code it wrongly. > > > > Thanks. > > > > The matlab codes is as follows: > > clear all; > > Fs=1000; > > T=0:1/Fs:0.3; > > x=cos(2*pi*200*t); > > % First, observe the peak value using Matlab function > > figure;periodogram(x,[],'onesided',512,Fs) % peak value observed is -9dB > > pow=var(x); > > disp(['Power is ',num2str(10*log10(pow)),'dB']) % power of x is -3dB > > > > % Try coding PSD: > > N=length(x); > > n=(0:N-1); > > PSD=zeros(1,N); > > for k=0:N-1 > > fk=k/N; > > X=sum(x.*exp(-j*2*pi*n*fk)); > > PSD(k+1)=(abs(X)^2)/(N*Fs); > > end > > > > PSD_dB=10*log10(PSD); > > fk=(0:N-1)*Fs/N; > > figure;plot(fx,PSD_dB) xlim([min(fk),max(fk)]) % peak value observed is -11.8dBHi Rick, Thanks for your time in explaining to me. Sorry for the late reply as I was always for few weeks. The example I used (as follows) was extracted from Matlab's help; topic under "periodogram function": Fs=1000; t=0:1/Fs:0.3; x=cos(2*pi*200*t); figure;periodogram(x,[],'onesided',512,Fs) To date, my understanding is as follows: 1) The nfft of periodogram is 512 will correspond to a time record of 512/Fs=512ms. 2) The continuous single tone sinewave when performed by FFT is actually time limited to a data record length of 512ms. This means that in the frequency domain it actually has a bandwidth of 2/512ms=3.9 Hz. 3) Due to the finite time record length, the signal tone signal now becomes a band-limited signal of bandwith 3.9Hz centered at 200Hz. Thus when see in the periodogram, its peak power is not -3dB but should be -3dB + 10*log10(1/3.9)=8.9dB which is quite close to that observed in Matlab's periodogram function of -9dB. Thanks for sharing.

Reply by ●December 18, 20132013-12-18

Hi Rick, I was wrong again in my previous reply. I tried with the following settings: figure;periodogram(x,[],'onesided',5*512,Fs) If I what I said earlier was correct, then the power observed should be -1.9282 dB based on the followings: nfft=5*512=> data record length=5*512/Fs=2.56sec, BW=2/data_record_length=2/2.56=0.7813 Hz, then power observed should be -3dB + 10log10(1/0.7813)=-1.9282dB. However, what observed on Matlab's periodogram was -8.24dB, thus I am wrong! Please advise!