% COGS 501 Fall 2011 % Octave code to get started with HW2 % format short format compact echo on % Read Peterson-Barney data into a cell array: fname = 'pb.Table1'; nrows = 1520; PB = cell(nrows,9); fid = fopen(fname); for r = 1:nrows PB(r,1) = fscanf(fid,'%s',1); PB(r,2) = fscanf(fid,'%s',1); PB(r,3) = fscanf(fid,'%d',1); PB(r,4) = fscanf(fid,'%s',1); PB(r,5) = fscanf(fid,'%s',1); PB(r,6) = fscanf(fid,'%f',1); PB(r,7) = fscanf(fid,'%f',1); PB(r,8) = fscanf(fid,'%f',1); PB(r,9) = fscanf(fid,'%f',1); end; fclose(fid); % % 1: m = man, w=woman, c=child % 2: m=male, f=female % 3: N=speaker number % 4: V=vowel name (heed/iy, hid/ih, head/eh, had/ae, hod/aa, hawed/ao, hood/uh, who'd/uw, hud/ah, heard/er) % 5: IPA % 6: F0 in Hz % 7: F1 % 8: F2 % 9: F3 % pause % Convert column 1 (man, woman, child) from cell array to string array: MWC = char(PB(:,1)); % Make some useful binary vectors: isman=(MWC=='m'); iswoman=(MWC=='w'); ischild=(MWC=='c'); % man/woman/child as values from 1 to 3: MWCints = isman + 2*iswoman + 3*ischild; % Convert column 2 (male, female) to string array: MF=char(PB(:,2)); % More useful binary vectors: ismale=(MF=='m'); isfemale=(MF=='f'); % Convert column 4 (vowel ID) to integers 1:10 in VID array % Note that options are 'iy','ih','eh', 'ae','aa','ao','uh','uw','ah','er' VID=zeros(length(isman),1); VID = VID + strcmp('iy',PB(:,4)); VID = VID + 2*strcmp('ih',PB(:,4)); VID = VID + 3*strcmp('eh',PB(:,4)); VID = VID + 4*strcmp('ae',PB(:,4)); VID = VID + 5*strcmp('aa',PB(:,4)); VID = VID + 6*strcmp('ao',PB(:,4)); VID = VID + 7*strcmp('uh',PB(:,4)); VID = VID + 8*strcmp('uw',PB(:,4)); VID = VID + 9*strcmp('ah',PB(:,4)); VID = VID + 10*strcmp('er',PB(:,4)); % pause % Make matrix whose rows are vowels, and % columns are F0, F1, F2, F3: F0123 = cell2mat(PB(:,6:9));