Power spectrum RMS or peak I’m a newbie and wondering if I calculate the power spectrum from the peak amplitude or from the amplitude rms ?

This is my matlab script so far:

%-----------------------
% Signal time domain
%-----------------------

Fs = 2000; % Sampling frequency Hz 
dT = 1/Fs; % Sampling period 
L = 1024; % Length of signal [points]
t = (0:L-1)*dT; % Time vector

% Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and a 120 Hz sinusoid of amplitude 1.

S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
% convert row vector to column vector
S = S(:); 
%---------------------------
% Windowing
%---------------------------
win = hamming(L); % Window
winS = S.*win; % Windowed signal

% Calc window scaling factor
coherentGain = sum(win)/L;
scaleFactorWin = 1/coherentGain;
%---------------------------
% FFT 
%---------------------------
Y = fft(winS);
Y = scaleFactorWin*Y;
% Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
Ampl = P1;
Ampl(2:end-1) = 2*P1(2:end-1); % Mult by 2 because we discarded the left side of the spectrum (skip first (DC) and last (Ny) values)
%---------------------------
% Power Spectrum : Magnitude^2 
%---------------------------
% Calculate with already scaled windowed data
PS = 2 * P1.^2;     % Mult by 2 for discarded left side

% or with rms amplitude spectrum: 

PSrms = 2 * (P1.*1/sqrt(2)).^2;

% PLot
f = Fs*(0:(L/2))/L;

plot(f,PS) 
title('Single-Sided Power Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('P²')

plot(f,PSrms) 
title('Single-Sided Power Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('P²')




This is my matlab script so far.
Im not sure how to calculate the power spectrum, either with PS or Psrms (see below)

Thanks for your help.
Mike

%-----------------------
% Signal time domain
%-----------------------

Fs = 2000; % Sampling frequency Hz 
dT = 1/Fs; % Sampling period 
L = 1024; % Length of signal [points]
t = (0:L-1)*dT; % Time vector

% Form a signal containing a 50 Hz sinusoid of amplitude 0.7 and a 120 Hz sinusoid of amplitude 1.

S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
% convert row vector to column vector
S = S(:); 
%---------------------------
% Windowing
%---------------------------
win = hamming(L); % Window
winS = S.*win; % Windowed signal

% Calc window scaling factor
coherentGain = sum(win)/L;
scaleFactorWin = 1/coherentGain;
%---------------------------
% FFT 
%---------------------------
Y = fft(winS);
Y = scaleFactorWin*Y;
% Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
Ampl = P1;
Ampl(2:end-1) = 2*P1(2:end-1); % Mult by 2 because we discarded the left side of the spectrum (skip first (DC) and last (Ny) values)
%---------------------------
% Power Spectrum : Magnitude^2 
%---------------------------
% Calculate with already scaled windowed data
PS = 2 * P1.^2;     % Mult by 2 for discarded left side

% or with rms amplitude spectrum: 

PSrms = 2 * (P1.*1/sqrt(2)).^2;

% PLot
f = Fs*(0:(L/2))/L;

plot(f,PS) 
title('Single-Sided Power Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('P²')

plot(f,PSrms) 
title('Single-Sided Power Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('P²')
Neither. You calculate the power spectrum from the signal directly. Both RMS value and peak are a single value that quantifies a long period. Hence, for all frequencies higher than the reciproce of that period will be lost.