✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。
🍎个人主页:Matlab科研工作室
🍊个人信条:格物致知。
⛄ 内容介绍
现阶段,我国数字信号处理与仿真技术正在逐步的发展,成为了一门新兴学科,并以其自身独特的特点对其他学科进行影响.不仅如此,数字信号处理与仿真技术与我国国民经济的发展存在着密切的联系.它的应用使我们的生产生活发生了翻天覆地变化.本文从数字信号处理与仿真的相关概念出发,系统的阐述了基于MATLAB下的数字信号处理与仿真技术.
⛄ 部分代码
function varargout = signal_gui(varargin)
% SIGNAL_GUI MATLAB code for signal_gui.fig
% SIGNAL_GUI, by itself, creates a new SIGNAL_GUI or raises the existing
% singleton*.
%
% H = SIGNAL_GUI returns the handle to a new SIGNAL_GUI or the handle to
% the existing singleton*.
%
% SIGNAL_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIGNAL_GUI.M with the given input arguments.
%
% SIGNAL_GUI('Property','Value',...) creates a new SIGNAL_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before signal_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to signal_gui_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 signal_gui
% Last Modified by GUIDE v2.5 22-Dec-2020 14:08:59
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @signal_gui_OpeningFcn, ...
'gui_OutputFcn', @signal_gui_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 signal_gui is made visible.
function signal_gui_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 signal_gui (see VARARGIN)
% Choose default command line output for signal_gui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes signal_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = signal_gui_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 pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% 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)
ret=questdlg('确认退出?','退出确认','yes','no','no');
if strcmp(ret,'no')
return;
end
close(gcf);
% --- Executes on selection change in popupmenu3.
function popupmenu3_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu3 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu3
% --- Executes during object creation, after setting all properties.
function popupmenu3_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu3 (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 button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% 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)
fre2=get(handles.edit4,'string');
amp2=get(handles.edit5,'string');
points2=get(handles.edit6,'string');
fre2 = eval(fre2);
amp2 = eval(amp2);
points2 = eval(points2);
va2 = get(handles.popupmenu2,'Value');
str2 = get(handles.popupmenu2,'String');
switch str2{va2}
case '正弦波'
fs = 100;
N2 = points2;
n2 = 0:N2-1;
t2 = n2/fs;
x2 = amp2*sin(2*pi*fre2*t2);
case '方波'
fs = 100;
N2 = points2;
n2 = 0:N2-1;
t2 = n2/fs;
x2 = amp2*square(2*pi*fre2*t2,50);
case '三角波'
fs = 100;
N2 = points2;
n2 = 0:N2-1;
t2 = n2/fs;
x2 = amp2*sawtooth(2*pi*fre2*t2,0.5);
end
fre1=get(handles.edit1,'string');
amp1=get(handles.edit2,'string');
points1=get(handles.edit3,'string');
fre1 = eval(fre1);
amp1 = eval(amp1);
points1 = eval(points1);
val = get(handles.popupmenu1,'Value');
str = get(handles.popupmenu1,'String');
switch str{val}
case '正弦波'
fs = 100;
N1 = points1;
n1 = 0:N1-1;
t1 = n1/fs;
x1 = amp1*sin(2*pi*fre1*t1);
case '方波'
fs = 100;
N1 = points1;
n1 = 0:N1-1;
t1 = n1/fs;
x1 = amp1*square(2*pi*fre1*t1,50);
case '三角波'
fs = 100;
N1 = points1;
n1 = 0:N1-1;
t1 = n1/fs;
x1 = amp1*sawtooth(2*pi*fre1*t1,0.5);
end
axes(handles.axes3);
cla reset;
va2 = get(handles.popupmenu3,'Value');
str2 = get(handles.popupmenu3,'String');
switch str2{va2}
case '加'
if length(x1)>length(x2)
t = t1;
x = x1+x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
else
t = t2;
x = x1+x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
end
case '减'
if length(x1)>length(x2)
t = t1;
x = x1-x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
else
t = t2;
x = x1-x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
end
case '乘'
if length(x1)>length(x2)
t = t1;
x = x1.*x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
else
t = t2;
x = x1.*x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
end
case '除'
if length(x1)>length(x2)
t = t1;
x = x1./x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
else
t = t2;
x = x1./x2;
plot(t,x,'r');
xlabel('时间');
ylabel('信号');
end
end
guidata(hObject,handles);
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (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
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
guidata(hObject,handles);
⛄ 运行结果
⛄ 参考文献
[1] 杨峰, 苏玉萍, 余冬菊. 用MATLAB模拟实现数字信号的调制与频谱分析[J]. 电脑学习, 2008.
[2] 王靖斌. 基于MATLAB的数字信号处理的模拟与仿真[J]. 2008.
[3] 钟丽辉, 戴正权, 李莎. 基于MATLAB的工程实践性"数字信号处理"实验改革初探[J]. 工业和信息化教育, 2016(12):6.