function varargout = eeg_filter(varargin)
% EEG_FILTER MATLAB code for eeg_filter.fig
% EEG_FILTER, by itself, creates a new EEG_FILTER or raises the existing
% singleton*.
%
% H = EEG_FILTER returns the handle to a new EEG_FILTER or the handle to
% the existing singleton*.
%
% EEG_FILTER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EEG_FILTER.M with the given input arguments.
%
% EEG_FILTER('Property','Value',...) creates a new EEG_FILTER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before eeg_filter_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to eeg_filter_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 eeg_filter
% Last Modified by GUIDE v2.5 11-Jan-2019 11:21:01
% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @eeg_filter_OpeningFcn, ...
'gui_OutputFcn', @eeg_filter_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 eeg_filter is made visible.
function eeg_filter_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 eeg_filter (see VARARGIN)
% Choose default command line output for eeg_filter
handles.output = hObject;
% t=msgbox('欢迎进入','欢迎界面');
% pause(2);
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes eeg_filter wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = eeg_filter_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 eeg_timedisplay. 脑电信号的时域显示
function eeg_timedisplay_Callback(hObject, eventdata, handles)
% hObject handle to eeg_timedisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% [FileName,PathName]=uigetfile('*.txt','Slect the Data file');
% file=fullfile(PathName,FileName);
% handles.S1=load(file);%怎样把文件用到频域中
%axes(handles.axes);
global x;global y;global S1;
S1='E:\医学信号处理课程设计\normal1.txt';
[x,y]=eeg_load(S1);
plot(handles.axes1,x,y,'b');
set(handles.axes1,'XGrid','on','YGrid','on');
xlabel(handles.axes1,'时间/s');
ylabel(handles.axes1,'幅值/uV');
title(handles.axes1,'脑电信号时域图');
cla(handles.axes2);cla(handles.axes3);cla(handles.axes4);
cla(handles.axes5);cla(handles.axes6);cla(handles.before_angle);
cla(handles.filter_angle);cla(handles.after_angle);cla(handles.axes15);
guidata(hObject,handles);%更新数据就可以将这个函数中的变量用到另一个函数中(参数传递)
% --- Executes on button press in filter_model. 滤波器模型
function filter_model_Callback(hObject, eventdata, handles)
% hObject handle to filter_model (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global S1;global fk;global Y1r;
[fk,Y1r,A1r]=eeg_fft(S1);[x,y]=eeg_load(S1);
if get(handles.rect_win,'value')
%option=1;
fs=500;wp=0.232*pi;ws=0.248*pi;
[H1,h1,w1]=rectfilter(wp,ws,fs);
plot(handles.axes6,w1,20*log10(abs(h1)),'g');%频域
plot(handles.axes3,w1,ifft(h1),'g');%时域 因为N=18所以滤波器只有18个点其他为0
plot(handles.filter_angle,w1,angle(h1),'g');%相位
%cla(handles.axes4);
set(handles.axes3,'XGrid','on','YGrid','on');
set(handles.axes6,'XGrid','on','YGrid','on');
set(handles.filter_angle,'XGrid','on','YGrid','on');
xlabel(handles.axes3,'时间');xlabel(handles.axes6,'频率/Hz');xlabel(handles.filter_angle,'相位/Hz');
ylabel(handles.axes3,'幅值/uV');ylabel(handles.axes6,'20log(H)/dB');
set(handles.axes6,'XLim',[0,125]);
set(handles.axes3,'XLim',[0,60]);
set(handles.filter_angle,'XLim',[0,125]);
elseif get(handles.butterworth,'value')
%option=2;
wp0=[4 8];ws0=[1 11]; Rp=1; Rs=18;
[Hb,wb]=butterfilter(wp0,ws0,Rp,Rs);
x1=[1,zeros(1,length(wb)-1)];%单位冲击响应
h3=filter(Hb,1,x1);%求出时域图
plot(handles.axes3,wb,h3,'g');%时域 ?????
set(handles.axes3,'XLim',[0,125]);
plot(handles.axes6,wb,20*log10(abs(Hb)),'g');%频域20*log10
set(handles.axes6,'XLim',[0,125]);
plot(handles.filter_angle,wb,angle(Hb),'g');%相位
guidata(hObject,handles);
set(handles.axes3,'XGrid','on','YGrid','on');
set(handles.axes6,'XGrid','on','YGrid','on');
set(handles.filter_angle,'XGrid','on','YGrid','on');
xlabel(handles.axes3,'时间');xlabel(handles.axes6,'频率/Hz');xlabel(handles.filter_angle,'相位/Hz');
ylabel(handles.axes3,'幅值/uV');ylabel(handles.axes6,'20log(H)/dB');
%cla(handles.axes4);
end
cla(handles.axes15);
% --- Executes on button press in eeg_fftdisplay.脑电信号频域图
function eeg_fftdisplay_Callback(hObject, eventdata, handles)
% hObject handle to eeg_fftdisplay (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fk;global Y1r;global A1r;global S1;
set(handles.axes2,'visible','on');
[fk,Y1r,A1r]=eeg_fft(S1);%频谱
plot(handles.axes2,fk,abs(Y1r),'r');
plot(handles.before_angle,fk,A1r,'r');
set(handles.axes2,'XGrid','on','YGrid','on');set(handles.before_angle,'XGrid','on','YGrid','on');
set(handles.axes2,'XLim',[0,125],'YLim',[0,70000]);
set(handles.before_angle,'XLim',[0,125],'YLim',[-4,4]);
xlabel(handles.axes2,'频率/Hz');xlabel(handles.before_angle,'相位/Hz');
cla(handles.axes15);
% --- Executes on button press in filtering.滤波
function filtering_Callback(hObject, eventdata, handles)
% hObject handle to filtering (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fk;global Y1r;global A1r;global S1;
global x;global y;
if get(handles.rect_win,'value')
fs=500;
wp=0.232*pi;ws=0.248*pi;
[H1,h1,w]=rectfilter(wp,ws,fs);%矩形窗滤波器
global sf;global Fsf;
sf=filter(H1,1,y);%时域
Fsf=fft(sf);%频域
plot(handles.axes5,x,sf,'b');%显示时域
plot(handles.axes4,fk,abs(Fsf),'b');%显示频谱
plot(handles.after_angle,fk,angle(Fsf),'r');%显示相位
set(handles.axes4,'XGrid','on','YGrid','on'); set(handles.axes5,'XGrid','on','YGrid','on');
set(handles.after_angle,'XGrid','on','YGrid','on');
xlabel(handles.axes5,'时间/s');xlabel(handles.axes4,'频率/Hz');xlabel(handles.after_angle,'相位/Hz');
ylabel(handles.axes5,'幅值/uV');
set(handles.axes4,'XLim',[0,125]); set(handles.axes5,'XLim',[0,60]); set(handles.after_angle,'XLim',[0,125]);
elseif get(handles.butterworth,'value')
wp0=[4 8];ws0=[1 11];Rp=1; Rs=18;
[Hb,wb,bz,az]=
评论1
最新资源