# MATLAB & Power Spectral Density - Error - Getting the same range of values regardless of sound type?

I wrote code [attached at end of question] to take .wav files of child vocalizations and tried to see if there are valid ranges for the formants F1:F2:F3 for the 5 different sound categories.

A Formant is the spectral shaping that results from an acoustic resonance of the human vocal tract

The 3D plot below is the output from my code. The professor says that I probably have to fix my peak identifying part of the code. Because F1 is always between 797 and 800 Hz for all sounds.

periodogram gives the spectral density plot, with y in terms of intensity, and x in terms of Hz. I used the code below iterated for the following ranges:

I'm getting the same range of values for all sounds.

 %% Fmaps2.m

clear all;
close all;
clc;
%% absolute paths to the sound directories
Ball='C:\Users\bu\Documents\ELAT\VowelSpace\ChildrenVocalizationsTestModel\Ball - BEST';
Jeep='C:\Users\bu\Documents\ELAT\VowelSpace\ChildrenVocalizationsTestModel\Jeep';
No='C:\Users\bu\Documents\ELAT\VowelSpace\ChildrenVocalizationsTestModel\No';
Tea_Pot= 'C:\Users\bu\Documents\ELAT\VowelSpace\ChildrenVocalizationsTestModel\Tea_Pot';
%% make a cell - to "vectorize" directory path variables
num_sounds=length(sound_dirs);
words=cell(1,num_sounds);
%% peel off the directory name from the path
for i=1:num_sounds;
path=sound_dirs{i};
[path, fname, ext] = fileparts(path);
%This peels off the last folder from path.
%The ext must be preserved in case the folder name has a dot it it.
opendir = strcat(fname, ext);
words{i}=opendir;
end
%% Each Directory is a cell. --- Within each cell you keep the struct array returned by the dir function.
data=cell(length(num_sounds),3); %preallocate space given # sound types
disp(data);
% Each row corresponds to a different sound
% First column = directory name
% Second column = "files struct" for .wav files
% Third column = "formant data struct"
%% fill the data_structure cell columns 1 & 2, with directory names and struct of .wav files.
for i=1:num_sounds;
wavPATH=fullfile(sound_dirs{i}, '*.wav'); % fullfile(Ball, '*.wav'); <-- gives specified path
wavLIST=dir(wavPATH); %saves .wav files in a struct call wavs_in_dir
data{i,2}=wavLIST;
data{i,1}=words{i};
end %all raw data saved into data_structure
%% data_structure{i,3} holds the processed data <-- Formants
for i=1:num_sounds;
NUMwavs=numel(data{i,2});
ith_file=data{i,2};
formants=struct('F1',[],'maxPxx1', [], 'F2',[],'maxPxx2',[], 'F3', [], 'maxPxx3', []);
for k=1:NUMwavs;
%need to define the window frame to match the size of the signal vector
w=ones(1, length(y));
%nfft points in discrete Fourier Transform (DFT)
nfft=length(y);
[pxx,f]= periodogram(y, w,nfft,Fs);
%% now find the range of frequencies
% L1= 200 - 800 Hz
% L2= 800 - 1800 Hz
% L3= 1800 - 3500 Hz
%% find Level 1 indices for frequency values between 200 - 800 Hz
fmin1=200; fmax1=800;
L1_ind= find((f>=fmin1)&(f<=fmax1));%L1_ind are indicies that are within 200-800
%% use L1_ind to find the relevant vectors
chunkOpsdFreqs1= f(L1_ind);%chunkOpsdFreqs1 gives all the freq values that are [200Hz, 800Hz]
chunkOpsd1 = pxx(L1_ind); %chunkOpsd1 gives all the pxx values
maxF1=max(chunkOpsdFreqs1);
maxPxx_index1=find(chunkOpsdFreqs1==maxF1);
maxPxx1=chunkOpsd1(maxPxx_index1);
%% find Level 2 indices for frequency values between 800 - 1800 Hz
Fmin2=800; Fmax2=1800;
L2_ind=find((f>=Fmin2) & (f<=Fmax2));
%% use L2_ind to find the relevant vectors
chunkOpsd2= pxx(L2_ind);
chunkOpsdFreqs2= f(L2_ind);
maxF2=max(chunkOpsdFreqs2);
maxPxx_index2=find(chunkOpsdFreqs2==maxF2);
maxPxx2=chunkOpsd2(maxPxx_index2);
%% find Level 3 indices for frequency values between 1800 - 3500 Hz
Fmin3=1800; Fmax3=3500;
L3_ind=find((f>=Fmin3) & (f<=Fmax3));
%% find Level 3 indices for frequency values between 800 - 1800 Hz
chunkOpsd3= pxx(L3_ind);
chunkOpsdFreqs3= f(L3_ind);
maxF3=max(chunkOpsdFreqs3);
maxPxx_index3=find(chunkOpsdFreqs3==maxF3);
maxPxx3=chunkOpsd3(maxPxx_index3);
%% Store all values in formants struct
% each row has its own formants struct
formants(k).F1= maxF1;
formants(k).F2= maxF2;
formants(k).F3= maxF3;
formants(k).maxPxx1=maxPxx1;
formants(k).maxPxx2=maxPxx2;
formants(k).maxPxx3=maxPxx3;
end
data{i,3}=formants;
end

%% Get the F#s from the structure in the cell
Plot3D=figure(1);
colors= ['b', 'k', 'r', 'g', 'm'];
for i=1:num_sounds;
num_pts=length(data{i,3});
for n=1:num_pts;
N=num2str(n);
[F1pts]=zeros(1,num_pts);
[F2pts]=zeros(1,num_pts);
[F3pts]=zeros(1,num_pts);
end

for n=1:num_pts;
F1pts(n)=data{i,3}(n).F1;
F2pts(n)=data{i,3}(n).F2;
F3pts(n)=data{i,3}(n).F3;
end
Plot3D; scatter3(F1pts, F2pts, F3pts, colors(i)); hold on;
end
Plot3D;
xlabel('F1 (Frequency) in Hz'); ylabel('F2 (Frequency) in Hz'); zlabel('F3 (Frequency) in Hz');
legend(data{1,1}, data{2,1}, data{3,1}, data{4,1}, data{5,1});


## bumped to the homepage by Community♦8 hours ago

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.