⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lpc_project.m

📁 LPC vocoder LPC vocoder with several option Graphical user interface Also included several .wav f
💻 M
📖 第 1 页 / 共 2 页
字号:
function LPC_Project

clear all;
close all;
clc;

global f;
global t_frame;
global curFrame;
global spectra;
global temporal;
global NFRAMES;
global state1;
global state2;
global state3;
global state4;
global Y;
global FS;
global Y_HAT;

state1=1;
state2=1;
state3=1;
state4=1;

move=175;

% Create and then hide the GUI as it is being constructed.
f = figure('Visible','off','Position',[360,500,450*1.5*1.2,285*1.5*1.4],...
    'MenuBar','none','NumberTitle','off');

% Construct the components
inputs = uipanel('Position',[0 0 .2 1]);
    Sig1 = uicontrol('parent',inputs,'Style','text',...
        'String','Ben Ross','Position',[2 395+move 55 25],...
        'FontWeight','bold');
    Sig2 = uicontrol('parent',inputs,'Style','text',...
        'String','Bill Taft','Position',[2 380+move 43 25],...
        'FontWeight','bold');

    runbutton = uicontrol('parent',inputs,'Style','pushButton',...
        'String','Run Program','Position',[42 353+move 75 25],...
        'Callback',{@runbutton_Callback});

    S_File = uicontrol('parent',inputs,'Style','edit',...
        'String','s5.wav','Position',[75 305+move 70 25],...
        'BackgroundColor','white',...
        'Callback',{@S_File_Callback});
    Label1 = uicontrol('parent',inputs,'Style','text',...
        'String','Speech File:','Position',[2 300+move 70 25]);
    
    P_File = uicontrol('parent',inputs,'Style','edit',...
        'String','pp5.mat','Position',[75 265+move 70 25],...
        'BackgroundColor','white',...
        'Callback',{@P_File_Callback});
    Label2 = uicontrol('parent',inputs,'Style','text',...
        'String','Pitch File:','Position',[2 260+move 70 25]);
    
    measure = uicontrol('parent',inputs,'Style','edit',...
        'String','10','Position',[75 225+move 70 25],...
        'BackgroundColor','white',...
        'Callback',{@measure_Callback});
    Label3 = uicontrol('parent',inputs,'Style','text',...
        'String','Pitch Measure (ms):','Position',[2 225+move 70 25]);
    
    fd = uicontrol('parent',inputs,'Style','edit',...
        'String','40','Position',[75 185+move 70 25],...
        'BackgroundColor','white',...
        'Callback',{@fd_Callback});
    Label4 = uicontrol('parent',inputs,'Style','text',...
        'String','Frame Duration (ms):','Position',[2 185+move 70 25]);
    
    fo = uicontrol('parent',inputs,'Style','edit',...
        'String','75','Position',[75 145+move 70 25],...
        'BackgroundColor','white',...
        'Callback',{@fo_Callback});
    Label5 = uicontrol('parent',inputs,'Style','text',...
        'String','Frame Overlap (%):','Position',[2 145+move 70 25]);

    winType = uicontrol('Style','popupmenu',...
          'String',{'Hamming','Triangular','Rectangular',...
          'Hanning','Blackman'},'BackgroundColor','white',...
          'Position',[75,105+move,80,25],...
          'Callback',{@winType_Callback});
    Label6 = uicontrol('parent',inputs,'Style','text',...
        'String','Window:','Position',[2 100+move 70 25]);

    fftSize = uicontrol('parent',inputs,'Style','edit',...
        'String','1024','Position',[75 65+move 70 25],...
        'BackgroundColor','white',...
        'Callback',{@fftSize_Callback});
    Label7 = uicontrol('parent',inputs,'Style','text',...
        'String','FFT Size:','Position',[2 60+move 70 25]);
    
    order = uicontrol('parent',inputs,'Style','edit',...
        'String','12','Position',[75 25+move 70 25],...
        'BackgroundColor','white',...
        'Callback',{@order_Callback});
    Label8 = uicontrol('parent',inputs,'Style','text',...
        'String','LPC Order:','Position',[2 20+move 70 25]);
    
    original = uicontrol('parent',inputs,'Style','checkbox',...
        'String','Original Signal','Position',[10 -55+move 100 25],...
        'backgroundcolor','r','value',1,'Callback',{@original_Callback});
    originalbutton = uicontrol('parent',inputs,'Style','pushButton',...
        'String','Play','Position',[112 -55+move 45 25],...
        'Callback',{@originalbutton_Callback});
    
    LPC_SIG = uicontrol('parent',inputs,'Style','checkbox',...
        'String','LPC Signal','Position',[10 -80+move 100 25],...
        'backgroundcolor','b','value',1,'Callback',{@LPC_Callback});
% % %     LPC_SIGbutton = uicontrol('parent',inputs,'Style','pushButton',...
% % %         'String','Play','Position',[112 -80+move 45 25],...
% % %         'Callback',{@LPC_SIGbutton_Callback});    

    syn_sig = uicontrol('parent',inputs,'Style','checkbox',...
        'String','Synthetic Signal','Position',[10 -105+move 100 25],...
        'backgroundcolor','g','value',1,'Callback',{@syn_Callback});
    syn_sigbutton = uicontrol('parent',inputs,'Style','pushButton',...
        'String','Play','Position',[112 -105+move 45 25],...
        'Callback',{@syn_sigbutton_Callback});

    excit_sig = uicontrol('parent',inputs,'Style','checkbox',...
        'String','Excitation Signal','Position',[10 -130+move 100 25],...
        'backgroundcolor','m','value',1,'Callback',{@excit_Callback});
