数字信号处理仿真系统程序【含GUI界面、MATLAB代码】

主要目标

本文内容主要是设计实现一个针对《数字信号处理》课程的仿真系统程序,要求程序具有界面,并能实现以下功能:

  • 信号产生:能产生或得到各种数字信号(sin、方波、三角波、语音、噪声及其叠加),噪声信号的噪声强度需要从键盘或鼠标输入,并能计算出信噪比,显示信噪比及时域波形;
  • 信号变换:具有DFT、DCT、DWT和经典功率谱估计功能,并能显示变换域波形;
  • 滤波器设计:具有根据需求设计IIR和FIR带通滤波器的功能,具体需求从键盘和鼠标输入,并能显示滤波器幅频和相频图;
  • 分别对产生的数字信号和读入的语音信号,显示时域和频域波形,在信号上叠加噪声(信噪比分别为20dB、10dB和0dB),显示时域和变换域波形,通过滤波器对其降噪,得到输出信号的频域特性和时间序列及信噪比。

设计思想

本文在设计的《数字信号处理》课程仿真系统程序中,主要包括“选择信号”、“信号变换”和“滤波去噪”三大模块:

  • 信号输入模块:考虑到设计要求,将信号分为数字信号、语音信号和噪声信号三类。对于数字信号而言,需要确定其时域起止范围和波形种类(正弦波、三角波、方波等);对于语音信号而言,可以通过选择本地文件进行读取;对于噪声信号而言,可以通过设定其均值和方差的方式来生成高斯噪声,也可以通过设定指定信噪比来产生相应的噪声信号,最终叠加到数字信号或语音信号上。在选择完成信号后,需要通过绘图框来将信号的时域波形和频域波形显示出来。
  • 信号变换模块:考虑到设计要求,对于上一个模块得到的含噪信号,能够实现基于DFT、DCT和DWT方法的变换处理,并在绘图框中显示变换域中信号的频谱图和相谱图。最后使用经典方法计算信号的功率谱密度,并在绘图框中显示相应的结果。
  • 信号处理模块:考虑到设计要求,对于IIR和FIR类型的带通滤波器而言,需要设定滤波器的通频带起止范围,然后分别使用双线性变换法和窗函数法实现指定要求的滤波器,并在绘图框里显示滤波器的幅频图和相频图。最后使用设计好的滤波器实现对含噪信号的去噪操作,得到滤波后的信号并显示。

结果展示

本文通过实现“基于数字信号、语音信号和噪声信号的信号输入”、“基于DFT、DCT、DWT的信号变换”和“基于IIR、FIR带通滤波器去噪的信号处理”三模块,合理设计GUI界面如下图所示:
在这里插入图片描述

  • 信号输入模块:在时域范围为0到100的情况下,分别生成正弦波、方波和三角波,或读取一段本地语音信号,得到时域和频域波形如下图所示:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    对于正弦波而言,分别添加信噪比为20dB、10dB和0dB的高斯噪声信号后,得到时域和频域波形如下图所示:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    对于三角波而言,分别添加信噪比为20dB、10dB和0dB的高斯噪声信号后,得到时域和频域波形如下图所示:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    对于方波而言,分别添加信噪比为20dB、10dB和0dB的高斯噪声信号后,得到时域和频域波形如下图所示:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
  • 信号变换模块:对于经信号输入模块最后得到的含噪信号,选择不同的变换域处理方法进行分析,并使用经典方法估计信号的功率谱密度。分别在对应绘图框中绘制变换后信号的频谱图和相谱图,以及频率-功率谱(dB)图。对于时域范围为0到20的信噪比为20dB的正弦波而言,其DFT、DCT、DWT和功率谱估计结果如下图所示:
    在这里插入图片描述
    对于时域范围为0到20的信噪比为20dB的方波而言,其DFT、DCT、DWT和功率谱估计结果如下图所示:
    在这里插入图片描述
    对于时域范围为0到20的信噪比为20dB的三角波而言,其DFT、DCT、DWT和功率谱估计结果如下图所示:
    在这里插入图片描述
    对于本地语音信号而言,其DFT、DCT、DWT和功率谱估计结果如下图所示:
    在这里插入图片描述
  • 信号处理模块:通过输入通频带起止频率范围,分别使用双线性变换法和加窗法得到相应的IIR和FIR数字带通滤波器。如当通频带为1800Hz到2200Hz时,IIR和FIR滤波器的幅频(dB)图和相频图分别如下图所示:
    在这里插入图片描述
    然后使用IIR滤波器分别对信噪比为20dB、10dB和0dB的含噪信号进行去噪,绘制去噪后信号的时域和频域图像并计算去噪后的信噪比。当初始波形为正弦波时,得到结果如下图所示:
    在这里插入图片描述
    当初始波形为方波时,得到结果如下图所示:
    在这里插入图片描述
    当初始波形为三角波时,得到结果如下图所示:
    在这里插入图片描述

