# Average value of power spectral density

I have a spectra of power spectral density (PSD) (vector (1:1e6)) from experimental data (blue color). However I want to plot only average value of PSD (red curve).

How can I do it by using MATLAB?

Thank you so much !

• Just my usual ranting: the PSD is a stochastic expectation value. What you have, based on an experiment, is an estimate of the PSD. – Marcus Müller Mar 23 '17 at 8:13

You should remove how frequency content of the diagram. Simply use moving average filter. find the optimum filter size that produces your desired result. Here is a matlab example code.

t=0:0.001:1;
PSD=2*sin(2*pi*1*t)+10*randn(size(t))+5; %assume as the power spectrum
filtered=zeros(size(t));
M=20 ;% Moving average filter size
for i=1:length(t)-M
filtered(i)=mean(PSD(i:i+M));
end
plot(PSD);
hold on
plot(filtered,'r') • Actually, I need to plot the frequency dispersion of frequency noise from laser. That why I have to use the frequency in this graph. – Hiep Xuan Dinh Mar 23 '17 at 7:18
• Actually, by frequency, I do not mean the frequency of actual data (which in your case is noise from laser). I meant to consider the PSD plot itself as a signal. – MimSaad Mar 23 '17 at 8:52