www.gusucode.com > GUI界面,语音信号滤波程序,低通、带通、多带通、fft卷积滤波源码程序 > zjdwork/zjd_lvbo.m

    function varargout = zjd_lvbo(varargin)
% ZJD_LVBO M-file for zjd_lvbo.fig
%      ZJD_LVBO, by itself, creates a new ZJD_LVBO or raises the existing
%      singleton*.
%
%      H = ZJD_LVBO returns the handle to a new ZJD_LVBO or the handle to
%      the existing singleton*.
%
%      ZJD_LVBO('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in ZJD_LVBO.M with the given input arguments.
%
%      ZJD_LVBO('Property','Value',...) creates a new ZJD_LVBO or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before zjd_lvbo_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to zjd_lvbo_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 zjd_lvbo

% Last Modified by GUIDE v2.5 12-Apr-2009 16:24:35

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @zjd_lvbo_OpeningFcn, ...
                   'gui_OutputFcn',  @zjd_lvbo_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 zjd_lvbo is made visible.
function zjd_lvbo_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 zjd_lvbo (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = zjd_lvbo_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
[x,fs,bits]=wavread('input.wav'); 
x=x(:,2);
t=(0:length(x)-1)/fs;
subplot(221);plot(t,x);
subplot(223);
sigLength=length(x); 
Y = fft(x,sigLength); 
Pyy = Y.* conj(Y) / sigLength; 
halflength=floor(sigLength/2); 
f=2*(0:halflength)/sigLength; 
plot(f,Pyy(1:halflength+1));
set(findobj('tag','alltime2'), 'String',length(x)/fs);
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
[x,fs,bits]=wavread('input.wav'); 
x=x(:,2);
jieshu = handles.metricdata.jieshu;
N=jieshu;wc=0.3;
[b,a]=butter(N,wc);
y=filter(b,a,x);
wavwrite(y,fs,bits,'lvbo.wav');  
t=(0:length(y)-1)/fs;
subplot(222);plot(t,y);
sigLength=length(y); 
Y = fft(y,sigLength); 
Pyy = Y.* conj(Y) / sigLength; 
halflength=floor(sigLength/2); 
f=2*(0:halflength)/sigLength; 
subplot(224);plot(f,Pyy(1:halflength+1));

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


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
[x,fs,bits]=wavread('input.wav');
x=x(:,2);
low = handles.metricdata.low;
high= handles.metricdata.high;
wp=[low,high];
ws=[0.001,0.999];
[N,wc]=buttord(wp,ws,3,18);
[b,a]=butter(N,wc,'bandpass'); 
y=filter(b,a,x);
wavwrite(y,fs,bits,'lvbo.wav');
t=(0:length(y)-1)/fs;
subplot(222);plot(t,y);
sigLength=length(y); 
Y = fft(y,sigLength); 
Pyy = Y.* conj(Y) / sigLength; 
halflength=floor(sigLength/2); 
f=2*(0:halflength)/sigLength; 
subplot(224);plot(f,Pyy(1:halflength+1));

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


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
[filename,pathname]=uiputfile('*.wav','save as');
str=[pathname filename];
[x,fs,bits]=wavread('lvbo.wav'); 
wavwrite(x,fs,bits,str);



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


% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
[x,fs,bits]=wavread('input.wav');
x=x(:,1);
sound(x,fs,bits); 
time=length(x)/fs;
set(findobj('tag','alltime2'), 'String',time);
for i=0:0.1:time;
    set(findobj('tag','jindu2'),'Value',i/time);
    set(findobj('tag','xianshi2'),'String',fix(i));
    pause(0.1);
end;
% hObject    handle to pushbutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
close;


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



function jieshu_Callback(hObject, eventdata, handles)
jieshu = str2double(get(hObject, 'String'));
if isnan(jieshu)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

% Save the new density value
handles.metricdata.jieshu = jieshu;
guidata(hObject,handles)
% hObject    handle to jieshu (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 jieshu as text
%        str2double(get(hObject,'String')) returns contents of jieshu as a double


% --- Executes during object creation, after setting all properties.
function jieshu_CreateFcn(hObject, eventdata, handles)
% hObject    handle to jieshu (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 low_Callback(hObject, eventdata, handles)
low = str2double(get(hObject, 'String'));
if isnan(low)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

% Save the new density value
handles.metricdata.low = low;
guidata(hObject,handles)
% hObject    handle to low (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 low as text
%        str2double(get(hObject,'String')) returns contents of low as a double


% --- Executes during object creation, after setting all properties.
function low_CreateFcn(hObject, eventdata, handles)
% hObject    handle to low (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 high_Callback(hObject, eventdata, handles)
high = str2double(get(hObject, 'String'));
if isnan(high)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

% Save the new density value
handles.metricdata.high = high;
guidata(hObject,handles)
% hObject    handle to high (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 high as text
%        str2double(get(hObject,'String')) returns contents of high as a double


% --- Executes during object creation, after setting all properties.
function high_CreateFcn(hObject, eventdata, handles)
% hObject    handle to high (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
a = handles.metricdata.a;
b = handles.metricdata.b;
c = handles.metricdata.c;
d = handles.metricdata.d;
e = handles.metricdata.e;
f = handles.metricdata.f;
[x,fs,bits]=wavread('input.wav');
x=x(:,2);
f=[0 0.99*a ,a b,1.01*b 0.99*c, c d,1.01*d 0.99*e,e f,1.01*f 1];
a=[0 0 ,1 1, 0 0, 1 1,0 0,1 1,0 0];
bb = firpm(20,f,a,'h');   % Bandpass Hilbert
y = filter(bb,1,x);
wavwrite(y,fs,bits,'lvbo.wav');
t=(0:length(y)-1)/fs;
subplot(222);plot(t,y);
sigLength=length(y); 
Y = fft(y,sigLength); 
Pyy = Y.* conj(Y) / sigLength; 
halflength=floor(sigLength/2); 
f=2*(0:halflength)/sigLength; 
subplot(224);plot(f,Pyy(1:halflength+1));
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
lenN = handles.metricdata.lenN;
[x,fs,bits]=wavread('input.wav');
x=x(:,1);
h = ones(1,lenN)/lenN; 
y = conv(h,x);
wavwrite(y,fs,bits,'lvbo.wav');  
t=(0:length(y)-1)/fs;
subplot(222);plot(t,y);
sigLength=length(y); 
Y = fft(y,sigLength); 
Pyy = Y.* conj(Y) / sigLength; 
halflength=floor(sigLength/2); 
f=2*(0:halflength)/sigLength; 
subplot(224);plot(f,Pyy(1:halflength+1));
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
prompt={'请输入起始数字通带:','请输入截止数字通带:'};
name='多带通滤波';
numlines=1;
defaultanswer={'0.01','0.1'};
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=inputdlg(prompt,name,numlines,defaultanswer,options);
a=str2num(char(answer(1,1)));
b=str2num(char(answer(2,1)));
handles.metricdata.a = a;
handles.metricdata.b = b;
guidata(hObject,handles)
% hObject    handle to pushbutton8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
prompt={'请输入起始数字通带:','请输入截止数字通带:'};
name='多带通滤波';
numlines=1;
defaultanswer={'0.2','0.3'};
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=inputdlg(prompt,name,numlines,defaultanswer,options);
c=str2num(char(answer(1,1)));
d=str2num(char(answer(2,1)));
handles.metricdata.c = c;
handles.metricdata.d = d;
guidata(hObject,handles)
% hObject    handle to pushbutton9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
prompt={'请输入起始数字通带:','请输入截止数字通带:'};
name='多带通滤波';
numlines=1;
defaultanswer={'0.8','0.9'};
options.Resize='on';
options.WindowStyle='normal';
options.Interpreter='tex';
answer=inputdlg(prompt,name,numlines,defaultanswer,options);
e=str2num(char(answer(1,1)));
f=str2num(char(answer(2,1)));
handles.metricdata.e = e;
handles.metricdata.f = f;
guidata(hObject,handles)
% hObject    handle to pushbutton10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton11.
function pushbutton11_Callback(hObject, eventdata, handles)
[x,fs,bits]=wavread('lvbo.wav');
sound(x,fs,bits); 
time=length(x)/fs;
for i=0:0.1:time;
    set(findobj('tag','jindu2'),'Value',i/time);
    set(findobj('tag','xianshi2'),'String',fix(i));
    pause(0.1);
end;
% hObject    handle to pushbutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on slider movement.
function jindu2_Callback(hObject, eventdata, handles)
% hObject    handle to jindu2 (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,'Value') returns position of slider
%        get(hObject,'Min') and get(hObject,'Max') to determine range of slider


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

% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
end



function edit5_Callback(hObject, eventdata, handles)
lenN = str2double(get(hObject, 'String'));
if isnan(lenN)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end

% Save the new density value
handles.metricdata.lenN = lenN;
guidata(hObject,handles)
% hObject    handle to edit5 (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 edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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