问题与解决

  • GUI界面设计:由于本实验中“数字信号处理”仿真系统实现功能较为复杂,设计GUI界面时较难形成和谐统一的整体,绘图框尺寸的不足导致很多信号显示不完整或过密,影响美观与实用性。于是在学习了其他美观简洁GUI界面设计之后,最终绘制好自己的GUI界面,并进行数次修改最终得到上面的结果。
  • 滤波器设计:一开始在设计IIR和FIR滤波器的过程,由于滤波器阶数、同代博文、阻带衰减等参数设置不当,滤波后的波形、信噪比等评价指标较差。通过重新对数字信号处理相关知识进行学习和修改部分参数的数值,最终得到较为满意的结果。

附:MATLAB代码

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

% Last Modified by GUIDE v2.5 16-Jul-2021 17:07:01

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = DIPSystem_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;



function edit_audiolocation_Callback(hObject, eventdata, handles)
% hObject    handle to edit_audiolocation (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 edit_audiolocation as text
%        str2double(get(hObject,'String')) returns contents of edit_audiolocation as a double


% --- Executes during object creation, after setting all properties.
function edit_audiolocation_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_audiolocation (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 pushbutton_sin.
function pushbutton_sin_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_sin (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_t = sin(handles.xlim);
handles.signal_f = fft(handles.signal_t);
axes(handles.TimeDomain); % 绘制时域波形
plot(handles.xlim, handles.signal_t, 'k', 'LineWidth', 1);
grid on;
axes(handles.FrequencyDomain); % 绘制频域波形
plot(abs(handles.signal_f), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);

% --- Executes on button press in pushbutton_square.
function pushbutton_square_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_square (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_t = square(handles.xlim);
handles.signal_f = fft(handles.signal_t);
axes(handles.TimeDomain); % 绘制时域波形
plot(handles.xlim, handles.signal_t, 'k', 'LineWidth', 1);
grid on;
axes(handles.FrequencyDomain); % 绘制频域波形
plot(abs(handles.signal_f), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);

% --- Executes on button press in pushbutton_sawtooth.
function pushbutton_sawtooth_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_sawtooth (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_t = sawtooth(handles.xlim, 0.5);
handles.signal_f = fft(handles.signal_t);
axes(handles.TimeDomain); % 绘制时域波形
plot(handles.xlim, handles.signal_t, 'k', 'LineWidth', 1);
grid on;
axes(handles.FrequencyDomain); % 绘制频域波形
plot(abs(handles.signal_f), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);


function edit_xlimstart_Callback(hObject, eventdata, handles)
% hObject    handle to edit_xlimstart (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 edit_xlimstart as text
%        str2double(get(hObject,'String')) returns contents of edit_xlimstart as a double
handles.xlimstart = str2double(get(hObject,'String'));
guidata(hObject, handles);


% --- Executes during object creation, after setting all properties.
function edit_xlimstart_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_xlimstart (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 edit_xlimend_Callback(hObject, eventdata, handles)
% hObject    handle to edit_xlimend (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 edit_xlimend as text
%        str2double(get(hObject,'String')) returns contents of edit_xlimend as a double
handles.xlimend = str2double(get(hObject,'String'));
handles.xlim = handles.xlimstart : 0.01 : handles.xlimend;
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit_xlimend_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_xlimend (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 pushbutton_loadaudio.
function pushbutton_loadaudio_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_loadaudio (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[handles.audio,handles.audiopath] = uigetfile;
[handles.signal_noise_t,handles.signal_fs] = audioread(handles.audio);
set(handles.edit_audiolocation, 'String', handles.audio);
handles.signal_noise_f = fft(handles.signal_noise_t);
axes(handles.TimeDomain); % 绘制时域波形
plot(handles.signal_noise_t, 'k', 'LineWidth', 1);
grid on;
axes(handles.FrequencyDomain); % 绘制频域波形
plot(abs(handles.signal_noise_f), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);



function edit_noisemean_Callback(hObject, eventdata, handles)
% hObject    handle to edit_noisemean (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 edit_noisemean as text
%        str2double(get(hObject,'String')) returns contents of edit_noisemean as a double
handles.noise_mean = str2double(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit_noisemean_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_noisemean (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 edit_noisevariance_Callback(hObject, eventdata, handles)
% hObject    handle to edit_noisevariance (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 edit_noisevariance as text
%        str2double(get(hObject,'String')) returns contents of edit_noisevariance as a double
handles.noise_variance = str2double(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit_noisevariance_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_noisevariance (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 pushbutton_noise.
function pushbutton_noise_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_noise (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_length = length(handles.xlim);
handles.noise = normrnd(handles.noise_mean, handles.noise_variance, [1 handles.signal_length]);
handles.signal_noise_t = handles.signal_t + handles.noise;
handles.snr_calculate = snr(handles.signal_t, handles.noise);
set(handles.edit_snrin, 'String', num2str(handles.snr_calculate));
handles.signal_noise_f = fft(handles.signal_noise_t);
axes(handles.TimeDomain); % 绘制时域波形
plot(handles.signal_noise_t, 'k', 'LineWidth', 1);
grid on;
axes(handles.FrequencyDomain); % 绘制频域波形
plot(abs(handles.signal_noise_f), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);


function edit_snrin_Callback(hObject, eventdata, handles)
% hObject    handle to edit_snrin (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 edit_snrin as text
%        str2double(get(hObject,'String')) returns contents of edit_snrin as a double
handles.snr_get = str2double(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit_snrin_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_snrin (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 pushbutton_dft.
function pushbutton_dft_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_dft (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_noise_f = fft(handles.signal_noise_t);
axes(handles.AmplitudeFreq); % 绘制幅频图
plot(abs(handles.signal_noise_f), 'k', 'LineWidth', 1);
grid on;
axes(handles.PhaseFreq); % 绘制相频图
plot(angle(handles.signal_noise_f), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);

% --- Executes on button press in pushbutton_dct.
function pushbutton_dct_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_dct (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_noise_c = dct(handles.signal_noise_t);
axes(handles.AmplitudeFreq); % 绘制幅频图
plot(abs(handles.signal_noise_c), 'k', 'LineWidth', 1);
grid on;
axes(handles.PhaseFreq); % 绘制相频图
plot(angle(handles.signal_noise_c), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);

% --- Executes on button press in pushbutton_dwt.
function pushbutton_dwt_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_dwt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_noise_w = dwt(handles.signal_noise_t(:,1), 'haar');
axes(handles.AmplitudeFreq); % 绘制幅频图
plot(abs(handles.signal_noise_w), 'k', 'LineWidth', 1);
grid on;
axes(handles.PhaseFreq); % 绘制相频图
plot(angle(handles.signal_noise_w), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);

% --- Executes on button press in pushbutton_powerspectrum.
function pushbutton_powerspectrum_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_powerspectrum (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[handles.pxx, handles.psf] = periodogram(handles.signal_noise_t, rectwin(length(handles.signal_noise_t)), length(handles.signal_noise_t));
axes(handles.PowerSpectrum);
plot(handles.psf, 10 * log10(handles.pxx), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);


function edit_filterstart_Callback(hObject, eventdata, handles)
% hObject    handle to edit_filterstart (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 edit_filterstart as text
%        str2double(get(hObject,'String')) returns contents of edit_filterstart as a double
handles.filterstart = str2double(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit_filterstart_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_filterstart (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 edit_filterend_Callback(hObject, eventdata, handles)
% hObject    handle to edit_filterend (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 edit_filterend as text
%        str2double(get(hObject,'String')) returns contents of edit_filterend as a double
handles.filterend = str2double(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function edit_filterend_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_filterend (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 pushbutton_iir.
function pushbutton_iir_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_iir (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.iir_Wp = [handles.filterstart handles.filterend];
handles.iir_Ws = [handles.iir_Wp(1) - 100 , handles.iir_Wp(2) + 100];
[handles.iir_n, handles.iir_Wn] = buttord(handles.iir_Wp/2500,handles.iir_Ws/2500,3,40);
[handles.iir_z,handles.iir_p,handles.iir_k] = butter(handles.iir_n, handles.iir_Wn);
handles.iir = zp2sos(handles.iir_z,handles.iir_p,handles.iir_k);
[handles.iir_h,handles.iir_w] = freqz(handles.iir,100);
axes(handles.filterAF);
plot(handles.iir_w/pi,20 * log10(abs(handles.iir_h)),'k', 'LineWidth', 1);
grid on;
axes(handles.filterPF);
plot(handles.iir_w/pi,angle(handles.iir_h),'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);


% --- Executes on button press in pushbutton_fir.
function pushbutton_fir_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_fir (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.fir_Wp = [handles.filterstart handles.filterend];
handles.fir = fir1(48,handles.fir_Wp/2500);
[handles.fir_h,handles.fir_w] = freqz(handles.fir,100);
axes(handles.filterAF);
plot(handles.fir_w/pi,20 * log10(abs(handles.fir_h)),'k', 'LineWidth', 1);
grid on;
axes(handles.filterPF);
plot(handles.fir_w/pi,angle(handles.fir_h),'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);

% --- Executes on button press in pushbutton_filternoisereduction.
function pushbutton_filternoisereduction_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_filternoisereduction (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.signal_noiseout_t = movmean(handles.signal_noise_t,5);
handles.signal_noiseout_f = fft(handles.signal_noiseout_t);
handles.snrout_set = snr(handles.signal_t,handles.signal_noiseout_t-handles.signal_t);
set(handles.edit_snrout, 'String', num2str(handles.snrout_set));
axes(handles.filterAF);
plot(handles.xlim,handles.signal_noiseout_t,'k', 'LineWidth', 1);
grid on;
axes(handles.filterPF);
plot(abs(handles.signal_noiseout_f),'k', 'LineWidth', 1);
grid on;


function edit_snrout_Callback(hObject, eventdata, handles)
% hObject    handle to edit_snrout (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 edit_snrout as text
%        str2double(get(hObject,'String')) returns contents of edit_snrout as a double


% --- Executes during object creation, after setting all properties.
function edit_snrout_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_snrout (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 pushbutton_noisesnr.
function pushbutton_noisesnr_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_noisesnr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
handles.snr_noise = randn(size(handles.signal_t))*std(handles.signal_t)/db2mag(handles.snr_get);
handles.signal_noise_t = handles.signal_t + handles.snr_noise;
handles.snr_set = snr(handles.signal_t, handles.snr_noise);
set(handles.edit_snrin, 'String', num2str(handles.snr_set));
handles.signal_noise_f = fft(handles.signal_noise_t);
axes(handles.TimeDomain); % 绘制时域波形
plot(handles.signal_noise_t, 'k', 'LineWidth', 1);
xlim auto;
grid on;
axes(handles.FrequencyDomain); % 绘制频域波形
plot(abs(handles.signal_noise_f), 'k', 'LineWidth', 1);
grid on;
guidata(hObject, handles);

  • 4
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值