【语音处理】基于Matlab GUI音频信号分析仪【含Matlab源码 876期】

一、简介

基于Matlab GUI音频信号分析仪

二、源代码

function varargout = soundanalyze2(varargin)
% SOUNDANALYZE2 MATLAB code for soundanalyze2.fig
%      SOUNDANALYZE2, by itself, creates a new SOUNDANALYZE2 or raises the existing
%      singleton*.
%
%      H = SOUNDANALYZE2 returns the handle to a new SOUNDANALYZE2 or the handle to
%      the existing singleton*.
%
%      SOUNDANALYZE2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SOUNDANALYZE2.M with the given input arguments.
%
%      SOUNDANALYZE2('Property','Value',...) creates a new SOUNDANALYZE2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before soundanalyze2_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to soundanalyze2_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help soundanalyze2

% Last Modified by GUIDE v2.5 02-Jul-2014 16:27:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @soundanalyze2_OpeningFcn, ...
                   'gui_OutputFcn',  @soundanalyze2_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{
     1})
    gui_State.gui_Callback = str2func(varargin{
     1});
end

if nargout
    [varargout{
     1:nargout}] = gui_mainfcn(gui_State, varargin{
     :});
else
    gui_mainfcn(gui_State, varargin{
     :});
end
% End initialization code - DO NOT EDIT


% --- Executes just before soundanalyze2 is made visible.
function soundanalyze2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to soundanalyze2 (see VARARGIN)


% % **_OpeningFcn函数是GUI在打开时的执行的命令,此时GUI界面还没有显示出来
% % 将背景图像载入Matlab
% % 如果图像不在当前目录,必须使用完整路径
% backgroundImage = importdata('backgound.jpg');
% % 选择坐标系
% axes(handles.axes_backgound);
% % 将图片添加到坐标系中,于是就成了背景了
% image(backgroundImage);
% % 将坐标系的坐标轴标签去掉
% axis off
handles.addednoise = 0;


% Choose default command line output for soundanalyze2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes soundanalyze2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = soundanalyze2_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{
     1} = handles.output;




function recordtime_input_Callback(hObject, eventdata, handles)
% hObject    handle to recordtime_input (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of recordtime_input as text
%        str2double(get(hObject,'String')) returns contents of recordtime_input as a double


% --- Executes during object creation, after setting all properties.
function recordtime_input_CreateFcn(hObject, eventdata, handles)
% hObject    handle to recordtime_input (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in startrecord.
function startrecord_Callback(hObject, eventdata, handles)
% hObject    handle to startrecord (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
recordtime = str2double(get(handles.recordtime_input,'string'));
sample_frequency = str2double(get(handles.edit_sample_frequency,'string'));
handles.Fs = sample_frequency;
recObj = audiorecorder(sample_frequency,16,1);
info_msgbox = msgbox('正在录音...请稍等','状态');
recordblocking(recObj, recordtime);
close(info_msgbox)
handles.Sample = getaudiodata(recObj);
handles.Sample = handles.Sample';
handles.inputtype = 1;
guidata(hObject,handles);
plot(handles.axes_time_waveform,...
    0:1/sample_frequency:recordtime-1/sample_frequency,...
    handles.Sample);
title(handles.axes_time_waveform,'原信号的时域波形')
xlabel(handles.axes_time_waveform,'time(s)');
ylabel(handles.axes_time_waveform,'amplitude');
set(handles.pushbutton_timanyalze,'enable','on')
set(handles.pushbutton_frequencyanyalze,'enable','on')
set(handles.pushbutton_noise_gensig,'enable','on')
set(handles.pushbutton_play,'enable','on')


% --- Executes on key press with focus on radiobutton_soundcard and none of its controls.
function radiobutton_soundcard_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to radiobutton_soundcard (see GCBO)
% eventdata  structure with the following fields (see UICONTROL)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton_timanyalze.
function pushbutton_timanyalze_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_timanyalze (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
switch handles.inputtype
    case 1
        set(handles.period_value,'string',0)
        set(handles.frequency_value,'string',0)
        set(handles.amplitude_value,'string',0)
        set(handles.phase_position_value,'string',0)
    case 2
        set(handles.period_value,'string',0)
        set(handles.frequency_value,'string',0)
        set(handles.amplitude_value,'string',0)
        set(handles.phase_position_value,'string',0)
    case 3
        set(handles.period_value,'string',1/str2double(get(handles.edit_frequency,'string')))
        set(handles.frequency_value,'string',str2double(get(handles.edit_frequency,'string')))
        set(handles.amplitude_value,'string',str2double(get(handles.edit_amplitude,'string')))
        set(handles.phase_position_value,'string',str2double(get(handles.edit_phase_position,'string')))
end

set(handles.peak_value,'string',max(handles.Sample))
set(handles.mean_value,'string',mean(handles.Sample))
set(handles.mean_square_error_value,'string',std(handles.Sample))
set(handles.variance_value,'string',var(handles.Sample))



function period_value_Callback(hObject, eventdata, handles)
% hObject    handle to period_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of period_value as text
%        str2double(get(hObject,'String')) returns contents of period_value as a double


% --- Executes during object creation, after setting all properties.
function period_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to period_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function frequency_value_Callback(hObject, eventdata, handles)
% hObject    handle to frequency_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of frequency_value as text
%        str2double(get(hObject,'String')) returns contents of frequency_value as a double


% --- Executes during object creation, after setting all properties.
function frequency_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to frequency_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function amplitude_value_Callback(hObject, eventdata, handles)
% hObject    handle to amplitude_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of amplitude_value as text
%        str2double(get(hObject,'String')) returns contents of amplitude_value as a double


% --- Executes during object creation, after setting all properties.
function amplitude_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to amplitude_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function phase_position_value_Callback(hObject, eventdata, handles)
% hObject    handle to phase_position_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of phase_position_value as text
%        str2double(get(hObject,'String')) returns contents of phase_position_value as a double


% --- Executes during object creation, after setting all properties.
function phase_position_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to phase_position_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

三、运行结果

【语音处理】基于Matlab GUI音频信号分析仪【含Matlab源码 876期】_第1张图片

四、备注

版本:2014
完整代码或者代写添加QQ 1564658423

你可能感兴趣的:(matlab,语音处理)