## Octave Band Averages from PSD

### John (view profile)

on 6 Oct 2012

Hi everyone,

I am using a simple code to extract the PSD from a set of time-based sound data. I am now interested in obtaining the octave band averages of this data and I am completely lost. Can anyone help me out?

The code I ave at the moment is:

*clear all

close all

echo on

Fs= 4000; % Sampling Frequency (Hz)

Hs=spectrum.welch;

psd(Hs,x,'Fs',Fs);

echo off;*

Thanks, John

### Wayne King (view profile)

on 6 Oct 2012
Edited by Wayne King

### Wayne King (view profile)

on 6 Oct 2012

You want to average the power over octave bands? You can do that with the avgpower() method.

```   t = 0:0.001:1-0.001
Fs = 1000;
x = cos(2*pi*50*t)+1/2*sin(2*pi*200*t)+randn(size(t));
psdest = psd(spectrum.welch,x,'Fs',Fs);```

Now to get the average power from [0,100] Hz

`   pwr = avgpower(psdest,[0 100]);`

It may be more useful to consider the percentage of the total power in that interval

```     totpower = avgpower(psdest,[0 Fs/2]);
100*(pwr/totpower)```

John

### John (view profile)

on 8 Oct 2012

Thankyou. That is extremely useful. I do have one more question though if you don't mind.

I am using msspectrum to plot the sound power over the frequency range and using avgpower on my calibration tests to determine how much each test needs to be adjusted.

ie. adjustment = real calibration value - avgpower(calibration)

At this stage, how do I take that adjustment value and apply it to my tests.

ie. instead of plotting by hmss = msspectrum(Hs,x,'Fs',Fs);

plot(hmss)

I want to plot that exact plot by translated down by the adjustment value.

Also, is there any way of exporting the (x,y) values that build the graph if i do plot(hmss)?