This document contains code for analyzing speech signals in Matlab. It includes functions for:
1) Opening a GUI that allows users to select a wav file for analysis or start recording audio.
2) Plotting the speech signal and performing frame-based analysis including calculating energy and magnitude over time using a hamming window.
3) Allowing the user to set window length and overlap for analysis through editable text boxes.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
125 views
Code Matlab
This document contains code for analyzing speech signals in Matlab. It includes functions for:
1) Opening a GUI that allows users to select a wav file for analysis or start recording audio.
2) Plotting the speech signal and performing frame-based analysis including calculating energy and magnitude over time using a hamming window.
3) Allowing the user to set window length and overlap for analysis through editable text boxes.
if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end
function bainop11_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = bainop11_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) [FileName,PathName] = uigetfile({ ... '*.wav', 'Wav (*.wav)'}, ... 'Select Wave file'); if isequal(FileName,0); return; end % Mo mot file am thanh dang .wav tu may tinh [y,Fs]=wavread([PathName FileName]);% y la tin hieu am thanh, Fs la tan so lay mau t = [0:length(y)-1]/Fs; subplot(1,1,1); plot(t, y);%ve do thi tieng hieu tieng noi title('Phan Tich Tieng Noi'); xlabel('Time (sec)');% chu thich truc hoanh hold on; %Khai Bao Ham cua so val = get(handles.edit1,'String'); winLen = str2num(val); % Do dai cua so, winOverlap = winLen -1; % Chieu dai cac cua so de len nhau wHamm = hamming(winLen);% dung cua so Hamming %Tinh Nang Luong Trung Binh sigFramed = buffer(y, winLen, winOverlap, 'nodelay'); sigWindowed = diag(sparse(wHamm)) * sigFramed; energyST = sum(sigWindowed.^2,1); delay = (winLen - 1)/2; plot(t(delay+1:end - delay), energyST, 'r'); %Tinh Do Lon Bien Do Trung Binh x = abs(y); sigFramed = buffer(x, winLen, winOverlap, 'nodelay'); sigWindowed = diag(sparse(wHamm)) * sigFramed; magnitudeAv = sum(sigWindowed,1); plot(t(delay+1:end - delay), magnitudeAv, 'g'); legend({'Speech','Nang Luong','Bien Do'});
function edit1_Callback(hObject, eventdata, handles)
function edit1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function edit2_Callback(hObject, eventdata, handles)
function edit2_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function edit3_Callback(hObject, eventdata, handles)
function edit3_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end
function pushbutton4_Callback(hObject, eventdata, handles)% Nhan nut Ghi Am
Fs = get(handles.edit2,'String'); Fs = str2num(Fs); T = get(handles.edit3,'String'); T = str2num(T); y = wavrecord(T*Fs,Fs,'double'); t = [0:length(y)-1]/Fs; subplot(1,1,1); plot(t, y); title('Phan Tich Tieng Noi'); xlabel('Time (sec)'); hold on; %Khai Bao Ham cua so val = get(handles.edit1,'String'); winLen = str2num(val); % Do dai cua so, winOverlap = winLen -1; wHamm = hamming(winLen); wRect = rectwin(winLen); %Tinh Nang Luong Trung Binh sigFramed = buffer(y, winLen, winOverlap, 'nodelay'); sigWindowed = diag(sparse(wHamm)) * sigFramed; energyST = sum(sigWindowed.^2,1); delay = (winLen - 1)/2; plot(t(delay+1:end - delay), energyST, 'r'); %Tinh Do Lon Bien Do Trung Binh x = abs(y); sigFramed = buffer(x, winLen, winOverlap, 'nodelay'); sigWindowed = diag(sparse(wHamm)) * sigFramed; magnitudeAv = sum(sigWindowed,1); plot(t(delay+1:end - delay), magnitudeAv, 'g'); legend({'Speech','Nang Luong','Bien Do'}); hold off;