Dawn@4: function mdata = func_buildMData(matfile, smoothwin) Dawn@4: % mdata = func_buildMData(matfile, smoothwin) Dawn@4: % Input: mat filename Dawn@4: % smoothing window size (0 denotes no smoothing) Dawn@4: % Output: mat data structure Dawn@4: % Notes: Function tries to construct as many parameters as possible based Dawn@4: % on the parameters currently in the mat file. Some parameters will have a Dawn@4: % different variable name to what is originally stored in the mat file: Dawn@4: % e.g. H1 is actually the uncorrected harmonic (H1u), it is stored this way Dawn@4: % for compatability reasons. Dawn@4: % Dawn@4: % Author: Yen-Liang Shue, Speech Processing and Auditory Perception Laboratory, UCLA Dawn@4: % Copyright UCLA SPAPL 2009 Dawn@4: Dawn@4: mdata = load(matfile); Dawn@4: Dawn@4: % these are for compatibility with VS0 matfiles Dawn@4: if (~isfield(mdata, 'HF0algorithm')) Dawn@4: mdata.HF0algorithm = 'F0 (Straight)'; Dawn@4: end Dawn@4: Dawn@4: if (~isfield(mdata, 'AFMTalgorithm')) Dawn@4: mdata.AFMTalgorithm = 'F1, F2, F3, F4 (Snack)'; Dawn@4: end Dawn@4: Dawn@4: if (~isfield(mdata, 'Fs')) Dawn@4: mdata.Fs = 16000; Dawn@4: end Dawn@4: Dawn@4: % get the right F0 Dawn@4: F0 = func_parseF0(mdata, mdata.HF0algorithm); Dawn@4: [F1, F2, F3] = func_parseFMT(mdata, mdata.AFMTalgorithm); Dawn@4: Dawn@4: % can't do much without F0 or FMTs Dawn@4: if (isempty(F0) || isempty(F1)) Dawn@4: return; Dawn@4: end Dawn@4: Dawn@4: % get bandwidth mapping Dawn@4: B1 = func_getBWfromFMT(F1, F0, 'hm'); Dawn@4: B2 = func_getBWfromFMT(F2, F0, 'hm'); Dawn@4: B3 = func_getBWfromFMT(F3, F0, 'hm'); Dawn@4: Dawn@4: % Hx Dawn@4: if (isfield(mdata, 'H1')) Dawn@4: mdata.H1u = mdata.H1; % H1 is actually the uncorrected harmonic Dawn@4: mdata.H1c = mdata.H1u - func_correct_iseli_z(F0, F1, B1, mdata.Fs); % correct for F1 Dawn@4: mdata.H1c = mdata.H1c - func_correct_iseli_z(F0, F2, B2, mdata.Fs); % correct for F2 Dawn@4: if (smoothwin~=0) Dawn@4: mdata.H1u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1u); Dawn@4: mdata.H1c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1c); Dawn@4: end Dawn@4: %mdata = rmfield(mdata, 'H1'); % remove H1 to remove confusion Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H2')) Dawn@4: mdata.H2u = mdata.H2; % H2 is actually the uncorrected harmonic Dawn@4: mdata.H2c = mdata.H2u - func_correct_iseli_z(2*F0, F1, B1, mdata.Fs); Dawn@4: mdata.H2c = mdata.H2c - func_correct_iseli_z(2*F0, F2, B2, mdata.Fs); Dawn@4: if (smoothwin~=0) Dawn@4: mdata.H2u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H2u); Dawn@4: mdata.H2c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H2c); Dawn@4: end Dawn@4: %mdata = rmfield(mdata, 'H2'); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H4')) Dawn@4: mdata.H4u = mdata.H4; % H4 is actually the uncorrected harmonic Dawn@4: mdata.H4c = mdata.H4u - func_correct_iseli_z(4*F0, F1, B1, mdata.Fs); Dawn@4: mdata.H4c = mdata.H4c - func_correct_iseli_z(4*F0, F2, B2, mdata.Fs); Dawn@4: if (smoothwin~=0) Dawn@4: mdata.H4u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H4u); Dawn@4: mdata.H4c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H4c); Dawn@4: end Dawn@4: %mdata = rmfield(mdata, 'H4'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % Ax Dawn@4: if (isfield(mdata, 'A1')) Dawn@4: mdata.A1u = mdata.A1; % A1 is actually the uncorrected amplitude Dawn@4: mdata.A1c = mdata.A1u - func_correct_iseli_z(F1, F1, B1, mdata.Fs); Dawn@4: mdata.A1c = mdata.A1c - func_correct_iseli_z(F1, F2, B3, mdata.Fs); Dawn@4: if (smoothwin~=0) Dawn@4: mdata.A1u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.A1u); Dawn@4: mdata.A1c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.A1c); Dawn@4: end Dawn@4: %mdata = rmfield(mdata, 'A1'); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'A2')) Dawn@4: mdata.A2u = mdata.A2; % A2 is acutally the uncorrected amplitude Dawn@4: mdata.A2c = mdata.A2u - func_correct_iseli_z(F2, F1, B1, mdata.Fs); Dawn@4: mdata.A2c = mdata.A2c - func_correct_iseli_z(F2, F2, B2, mdata.Fs); Dawn@4: if (smoothwin~=0) Dawn@4: mdata.A2u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.A2u); Dawn@4: mdata.A2c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.A2c); Dawn@4: end Dawn@4: %mdata = rmfield(mdata, 'A2'); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'A3')) Dawn@4: mdata.A3u = mdata.A3; % A3 is actually the uncorrected amplitude Dawn@4: mdata.A3c = mdata.A3u - func_correct_iseli_z(F3, F1, B1, mdata.Fs); Dawn@4: mdata.A3c = mdata.A3c - func_correct_iseli_z(F3, F2, B2, mdata.Fs); Dawn@4: mdata.A3c = mdata.A3c - func_correct_iseli_z(F3, F3, B3, mdata.Fs); Dawn@4: if (smoothwin~=0) Dawn@4: mdata.A3u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.A3u); Dawn@4: mdata.A3c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.A3c); Dawn@4: end Dawn@4: %mdata = rmfield(mdata, 'A3'); Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % the uncorrected combo parameters Dawn@4: if (isfield(mdata, 'H1') && isfield(mdata, 'H2')) Dawn@4: mdata.H1H2u = mdata.H1 - mdata.H2; Dawn@4: if (smoothwin ~= 0) Dawn@4: mdata.H1H2u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1H2u); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H2') && isfield(mdata, 'H4')) Dawn@4: mdata.H2H4u = mdata.H2 - mdata.H4; Dawn@4: if (smoothwin ~= 0) Dawn@4: mdata.H2H4u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H2H4u); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1') && isfield(mdata, 'A1')) Dawn@4: mdata.H1A1u = mdata.H1 - mdata.A1; Dawn@4: if (smoothwin ~= 0) Dawn@4: mdata.H1A1u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1A1u); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1') && isfield(mdata, 'A2')) Dawn@4: mdata.H1A2u = mdata.H1 - mdata.A2; Dawn@4: if (smoothwin ~= 0) Dawn@4: mdata.H1A2u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1A2u); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1') && isfield(mdata, 'A3')) Dawn@4: mdata.H1A3u = mdata.H1 - mdata.A3; Dawn@4: if (smoothwin ~= 0) Dawn@4: mdata.H1A3u = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1A3u); Dawn@4: end Dawn@4: end Dawn@4: Dawn@4: % this section is included for old VS compatibility, previously, the Dawn@4: % corrected versions of HxHx and HxAx were stored as HxHx and HxAx (i.e. Dawn@4: % without the "c" Dawn@4: if (isfield(mdata, 'H1H2')) Dawn@4: mdata.H1H2c = mdata.H1H2; Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H2H4')) Dawn@4: mdata.H2H4c = mdata.H2H4; Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1A1')) Dawn@4: mdata.H1A1c = mdata.H1A1; Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1A2')) Dawn@4: mdata.H1A2c = mdata.H1A2; Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1A3')) Dawn@4: mdata.H1A3c = mdata.H1A3; Dawn@4: end Dawn@4: Dawn@4: Dawn@4: % check if the others require smoothing Dawn@4: if (smoothwin ~= 0) Dawn@4: if (isfield(mdata, 'H1H2c')) Dawn@4: mdata.H1H2c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1H2c); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H2H4c')) Dawn@4: mdata.H2H4c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H2H4c); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1A1c')) Dawn@4: mdata.H1A1c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1A1c); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1A2c')) Dawn@4: mdata.H1A2c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1A2c); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'H1A3c')) Dawn@4: mdata.H1A3c = filter(ones(smoothwin,1)/smoothwin, 1, mdata.H1A3c); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'CPP')) Dawn@4: mdata.CPP = filter(ones(smoothwin,1)/smoothwin, 1, mdata.CPP); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'HNR05')) Dawn@4: mdata.HNR05 = filter(ones(smoothwin,1)/smoothwin, 1, mdata.HNR05); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'HNR15')) Dawn@4: mdata.HNR15 = filter(ones(smoothwin,1)/smoothwin, 1, mdata.HNR15); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'HNR25')) Dawn@4: mdata.HNR25 = filter(ones(smoothwin,1)/smoothwin, 1, mdata.HNR25); Dawn@4: end Dawn@4: Dawn@4: if (isfield(mdata, 'HNR35')) Dawn@4: mdata.HNR35 = filter(ones(smoothwin,1)/smoothwin, 1, mdata.HNR35); Dawn@4: end Dawn@4: Dawn@4: end