Average of multiple Thompson Multitaper Power Spectral Density Estimates

3 views (last 30 days)
I am doing signal processing of fricative sounds. I have managed to plot the tokens I have on the same plot, but I also want to plot the average spectra, based on the other PSDs . Of course, I would like it if I could also plot the average spectra in a different color! Any help would be appreciated.
The current spectra I have were created using the functions:
Hs = spectrum.mtm;
fs = 44100 %this is the recording quality of the signal;
x = wavread('filename');
y = wavread('otherfilename');
z = wavread('lastfilename');
x1 = psd(Hs, x, 'fs', fs);
y2 = psd(Hs, y, 'fs', fs);
z1 = psd(Hs, z, 'fs', fs);
hold on;
plot(x1);
plot(y1);
plot(z1);
I want to plot the average spectrum on top of those spectrums (in black, if possible)! Again, thank you for any help!
I have attached the .wav files in a .zip folder.
Phil

Accepted Answer

Image Analyst
Image Analyst on 2 Aug 2014
So can't you just take the mean and plot it? I mean
meanSpectrum = (x1+y1+z1)/3;
plot(meanSpectrum, 'k-', 'LineWidth', 3);
legend('x1', 'y1', 'z1', 'meanSpectrum');
It seems really trivial, or am I missing something???
  16 Comments
Image Analyst
Image Analyst on 3 Aug 2014
Edited: Image Analyst on 3 Aug 2014
This is my code. Originally you were plotting the first 9 as a function of element number, not frequency, and only the mean PSD was vs. frequency, so it was all messed up.
Hs = spectrum.mtm;
fs = 44100 %this is the recording quality of the signal;
w1 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_1.wav');
w2 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_2.wav');
w3 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_3.wav');
w4 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_4.wav');
w5 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_5.wav');
w6 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_6.wav');
w7 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_7.wav');
w8 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_8.wav');
w9 = wavread('C:\Users\Mark\Documents\Temporary\sheppard_9.wav');
psd1 = psd(Hs, w1, 'fs', fs);
psd2 = psd(Hs, w2, 'fs', fs);
psd3 = psd(Hs, w3, 'fs', fs);
psd4 = psd(Hs, w4, 'fs', fs);
psd5 = psd(Hs, w5, 'fs', fs);
psd6 = psd(Hs, w6, 'fs', fs);
psd7 = psd(Hs, w7, 'fs', fs);
psd8 = psd(Hs, w8, 'fs', fs);
psd9 = psd(Hs, w9, 'fs', fs);
hold on;
plot(psd1.Frequencies, psd1.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd2.Frequencies, psd2.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd3.Frequencies, psd3.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd4.Frequencies, psd4.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd5.Frequencies, psd5.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd6.Frequencies, psd6.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd7.Frequencies, psd7.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd8.Frequencies, psd8.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
plot(psd9.Frequencies, psd9.Data, '-', 'Color', rand(1,3), 'LineWidth', 2);
meanPsd = (psd1.Data + psd2.Data + psd3.Data + psd4.Data + psd5.Data + psd6.Data + psd7.Data + psd8.Data + psd9.Data)/9;
plot(psd1.Frequencies, meanPsd, 'k-', 'LineWidth', 5);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
grid on;
legend('x', 'y', 'z', 'Mean');
Phil
Phil on 3 Aug 2014
Based on what you were doing I changed the functions to:
[pxxa,fa] = pmtm(a, 3, length(a), fs);
[pxxb,fb] = pmtm(b, 3, length(b), fs);
[pxxc,fc] = pmtm(c, 3, length(c), fs);
[pxxd,fd] = pmtm(d, 3, length(d), fs);
[pxxe,fe] = pmtm(e, 3, length(e), fs);
[pxxf,ff] = pmtm(f, 3, length(f), fs);
[pxxg,fg] = pmtm(g, 3, length(g), fs);
[pxxh,fh] = pmtm(h, 3, length(h), fs);
[pxxi,fi] = pmtm(i, 3, length(i), fs);
Instead of the psd function! I'm not sure why it worked, but it did, and then I was able to follow your original suggestion of just adding them and dividing by the total, which gave me a plot like the one I attached, which is exactly what I'm trying to plot. To get the axis the way I wanted, I had to manually change it. I'm gonna try and figure out some code to automate that as well.
Thanks for taking the time to help me! I'm sure I couldn't have figured this out without your suggestions.
Thanks!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!