function varargout = work3(varargin)
% WORK3 M-file for work3.fig
% WORK3, by itself, creates a new WORK3 or raises the existing
% singleton*.
%
% H = WORK3 returns the handle to a new WORK3 or the handle to
% the existing singleton*.
%
% WORK3('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WORK3.M with the given input arguments.
%
% WORK3('Property','Value',...) creates a new WORK3 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before work3_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to work3_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 work3
% Last Modified by GUIDE v2.5 26-Jun-2007 20:51:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @work3_OpeningFcn, ...
'gui_OutputFcn', @work3_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(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 work3 is made visible.
function work3_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 work3 (see VARARGIN)
% Choose default command line output for work3
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes work3 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
setappdata(0 ,'hMainGui' ,gcf);
hAxes1=findobj(gcf,'type','axes','Tag','axes1');
hAxes2=findobj(gcf,'type','axes','Tag','axes2');
hAxes3=findobj(gcf,'type','axes','Tag','axes3');
hAxes4=findobj(gcf,'type','axes','Tag','axes4');
hAxes5=findobj(gcf,'type','axes','Tag','axes5');
hAxes6=findobj(gcf,'type','axes','Tag','axes6');
setappdata(gcf,'hAxes1',hAxes1);
setappdata(gcf,'hAxes2',hAxes2);
setappdata(gcf,'hAxes3',hAxes3);
setappdata(gcf,'hAxes4',hAxes4);
setappdata(gcf,'hAxes5',hAxes5);
setappdata(gcf,'hAxes6',hAxes6);
% --- Outputs from this function are returned to the command line.
function varargout = work3_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;
% --- Executes on button press in pushbutton_open.
function pushbutton_open_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hMainGui = getappdata(0,'hMainGui');
filename=uigetfile('*.wav');
setappdata(hMainGui,'filename',filename);
plotwav;
function plotwav
hMainGui = getappdata(0,'hMainGui');
filename = getappdata(hMainGui,'filename');
hAxes1 = getappdata(hMainGui,'hAxes1');
hAxes2 = getappdata(hMainGui,'hAxes2');
hAxes3 = getappdata(hMainGui,'hAxes3');
[data,fs]=wavread(filename);
setappdata(hMainGui,'data',data);
setappdata(hMainGui,'fs',fs);
%画时域图形
axes(hAxes1);
samp_len = length(data)/fs;
delta_t = 1/fs;
t = 0:delta_t:(samp_len-delta_t);
setappdata(hMainGui,'t',t);
plot(t,data), xlabel('Time [sec]'), ylabel('Amplitude'),title('原信号时域波形图');
axis([0 t(length(data)-1) -1 1 ]);
%画频域图形
%spec = 'wideband';
spec = 'narrowband';
wideband_time = 4e-3;
narrowband_time = 25e-3;
%window_width = 200; % window width for FFT
%step_size = 100; % window movement
fft_pts = 2048; % # of points in the FFT
% Sampling rate dependent window width
if strcmp(spec,'narrowband')
window_width = round(fs*narrowband_time);
step_size = round(window_width/8);
elseif strcmp(spec,'wideband')
window_width = round(fs*wideband_time);
step_size = round(window_width/2);
end
% calculates the spectrum of the voice signal
X = specgram(data,fft_pts,1,hamming(window_width),window_width-step_size);
X = abs(X);
% frequency axis vector
y_len = size(X,1); % num of rows
f = [0:y_len-1]*fs/y_len/2;
f = f/1000 ;% kHz scale
setappdata(hMainGui,'f',f);
% time axis vector
x_len = size(X,2); % num of columns
%t = [0.5:1:x_len+0.5]*step/fs;
%t = [(ww-1)/2-0.5:step:step*x_len+(ww-1)/2-1.5]/fs;
t = [(window_width-1)/2:step_size:(x_len-1)*step_size+(window_width-1)/2]/fs;
% display the signal
axes(hAxes2);
log_data = -log10(X+0.0001);
imagesc(t,f,log_data);
xlabel('Time [sec]'), ylabel('Frequency [kHz]')
title('原信号语音频谱图')
%原信号的幅频响应
data_fft = fft(data,1025);
%data_fftPow = data_fft.*conj(data_fft)/1025;
data_fft = abs(data_fft) ;
axes(hAxes3);
plot(f,data_fft);
title('原信号的幅频响应');
xlabel('Frequency [kHz]'),ylabel('Amplitude')
axis([-4 4 0 100])
% --- Executes on button press in pushbutton_play.
function pushbutton_play_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton_play (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hMainGui = getappdata(0,'hMainGui');
data = getappdata(hMainGui,'data');
fs = getappdata(hMainGui,'fs');
data = 0.99*data/max(abs(data));
data_1 = data;
if length(data_1) ~= 0
sound(data_1,fs)
end
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
wp=str2double(get(hObject,'String'))*1000;
hMainGui = getappdata(0,'hMainGui');
setappdata(hMainGui,'wp',wp);
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% event