load_file_select.m

来自「这是一个用于语音信号处理的工具箱」· M 代码 · 共 136 行

M
136
字号
%Callback program for the ASCII/MATLAB popup button in the choose mode window
%
%Author Karthik
%chooses between mat and ascii files for loading
% For ascii files the function basename is used to find out the filename and
%then this is used as the excitation source
%
%Please note that the only mat files that can be loaded are the ones that
%have been created using this program.  Other MAT files will not produce any
%error message, but the program simply ignores the file loaded and will
%create a new source file using default formats.
%
%A source file and a formant file (in .mat format) are loaded using this option
%
%Author : Karthik 1/98
%Filenames can be specified interactively
%Modified by D. G. Childers 2/25/98

clear excitation;

val = get(src_MATflag_popup,'Value');
if val == 1     %Load Matfile
   cwd=pwd;
   [fname pathname]=uigetfile('*.mat','Load source file');
   if fname ~= 0
      S=sprintf('cd %s',cwd);
      eval(S);
      S=sprintf('Load %s%s as source file',pathname,fname);
      disp(S);
      S=sprintf('load %s%s',pathname,fname);
      eval(S);
      S=sprintf('cd %s',cwd);
      eval(S);
      excitation = excitation';
   else
      disp('Please load a source file');
   end
elseif val == 2
   cwd=pwd;
   [fname pathname]=uigetfile('*.dat','Load source file');
   if fname ~= 0
      S=sprintf('cd %s',cwd);
      eval(S);
      S=sprintf('Load %s%s as source file',pathname,fname);
      disp(S);
      S=sprintf('load %s%s',pathname,fname);
      eval(S);
      S=sprintf('cd %s',cwd);
      eval(S);
      excitation = eval(basename(fname));
   else
      disp('Please load a source file');
   end
end
if val ~= 3
   excitation = 40* excitation./(max(abs(excitation)));
   %After the file is loaded, now analyze the file and find the required parameters
   [Pitch uvindicate gci] = Pitch_determine(excitation);
   Nframe = length(Pitch);
   Lens_array = 200*ones(Nframe,1);
   for i = 1:Nframe
      if Pitch(i) == 0
         uvindicate(i) = 0;
      end
   end
   Vgain = ones(Nframe,1);
   Ncof = zeros(Nframe,5);
   Ngain = zeros(Nframe,1);
   file_flag = 1;
end

if val == 3  %Load a coefficient file
   cwd=pwd;
   [fname pathname]=uigetfile('*.mat','Load source file');
   if fname ~= 0
      S=sprintf('cd %s',cwd);
      eval(S);
      S=sprintf('Load %s%s as source file',pathname,fname);
      disp(S);
      S=sprintf('load %s%s',pathname,fname);
      eval(S);
      S=sprintf('cd %s',cwd);
      eval(S);
      file_flag = 0;
      Nframe=length(Pitch);
      Lens_array = Pitch;
    
      % 1. calculate the LF model waveform for voiced exciation
      Tp=Lcof(1,2);
      Te=Lcof(1,3);
      Ta=Lcof(1,4);
      Tc=Lcof(1,5);
      Ee=Lcof(1,1);
      Lens=Pitch(1);
      temp_excitation = lfpuls(Tp,Te,Ta,Tc,Ee,Lens);
      gm=Vgain(1)-Ngain(1)-Ncof(1,1);
      if Vgain(1)==0
         amp=0;
      else
         amp=sqrt(gm*Lens/sum(temp_excitation.^2));
      end
      temp_excitation = amp*temp_excitation;
      % 2. calculate the noise exciation 
      Aspgain=Ncof(1,1);  % aspiration noise gain
      Amp1=Ncof(1,2);
      Offset=Ncof(1,3);
      Amp2=Ncof(1,4);
      Duration=Ncof(1,5);
      Fgain=Ngain(1);  % fricative noise gain
      temp_noise_excitation=nspuls(Amp1,Offset,Amp2,Duration,Lens,Aspgain,Fgain);
      
      % 3.The combined the excitation waveform (voiced+unvoiced)
      
      temp_excitation = temp_excitation + temp_noise_excitation;
      
      %Replicate this array to produce the excitation 
      for i = 1:Nframe
         start_point = (i*Lens) - (Lens-1);
         end_point = start_point + Lens - 1;
         excitation(start_point:end_point) = temp_excitation;
      end
   else
      disp('Please load a source file');
   end
end

if size(excitation,1) ~= 1
   excitation = excitation';
end






  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?