% % %     excit_sigbutton = uicontrol('parent',inputs,'Style','pushButton',...
% % %         'String','Play','Position',[112 -130+move 45 25],...
% % %         'Callback',{@excit_sigbutton_Callback});    
    
p1 = uipanel('Position',[0.2 0.45 0.8 .55]);
    h = axes('parent',p1,'Position',[0.11 0.11 0.84 0.79],...
       'GridLineStyle','--');
   
p2 = uipanel('Position',[0.2 0.4 0.8 .05]);
    start = uicontrol('parent',p2,'Style','pushbutton','String','<<',...
           'Callback',{@startbutton_Callback},...
           'Position',[10+110 2 70 25]);
    back = uicontrol('parent',p2,'Style','pushbutton','String','<',...
           'Callback',{@backbutton_Callback},...
           'Position',[90+110 2 70 25]);
    forward = uicontrol('parent',p2,'Style','pushbutton','String','>',...
           'Callback',{@forwardbutton_Callback},...
           'Position',[260+110 2 70 25]);
    finish = uicontrol('parent',p2,'Style','pushbutton',...
           'String','>>',...
           'Callback',{@finishbutton_Callback},...
           'Position',[340+110 2 70 25]);
       
p3 = uipanel('Position',[0.2 0 0.8 0.4]);
    ha = axes('parent',p3,'Position',[0.11 0.21 0.84 0.69],...
       'GridLineStyle','--');
       
% Initialize the GUI.
set([f,p1,p2,p3],'Units','normalized');

% Assign the GUI a name to appear in the window title.
set(f,'Name','LPC Vocoder Project')

% Move the GUI to the center of the screen.
movegui(f,'center')

% Make the GUI visible.
set(f,'Visible','on');


function runbutton_Callback(source,eventdata)
clear global f;
clear global t_frame;
clear global curFrame;
clear global spectra;
clear global temporal;
clear global NFRAMES;
clear Y;
clear FS;
tic
    %load speech file and determine sampling rate
    [Y,FS] = loadwav(S_File_Callback(source,eventdata));
    
    %load pitch file and determine asynchrnonous pitch measurement rate
    PITCH=load(P_File_Callback(source,eventdata));
    if P_File_Callback(source,eventdata)=='pp6.mat';
        for i=1:size(PITCH.pp6,1)
            PP(i,1)=PITCH.pp6(i);
        end
    end
    if P_File_Callback(source,eventdata)=='pp5.mat';
        for i=1:size(PITCH.pp5,1)
            PP(i,1)=PITCH.pp5(i);
        end
    end
    if P_File_Callback(source,eventdata)=='pp4.mat';
        for i=1:size(PITCH.pp4,1)
            PP(i,1)=PITCH.pp4(i);
        end
    end
    if P_File_Callback(source,eventdata)=='pp3.mat';
        for i=1:size(PITCH.pp3p,1)
            PP(i,1)=PITCH.pp3p(i);
        end
    end
    if P_File_Callback(source,eventdata)=='pp2.mat';
        for i=1:size(PITCH.pp2,1)
            PP(i,1)=PITCH.pp2(i);
        end
    end
    if P_File_Callback(source,eventdata)=='pp1.mat';
        for i=1:size(PITCH.pp1,1)
            PP(i,1)=PITCH.pp1(i);
        end
    end    
    asynch_m=measure_Callback(source,eventdata)*(1/1000)*FS;
    
    %separate speech into frames
    frame_size=round(fd_Callback(source,eventdata)*(1/1000)*FS);
    SHIFT=round(frame_size-(frame_size*fo_Callback(source,...
        eventdata)/100));
    [DATA,NFRAMES]=frames(Y,SHIFT,frame_size);
    
    %save('X.mat','DATA');
    
    %determine window type and weight frames by window
    [STR,VAL]=winType_Callback(source,eventdata);
    switch STR{VAL};
        case 'Hamming' 
            w = hamming(frame_size);
            w_hat=hamming(fftSize_Callback(source,eventdata));
        case 'Triangular' 
            w = triang(frame_size);
            w_hat=triang(fftSize_Callback(source,eventdata));
        case 'Rectangular' 
            w = rectwin(frame_size);
            w_hat=rectwin(fftSize_Callback(source,eventdata));
        case 'Hanning' 
            w = hann(frame_size);
            w_hat=hann(fftSize_Callback(source,eventdata));
        case 'Blackman' 
            w = blackman(frame_size);
            w_hat=blackman(fftSize_Callback(source,eventdata));
    end
    WINDOW_DATA=zeros(frame_size,NFRAMES);
    for j=1:NFRAMES
        WINDOW_DATA(:,j)=DATA(:,j).*w;
    end
    
    %save('wX.mat','WINDOW_DATA');
    
    %Perform autocorrelation method on each frame. Determine alphas and
    %gains for each frame of speech.
    Rn=zeros(order_Callback(source,eventdata)+1,NFRAMES);
    alpha=zeros(order_Callback(source,eventdata),NFRAMES);
    G=zeros(1,NFRAMES);
    for i=1:NFRAMES

⌨️ 快捷键说明

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