📄 moddemo.m
字号:
function moddemo(action,s,ss);
%MODDEMO Demonstrates modulation and demodulation.
%
% See also CZTDEMO, FILTDEMO, SOSDEMO.
% Copyright (c) 1988-98 by The MathWorks, Inc.
% $Revision: 1.20 $ $Date: 1997/12/02 18:36:00 $
% Possible actions:
% initialize
% window
% lowpass
% operation
% cutoff
% order
% button callbacks:
% radio
% apply
% info
% close
if nargin<1,
action='initialize';
end;
if strcmp(action,'initialize'),
shh = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','on')
figNumber=figure( ...
'Name','Modulation/Demodulation Demo', ...
'handlevisibility','callback',...
'IntegerHandle','off',...
'NumberTitle','off');
%==================================
% Set up the axes
origHndl = axes( ...
'Units','normalized', ...
'Position',[0.10 0.80 0.60 0.18], ...
'XTick',[],'YTick',[], ...
'Box','on');
modHndl = axes( ...
'Units','normalized', ...
'Position',[0.10 0.3 0.60 0.45], ...
'XTick',[],'YTick',[], ...
'Box','on');
demodHndl = axes( ...
'Units','normalized', ...
'Position',[0.10 0.07 .60 0.18], ...
'XTick',[],'YTick',[], ...
'Box','on');
%====================================
% Information for all buttons (and menus)
labelColor=[0.8 0.8 0.8];
yInitPos=0.90;
menutop=0.95;
btnTop = 0.6;
top=0.75;
left=0.785;
btnWid=0.175;
btnHt=0.06;
textHeight = 0.05;
textWidth = 0.12;
% Spacing between the button and the next command's label
spacing=0.012;
%====================================
% The CONSOLE frame
frmBorder=0.019; frmBottom=0.04;
frmHeight = 0.92; frmWidth = btnWid;
yPos=frmBottom-frmBorder;
frmPos=[left-frmBorder yPos frmWidth+2*frmBorder frmHeight+2*frmBorder];
h=uicontrol( ...
'Style','frame', ...
'Units','normalized', ...
'Position',frmPos, ...
'BackgroundColor',[0.5 0.5 0.5]);
%====================================
% The DISPLAY Menu
menuNumber=1;
yPos=menutop-(menuNumber-1)*(btnHt+spacing);
if ~isstudent
labelStr='time|psd|specgram';
else
labelStr='time|psd';
end
callbackStr='moddemo(''modulate'');';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
dispHndl=uicontrol( ...
'Style','popupmenu', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Interruptible','on', ...
'Callback',callbackStr);
%====================================
% The WAVEFORM Menu
menuNumber=2;
yPos=menutop-(menuNumber-1)*(btnHt+spacing);
labelStr='speech|sine|square|triangle';
callbackStr='moddemo(''changewave'');';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
waveHndl=uicontrol( ...
'Style','popupmenu', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Interruptible','on', ...
'Callback',callbackStr);
%===================================
% Carrier frequency label and text field
top = yPos - btnHt - spacing;
labelWidth = frmWidth-textWidth-.01;
labelBottom = top-textHeight;
labelLeft = left;
labelPos = [labelLeft labelBottom labelWidth textHeight];
h = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'HorizontalAlignment','left', ...
'String','Fc', ...
'Interruptible','off', ...
'BackgroundColor',[0.5 0.5 0.5], ...
'ForegroundColor','white');
% Text field
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
callbackStr = 'moddemo(''setFc'')';
FcHndl = uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'HorizontalAlignment','center', ...
'Background','white', ...
'Foreground','black', ...
'String','400','Userdata',400, ...
'callback',callbackStr);
%===================================
% Sampling frequency label and text field
labelBottom=top-2*textHeight-spacing;
labelLeft = left;
labelPos = [labelLeft labelBottom labelWidth textHeight];
h = uicontrol( ...
'Style','text', ...
'Units','normalized', ...
'Position',labelPos, ...
'String','Fs', ...
'HorizontalAlignment','left', ...
'Interruptible','off', ...
'Background',[0.5 0.5 0.5], ...
'Foreground','white');
% Text field
textPos = [labelLeft+labelWidth labelBottom textWidth textHeight];
callbackStr = 'moddemo(''setFs'')';
FsHndl = uicontrol( ...
'Style','edit', ...
'Units','normalized', ...
'Position',textPos, ...
'HorizontalAlignment','center', ...
'Background','white', ...
'Foreground','black', ...
'String','2000','Userdata',2000, ...
'Callback',callbackStr);
%====================================
% AM radio button
btnTop = labelBottom-spacing;
btnNumber=1;
yPos=btnTop-(btnNumber-1)*(btnHt+spacing);
labelStr='AM';
callbackStr='moddemo(''radio'',1,''am'');';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
btn1Hndl=uicontrol( ...
'Style','radiobutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'value',1,'Userdata','am', ...
'Callback',callbackStr);
%====================================
% AMSSB radio button
btnTop = labelBottom-spacing;
btnNumber=2;
yPos=btnTop-(btnNumber-1)*(btnHt+spacing);
labelStr='AMSSB';
callbackStr='moddemo(''radio'',2,''amssb'');';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
btn2Hndl=uicontrol( ...
'Style','radiobutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'value',0, ...
'Callback',callbackStr);
%====================================
% FM radio button
btnNumber=3;
yPos=btnTop-(btnNumber-1)*(btnHt+spacing);
labelStr='FM';
callbackStr='moddemo(''radio'',3,''fm'');';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
btn3Hndl=uicontrol( ...
'Style','radiobutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% PM radio button
btnNumber=4;
yPos=btnTop-(btnNumber-1)*(btnHt+spacing);
labelStr='PM';
callbackStr='moddemo(''radio'',4,''pm'');';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
btn4Hndl=uicontrol( ...
'Style','radiobutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% "Play original" button
btnNumber=5;
yPos=btnTop-(btnNumber-1)*(btnHt+spacing);
labelStr='Play orig';
callbackStr='moddemo(''playsound'',1);';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
playorigHandl=uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% "Play mod" button
btnNumber=6;
yPos=btnTop-(btnNumber-1)*(btnHt+spacing);
labelStr='Play mod';
callbackStr='moddemo(''playsound'',2);';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
playmodHndl=uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% "Play demod" button
btnNumber=7;
yPos=btnTop-(btnNumber-1)*(btnHt+spacing);
labelStr='Play demod';
callbackStr='moddemo(''playsound'',3);';
% Generic button information
btnPos=[left yPos-btnHt btnWid btnHt];
playdemodHndl=uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',btnPos, ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% Message box in center of figure - usually invisible
messageHndl = uicontrol('style','edit',...
'string','Resampling speech waveform ...',...
'units','normalized',...
'position',[.15 .45 .5 .15],...
'max',2,...
'visible','off');
%====================================
% The INFO button
labelStr='Info';
callbackStr='moddemo(''info'')';
helpHndl=uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left frmBottom+btnHt+spacing btnWid btnHt], ...
'String',labelStr, ...
'Callback',callbackStr);
%====================================
% The CLOSE button
labelStr='Close';
callbackStr='close(gcf)';
closeHndl=uicontrol( ...
'Style','pushbutton', ...
'Units','normalized', ...
'Position',[left frmBottom btnWid btnHt], ...
'String',labelStr, ...
'Callback',callbackStr);
hndlList=[origHndl modHndl demodHndl waveHndl ...
FcHndl FsHndl dispHndl btn1Hndl btn2Hndl btn3Hndl ...
btn4Hndl messageHndl helpHndl closeHndl];
set(figNumber, ...
'Visible','on', ...
'UserData',hndlList);
set(gcf,'Pointer','watch');
drawnow
moddemo('changewave')
set(gcf,'Pointer','arrow');
set(0,'ShowHiddenHandles',shh)
return
elseif strcmp(action,'setFc'),
hndlList=get(gcf,'Userdata');
filtHndl = hndlList(6);
v = get(gco,'Userdata');
s = get(gco,'String');
vv = eval(s,num2str(v));
Fs = get(filtHndl,'UserData');
if vv<0, vv = v; end
vv = round(vv);
if vv>Fs/2
waitfor(msgbox({'Sorry, the carrier frequency Fc must be at most'...
'half the sampling frequency Fs.'},...
'Moddemo Error','error','modal'))
vv = v;
end
set(gco,'Userdata',vv,'String',num2str(vv))
if vv == v
return
end
moddemo('modulate')
elseif strcmp(action,'setFs'),
fig = gcf;
set(fig,'Pointer','watch');
hndlList=get(fig,'Userdata');
waveHndl = hndlList(4);
FcHndl = hndlList(5);
FsHndl = hndlList(6);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -