说明:
下文分析了9. AM.zip中的代码,并给出了注释。代码中,以’%%’开头的注释行为新加入部分。
该文件中的代码给出了一个直观的AM(幅度调制或调幅)直观演示。可以通过右侧的划块分别控制调制的载波频率(f_c, 0~200)和基带信号频率(f_m, 0~50)。左侧两个figure分别展示了调幅波的时域波形和频谱图。左上图中,红虚线为基带信号波形,同时也是调幅波的包络;蓝实线为调幅波的时域波形。左下图中展示的是调幅波的频谱图。
另外ZOOM ON/OFF按钮可以控制两个figure能否放大。使能放大特性后,可以鼠标点击figure,放大/缩小波形。
另外,由于给出的代码中有部分代码重复,我将三次重复的代码提取出来,写成了一个新的函数(function common()),从而减少了代码量。 由于在我的系统上,中文注释粘贴过来变成乱码,所以都改成了英文注释。
图 1 运行结果截图
Am_mod.m
function varargout = am_mod(varargin)
% Edit the above text to modify the response to help am_mod
% Last Modified by GUIDE v2.5 04-Oct-2007 22:39:46
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @am_mod_OpeningFcn, ...
'gui_OutputFcn', @am_mod_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
object to
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 am_mod is made visible.
function am_mod_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 am_mod (see VARARGIN)
%% set the current figure's backgroud color to yellow
%% gcf refers to current figure handle;
set(gcf,'Color',[1 1 0]);
%% set Carrier Handle's value to 50% of its max value(frequency)
set(handles.carrier,'Value',0.5);
%% set Modulating signal's value to 50% of its max value(frequency)
d,'Value',0.5);
%% set the ejex's horrizontal axis to 0~0.5, step = 1/1000; (time domain)
handles.ejex=0:1/1000:.5;
common(200*.5, 50*.5, handles);
%zoom on
% Choose default command line output for am_mod
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes am_mod wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = am_mod_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 slider movement.
function mod_Callback(hObject, eventdata, handles)
% hObject handle to mod (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
f_m=50*get(hObject,'Value');
f_c=200*get(handles.carrier,'Value');
common(f_c, f_m, handles);
% --- Executes during object creation, after setting all properties.
function mod_CreateFcn(hObject, eventdata, handles)
% hObject handle to mod (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 carrier_Callback(hObject, eventdata, handles)
% hObject handle to carrier (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
f_c=200*get(hObject,'Value');
f_m=50*d,'Value');
common(f_c, f_m, handles);
% --- Executes during object creation, after setting all properties.
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论