⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wavelet_thresh_traditional.m

📁 一个用于小波去噪的matlab程序
💻 M
字号:
function varargout = wavelet_thresh_traditional(varargin)% WAVELET_THRESH_TRADITIONAL M-file for wavelet_thresh_traditional.fig%      WAVELET_THRESH_TRADITIONAL, by itself, creates a new WAVELET_THRESH_TRADITIONAL or raises the existing%      singleton*.%%      H = WAVELET_THRESH_TRADITIONAL returns the handle to a new WAVELET_THRESH_TRADITIONAL or the handle to%      the existing singleton*.%%      WAVELET_THRESH_TRADITIONAL('CALLBACK',hObject,eventData,handles,...) calls the local%      function named CALLBACK in WAVELET_THRESH_TRADITIONAL.M with the given input arguments.%%      WAVELET_THRESH_TRADITIONAL('Property','Value',...) creates a new WAVELET_THRESH_TRADITIONAL or raises the%      existing singleton*.  Starting from the left, property value pairs are%      applied to the GUI before wavelet_thresh_traditional_OpeningFcn gets called.  An%      unrecognized property name or invalid value makes property application%      stop.  All inputs are passed to wavelet_thresh_traditional_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 wavelet_thresh_traditional% Last Modified by GUIDE v2.5 26-Mar-2009 10:56:13% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name',       mfilename, ...                   'gui_Singleton',  gui_Singleton, ...                   'gui_OpeningFcn', @wavelet_thresh_traditional_OpeningFcn, ...                   'gui_OutputFcn',  @wavelet_thresh_traditional_OutputFcn, ...                   'gui_LayoutFcn',  [] , ...                   'gui_Callback',   []);if nargin && ischar(varargin{1})    gui_State.gui_Callback = str2func(varargin{1});endif 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 wavelet_thresh_traditional is made visible.function wavelet_thresh_traditional_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject    handle to axes_signal% 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 wavelet_thresh_traditional (see VARARGIN)% Choose default command line output for wavelet_thresh_traditional%初始化参数handles.i=1;handles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT makes wavelet_thresh_traditional wait for user response (see UIRESUME)% uiwait(handles.figure1);% --- Outputs from this function are returned to the command line.function varargout = wavelet_thresh_traditional_OutputFcn(hObject, eventdata, handles) % varargout  cell array for returning output args (see VARARGOUT);% hObject    handle to axes_signal% 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 structurevarargout{1} = handles.output;% --- Executes on button press in update.function update_Callback(hObject, eventdata, handles)% hObject    handle to update (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%获取小波函数wnamewn = get(handles.wname,'string');t = get(handles.wname,'value');w = wn(t);hj = findobj(gcf,'tag','j');if ~isempty(hj)    switch handles.signtag        case {1}            w1 = get(hj,'string');        case {2}            wn = get(hj,'string');            t = get(hj,'value');            w1 = wn(t);    end    w=strcat(w,w1);endw = deblank(w);w = w{1};%获取分解层次n = (get(handles.n,'value'));%获取阈值选择规则wn = get(handles.tptr,'string');t = get(handles.tptr,'value');tptr = wn(t);tptr = tptr{1};%获取阈值方式s = (get(handles.sorh,'value'));switch s    case 1        sorh = 's';    case 2        sorh = 'h';end%获取是否调整的信息wn = get(handles.scal,'string');t = get(handles.scal,'value');scal = wn(t);scal = scal{1};%信号去噪及显示xd = wden(handles.sig,tptr,sorh,scal,n,w);axes(handles.axes_denoising);plot(xd);title('去噪后的信号');xlabel('时间t');ylabel('信号幅度XD');%信噪比和相关系数计算cor=Cor(handles.sig,xd);snr=Snr(handles.sig,xd);%输出控制handles.data(handles.i,:) = {w,n,tptr,sorh,scal,snr,cor};colnames = {'小波函数', '分解层次', '阈值选取规则','阈值方式','调整信息','信噪比','相关系数'};t = uitable(gcf, 'Data', handles.data, 'ColumnName', colnames, ...             'Position', [790 150 310 200]);handles.i = handles.i+1;guidata(hObject, handles);% --- Executes on button press in open.function open_Callback(hObject, eventdata, handles)% hObject    handle to open (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)%打开文件[fname,dirpath,findex] = uigetfile ({'*.m;*.mat','Signal(*.m,*.mat)'},'打开文件');filename=[dirpath fname];%将struct变量转换为矩阵sig1 = struct2cell(load(filename));handles.sig = sig1{1};%在第一个axes中显示原始图像axes(handles.axes_signal);plot(handles.sig);title('含有噪声的原始信号');xlabel('时间t');ylabel('信号幅度X');%更新数据guidata(hObject,handles);% --- Executes on selection change in scal.function scal_Callback(hObject, eventdata, handles)% hObject    handle to scal (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns scal contents as cell array%        contents{get(hObject,'Value')} returns selected item from scal% --- Executes during object creation, after setting all properties.function scal_CreateFcn(hObject, eventdata, handles)% hObject    handle to scal (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu 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 selection change in sorh.function sorh_Callback(hObject, eventdata, handles)% hObject    handle to sorh (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns sorh contents as cell array%        contents{get(hObject,'Value')} returns selected item from sorh% --- Executes during object creation, after setting all properties.function sorh_CreateFcn(hObject, eventdata, handles)% hObject    handle to sorh (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu 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 selection change in tptr.function tptr_Callback(hObject, eventdata, handles)% hObject    handle to tptr (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns tptr contents as cell array%        contents{get(hObject,'Value')} returns selected item from tptr% --- Executes during object creation, after setting all properties.function tptr_CreateFcn(hObject, eventdata, handles)% hObject    handle to tptr (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu 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 selection change in n.function n_Callback(hObject, eventdata, handles)% hObject    handle to n (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns n contents as cell array%        contents{get(hObject,'Value')} returns selected item from n% --- Executes during object creation, after setting all properties.function n_CreateFcn(hObject, eventdata, handles)% hObject    handle to n (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu 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 selection change in wname.function wname_Callback(hObject, eventdata, handles)% hObject    handle to wname (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)% Hints: contents = get(hObject,'String') returns wname contents as cell array%        contents{get(hObject,'Value')} returns selected item from wname%去除上次产生的动态控件hj = findobj(gcf,'tag','j');if ~isempty(hj)delete(findobj(gcf,'tag','j'));endhj=findobj(gcf,'tag','i');if ~isempty(hj)delete(findobj(gcf,'tag','i'));endvalue=get(handles.wname,'value');switch value    case {1,7}            case {2,3,4}        uicontrol(gcf,'style','text',...                  'fontsize',10.0,'position',[950.0,600,100,20],...                  'string','输入正整数:','tag','i');        uicontrol(gcf,'style','edit',...                      'fontsize',10.0,...                      'position',[950.0,572,100,25],...                       'backgroundcolor',[1.0,1.0,1.0],...                      'string','5','tag','j');         handles.signtag = 1;    case {5,6}        uicontrol(gcf,'style','text',...                  'fontsize',10.0,...                  'position',[950.0,600,100,20],...                  'string','选择小波阶次:','tag','i');        uicontrol(gcf,'style','popupmenu',...                  'fontsize',10.0,...                  'position',[950.0,578,100,20],...                  'string',{'1.1','1.3','1.5','2.6','2.4','2.6','2.8','3.1','3.3','3.5','3.7','3.9','4.4','5.5','6.8'},...                  'backgroundcolor',[1.0,1.0,1.0],...                  'tag','j');         handles.signtag = 2;endguidata(hObject,handles);% --- Executes during object creation, after setting all properties.function wname_CreateFcn(hObject, eventdata, handles)% hObject    handle to wname (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu 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 slider movement.function slider1_Callback(hObject, eventdata, handles)% hObject    handle to slider1 (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 slider1_CreateFcn(hObject, eventdata, handles)% hObject    handle to slider1 (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% --- Executes on slider movement.function slider2_Callback(hObject, eventdata, handles)% hObject    handle to slider2 (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 slider2_CreateFcn(hObject, eventdata, handles)% hObject    handle to slider2 (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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -