Having picture appear on GUI
3 次查看(过去 30 天)
显示 更早的评论
I have created a GUI that has an listbox that displays information from my popup menu. I also have recreated a radio button that shows the information that I have inputed from click on the selections from the popup box. I want to display a picture when the user clicks the radio button. I have been have trouble with having different pictures show when clicking a selection from the popup box into the axis box I have on the screen. I would like to know of any hints that might help with my situation. Thanks.
Here is the code from the GUI if it needs to be viewed
function varargout = Heisman(varargin)
% HEISMAN MATLAB code for Heisman.fig
% HEISMAN, by itself, creates a new HEISMAN or raises the existing
% singleton*.
%
% H = HEISMAN returns the handle to a new HEISMAN or the handle to
% the existing singleton*.
%
% HEISMAN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HEISMAN.M with the given input arguments.
%
% HEISMAN('Property','Value',...) creates a new HEISMAN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Heisman_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Heisman_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 Heisman
% Last Modified by GUIDE v2.5 02-Aug-2013 13:19:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Heisman_OpeningFcn, ...
'gui_OutputFcn', @Heisman_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 Heisman is made visible.
function Heisman_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 Heisman (see VARARGIN)
% Choose default command line output for Heisman
handles.output = hObject;
handles.radio=0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Heisman wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Heisman_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 radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
radio_state=get(hObject,'Value');
handles.radio=radio_state;
guidata(hObject,handles);
function listbox1_Callback(hObject, eventdata, handles)
% hObject handle to listbox1 (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 listbox1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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 popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
contents=cellstr(get(hObject,'String'));
player=contents{get(hObject,'Value')};
if handles.radio==0
a=char('Name: Johnny Manziel','','School:Texas A&M','','Class:Freshman','','Stats','','Completion%: 68%','','Passing Yards: 3706','','Avg. Yards: 8.4','','TDs: 26','','Int: 9','','QB Rating: 155.32','','Rushing Yards: 1410','','Avg. Rush: 7.0','','Rush TDs: 21');
b=char('Trent Richardson','','Alabama');
end
switch player
case {'2013'}
set(handles.listbox1,'String',a)
case {'2012'}
set(handles.listbox1,'String',b)
otherwise
set(handles.listbox1,'String','')
end
guidata(hObject,handles);
% --- 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
0 个评论
回答(1 个)
Suman Saha
2013-8-7
%%%THIS IS AN GUI FUNCTION YOU CAN GET SO MANY TYPES OF BUTTONS AND THE USE %%%OF POPUP BUTTONS: 'HOW TO ASSOCIATE WITH DIFFERENT FUNCTIONS WITH THE %%%DIFFERENT POPUP MENUS'.
function ANALOGCOMM(action) % This is a Amplitude Modulation tool box. It can be used for the % visualization of modulated signal in time domain as well as in frequency % domain. Messasge signal & carrier signal can also be seen in time as well % as freq domain. There are five types of functions included for the generation % of message signal & carrier signal.For a perticular message function different % carrier signals can be used to see the modulated signal in time domain as % well as in frequency domain. The amplitude & frequency of the message & % carrier signal can be changed by the user to see the differences in output % signal in both domains. The maximum frequency limit also can be cganged % just by changing the sample rate (here, NN=9001 is used) of the sin, % cosine, square, trangular or the sawtooth function generator. % Creator : Suman Saha; MTECH, ECE, KGEC % Date of complition: 04/05/2013. Time: 8.00pm Total time taken: 6.5hours if nargin<1, action='initialize'; end; if strcmp(action,'initialize') close all;clc %============================================ % TOTAL FIGURE figNumber=figure('Name','A M P L I T U D E M O D U L A T I O N','NumberTitle','off','Units','inches','Position',[0.8 0.8 9 6],'Resize','off','ToolBar','figure'); colordef(figNumber,'black') axes('Units','inches','Position',[0.5 0.4 4.8 4.3],'Visible','on'); %========================================================================== xpos=5.6; ypos=4.6; xw=1.5; yw=0.2; CROdis=uicontrol('Style','text','Tag','CRO','Unit','inches','Position',[0.3 4.91 2 0.2],'BackgroundColor',[0.2 0.2 0.2],'FontWeight','bold','FontName','Times New Roman','FontSize',12,'ForeGroundColor',[1 0 1 ]); %popup button for the modulation schemes cmdListmod=strvcat('NULL','DSBFC','DSBSC','SSBSC LSB','SSBSC USB'); hndl1mod=uicontrol('Style','popup','Units','inches','Position',[xpos-3.4 ypos+0.8 xw+0.3 yw],... 'ForegroundColor',[0 0 0],'BackgroundColor',[0.9 0.06 0.6],'FontWeight','bold',... 'String','See Message or Carrier|DSBFC|DSBSC|SSBSC (LSB)|SSBSC (USB)','FontSize',10,... 'Callback','ANALOGCOMM build','UserData',cmdListmod); uicontrol('Style','text','String','Choose Display for Message or Carrier/DSBFC/DSBSC/SSBSC','Units','inches','ForegroundColor',[1 1 1],'FontSize',12,... 'Position',[0.3 5.65 5 0.2],'BackgroundColor',[0.2 0.2 0.2],'FontName','times new roman','FontWeight','bold'); %========================================================================== %text for Message signal display uicontrol('Style','text','Units','inches','Position',[xpos-0.11 ypos+0.4 1.75 0.2],'FontSize',10,... 'BackgroundColor',[0.2 0.2 0.2],'String','MESSAGE SIGNAL','FontWeight','bold',... 'FontName','Times new roman','HorizontalAlignment','center','ForegroundColor',[1 1 1]); %text for Carrier Signal display uicontrol('Style','text','Units','inches','Position',[xpos+1.68 ypos+0.4 1.75 0.2],'FontSize',10,... 'BackgroundColor',[0.2 0.2 0.2],'String','CARRIER SIGNAL','ForegroundColor',[1 1 1],... 'FontName','Times new roman','FontWeight','bold','HorizontalAlignment','center'); %========================================================================== %%----------FOR MESSAGE SIGNAL-----------%% %----THE CONSOLE FRAME1----% h1=uicontrol('Style','frame','Units','inches','Position',[xpos-0.11 ypos-3.08 1.75 3.5], ... 'BackgroundColor',0.8*[0.5 0.8 0.04]); h=uicontrol('Style','frame','Units','inches','Position',[xpos-0.06 ypos-3.05 1.6 3.4], ... 'BackgroundColor',[0.50 0.750 0.050]); %============================================ % FIRST SLIDER for message signal sld1Hndl=uicontrol('Style','slider','Tag','Amplitude','Units','inches', ... 'Position',[xpos ypos-0.4 xw yw],'BackgroundColor',0.6*[0 1 1],'Callback','ANALOGCOMM(''build'')'); uicontrol('Style','text','String','Amplitude','Units','inches','FontName','monotype corsiva', ... 'Position',[xpos ypos xw yw+0.1],'BackgroundColor',0.3*[0 0 1],'FontSize',15,... 'ForegroundColor',0.9*[1 0 1]); uicontrol('Style','text','String',' 0 [Volt] --- 50','BackgroundColor',0.3*[0 0 1],'FontSize',10,... 'ForegroundColor',0.9*[0 1 1],'Units','inches','Position',[xpos ypos-0.2 xw yw]); %============================================ % Text for Inputing Frequency range uicontrol('Style','text','FontName','Times new roman','FontWeight','bold',... 'FontSize',10,'HorizontalAlignment','center','Units','inches', ... 'String','Input Frequency Range','BackgroundColor','yellow', ... 'Position',[xpos ypos-1.08 xw yw+0.25]); FF=uicontrol('Style','edit','FontName','monotype corsiva', ... 'FontSize',14,'HorizontalAlignment','left', ... 'Units','inches','Max',1,'String','50','BackgroundColor',[0.7 0.7 0.5], ... 'Callback','ANALOGCOMM(''build'')','Position',[xpos+0.09 ypos-1.06 xw-0.2 yw]); %============================================ % SECOND SLIDER for message signal sld2Hndl=uicontrol('Style','slider','Tag','Frequency','Units','inches', ... 'Position',[xpos ypos-1.8 xw yw],'BackgroundColor',0.6*[0 1 1],'Callback','ANALOGCOMM(''build'')'); uicontrol('Style','text','String','Frequency','Units','inches','FontSize',15,'FontName','monotype corsiva', ... 'Position',[xpos ypos-1.4 xw yw+0.1],'BackgroundColor',0.3*[0 0 1],'ForegroundColor',0.9*[1 0 1]); uicontrol('Style','text','Tag','DisFreq','Units','inches','ForegroundColor',0.9*[0 1 1],'FontSize',10,... 'Position',[xpos ypos-1.6 xw yw],'BackgroundColor',0.3*[0 0 1]); %======================================== %============================================ % TEXT FOR CHOOSE FUNCTION for message signal uicontrol('Style','text','Units','inches','Position',[xpos ypos-2.4 xw yw+0.1],'String','Choose Function','FontName','times new roman', ... 'ForegroundColor','black','FontWeight','bold','FontSize',11,'BackgroundColor',[0.50 0.750 0.050]); % POPUP BUTTON TO SELECT FUNCTION TYPE cmdList=strvcat('Sine','Cosine','Square','Triangular','Sawtooth'); hndl1=uicontrol('Style','popup','Units','inches','Position',[xpos-0.01 ypos-2.4 xw+0.03 yw-0.1],... 'ForegroundColor',0.9*[1 1 0],'BackgroundColor',0.3*[0 0 1],'FontWeight','bold',... 'String','SINE|COSINE|SQUARE|TRIANGULAR|SAWTOOTH','FontSize',9,... 'Callback','ANALOGCOMM build','UserData',cmdList); %============================================= %%----------FOR CARRIER SIGNAL-----------%% %THE CONSOLE FRAME h1C=uicontrol('Style','frame','Units','inches','Position',[7.3 1.52 1.75 3.5], ... 'BackgroundColor',0.8*[0.5 0.8 0.04]); hC=uicontrol('Style','frame','Units','inches','Position',[7.35 1.55 1.6 3.4], ... 'BackgroundColor',[0.50 0.750 0.050]); %============================================ % FIRST SLIDER for carrier signal sld1HndlC=uicontrol('Style','slider','Tag','AmplitudeC','Units','inches', ... 'Position',[7.41 4.2 1.5 0.2],'BackgroundColor',0.6*[0 1 1],'Callback','ANALOGCOMM(''build'')'); uicontrol('Style','text','String','Amplitude','Units','inches','FontName','monotype corsiva', ... 'Position',[7.41 4.6 1.5 0.3],'BackgroundColor',0.3*[0 0 1],'FontSize',15,... 'ForegroundColor',0.9*[1 0 1]); uicontrol('Style','text','String',' 0 [Volt] --- 50','BackgroundColor',0.3*[0 0 1],'FontSize',10,... 'ForegroundColor',0.9*[0 1 1],'Units','inches','Position',[7.41 4.4 1.5 0.2]); %============================================ % Text for Inputing Frequency range for carrier signal uicontrol('Style','text','FontName','Times new roman','FontWeight','bold',... 'FontSize',10,'HorizontalAlignment','center','Units','inches', ... 'String','Input Frequency Range','BackgroundColor','yellow', ... 'Position',[7.41 3.52 1.5 0.45]); FFC=uicontrol('Style','edit','FontName','monotype corsiva', ... 'FontSize',14,'HorizontalAlignment','left', ... 'Units','inches','Max',1,'String','50','BackgroundColor',[0.7 0.7 0.5], ... 'Callback','ANALOGCOMM(''build'')','Position',[7.5 3.54 1.3 0.2]); %============================================ % SECOND SLIDER for carrier signal sld2HndlC=uicontrol('Style','slider','Tag','FrequencyC','Units','inches', ... 'Position',[7.41 2.8 1.5 0.2],'BackgroundColor',0.6*[0 1 1],'Callback','ANALOGCOMM(''build'')'); uicontrol('Style','text','String','Frequency','Units','inches','FontSize',15,'FontName','monotype corsiva', ... 'Position',[7.41 3.2 1.5 0.3],'BackgroundColor',0.3*[0 0 1],'ForegroundColor',0.9*[1 0 1]); uicontrol('Style','text','Tag','DisFreqC','Units','inches','ForegroundColor',0.9*[0 1 1],'FontSize',10,... 'Position',[7.41 3 1.5 0.2],'BackgroundColor',0.3*[0 0 1]); %============================================ % TEXT FOR CHOOSE FUNCTION for carrier signal uicontrol('Style','text','Units','inches','Position',[7.41 2.2 1.5 0.3],'String','Choose Function','FontName','times new roman', ... 'ForegroundColor','black','FontWeight','bold','FontSize',11,'BackgroundColor',[0.50 0.750 0.050]); % POPUP BUTTON TO SELECT FUNCTION TYPE cmdListC=strvcat('Sine','Cosine','Square','Triangular','Sawtooth'); hndl1C=uicontrol('Style','popup','Units','inches','Position',[7.4 2.2 1.53 0.1],... 'ForegroundColor',0.9*[1 1 0],'BackgroundColor',0.3*[0 0 1],'FontWeight','bold',... 'String','SINE|COSINE|SQUARE|TRIANGULAR|SAWTOOTH','FontSize',9,... 'Callback','ANALOGCOMM build','UserData',cmdListC); %========================================================================== %---------------Toogle button to display message signal or carrier signal sld4Hndl=uicontrol('Style','toggle','Tag','tdis','Units','inches','String','Message/Carrier','FontSize',11,'FontWeight','bold',... 'Position',[6.31 5.3 1.8 0.3],'BackgroundColor',[0.9 0.06 0.6],'Callback','ANALOGCOMM(''build'')'); uicontrol('Style','text','String','Choose Display for Message/Carrier','Units','inches','ForegroundColor',[1 1 1],'FontSize',12,... 'Position',[5.7 5.6 3 0.2],'BackgroundColor',[0.2 0.2 0.2],'FontName','times new roman','FontWeight','bold'); %----CHOOSE time DOMAIN or freauency domain ,TOGGLE BUTTON----% sld3Hndl=uicontrol('Style','toggle','Tag','TFreq','Units','inches','String','Time/Freq','FontSize',12,'FontWeight','bold',... 'Position',[6.44 1 1.4 0.3],'BackgroundColor',[0.9 0.06 0.6],'Callback','ANALOGCOMM(''build'')'); uicontrol('Style','text','String','Choose Domain Time/Freq','Units','inches','ForegroundColor',[1 1 1],'FontSize',12,... 'Position',[5.9 1.25 2.4 0.2],'BackgroundColor',[0.2 0.2 0.2],'FontName','times new roman','FontWeight','bold'); %%----SPECIFICATION TEXT-----%% specstrC=sprintf('Maximum Amplitude 50 Volt\nMaximum freq. 4.499kHz\nMade by Suman Saha\n MTech ECE KGEC\n Date: 4.5.13'); specification=uicontrol('Style','text','Units','inches','Position',[7.34 0.1 1.6 0.7],'String',specstrC, ... 'ForegroundColor',[1 1 1],'BackgroundColor',[0.2 0.2 0.2],'FontSize',8); %%----Initialize button------%% initialization=uicontrol('Style','push','FontName','Times new roman','FontWeight','bold',... 'FontSize',12,'HorizontalAlignment','center','Units','inches','String','Initialize',... 'BackgroundColor',[0.2071 0.6072 0.6299],'Callback','ANALOGCOMM(''initialize'')','Position',[xpos 0.6 1.4 0.3]); %%----THE CLOSE BUTTON-----% closee=uicontrol('Style','push','Units','inches','Position',[xpos 0.2 1.4 0.3],'String','C L O S E','FontName','monotype corsiva', ... 'ForegroundColor','black','BackgroundColor','red','FontWeight','bold','FontSize',15,'Callback','close(gcf)'); %========================================================================== %------------Typing the value of Amplitud of Message--------% uicontrol('Style','text','Tag','Ampl','Units','inches','FontWeight','bold','FontSize',11,... 'Position',[xpos ypos-0.6 xw yw],'BackgroundColor',0.3*[0 0 1],'ForegroundColor',0.9*[0 1 1]); %------------Typing the value of Frequency of Message--------% uicontrol('Style','text','Tag','Freq','Units','inches','FontWeight','bold','FontSize',11,... 'Position',[xpos ypos-2 xw yw],'BackgroundColor',0.3*[0 0 1],'ForegroundColor',0.9*[0 1 1]); %------------Typing the value of Amplitud of Carrier--------% uicontrol('Style','text','Tag','AmplC','Units','inches','FontWeight','bold','FontSize',11,... 'Position',[xpos+1.8 ypos-0.6 xw yw],'BackgroundColor',0.3*[0 0 1],'ForegroundColor',0.9*[0 1 1]); %------------Typing the value of Frequency of Carrier--------% uicontrol('Style','text','Tag','FreqC','Units','inches','FontWeight','bold','FontSize',11,... 'Position',[xpos+1.8 ypos-2 xw yw],'BackgroundColor',0.3*[0 0 1],'ForegroundColor',0.9*[0 1 1]); %========================================================================== hndlList=[hndl1,FF,hndl1C,FFC,hndl1mod]; set(figNumber,'Visible','on','UserData',hndlList); ANALOGCOMM('build'); % call itself to build the defferent function %============================================ %%---Take Slider Input as well as Popup button input & Redraw---%% elseif strcmp(action,'build') kt=get(findobj(gcf,'Tag','tdis'),'Value'); TF=get(findobj(gcf,'Tag','TFreq'),'Value'); hndlList=get(gcf,'UserData'); [rmod,cmod]=size(hndlList(:,5)); for countmod=1:rmod newStrListmod=get(hndlList(countmod,5),'UserData'); newStrValmod=get(hndlList(countmod,5),'Value'); newStrmod=deblank(newStrListmod(newStrValmod,:)); end FF=hndlList(2); fr=str2num(get(FF(1),'String')); FFC=hndlList(4); frC=str2num(get(FFC(1),'String')); A=50*get(findobj(gcf,'Tag','Amplitude'),'Value'); F=fr*get(findobj(gcf,'Tag','Frequency'),'Value'); AC=50*get(findobj(gcf,'Tag','AmplitudeC'),'Value'); FC=frC*get(findobj(gcf,'Tag','FrequencyC'),'Value'); [rn,cn]=size(hndlList(:,1)); for count=1:rn newStrList=get(hndlList(count,1),'UserData'); newStrVal=get(hndlList(count,1),'Value'); newStr=deblank(newStrList(newStrVal,:)); % Optional newStrListC=get(hndlList(count,3),'UserData'); newStrValC=get(hndlList(count,3),'Value'); newStrC=deblank(newStrListC(newStrValC,:)); % Optional end %---------------------------------------------------- set(findobj(gcf,'Tag','CRO'),'String','CRO'); set(findobj(gcf,'Tag','Ampl'),'String',sprintf('%f Volt',A)); set(findobj(gcf,'Tag','Freq'),'String',sprintf('%f Hz',F)); set(findobj(gcf,'Tag','DisFreq'),'String',sprintf(' 0 [Hz] --- %d',fr)); set(findobj(gcf,'Tag','AmplC'),'String',sprintf('%f Volt',AC)); set(findobj(gcf,'Tag','FreqC'),'String',sprintf('%f Hz',FC)); set(findobj(gcf,'Tag','DisFreqC'),'String',sprintf(' 0 [Hz] --- %d',frC)); % Default Display Message set(findobj(gcf,'Tag','tdis'),'String','MESSAGE');
[tsM,xM,yM]= amardacM(newStrVal,A,F,fr);
% title 'TIME DOMAIN MESSAGE SIGNAL'
set(get(gca,'Title'),'String','TIME DOMAIN MESSAGE SIGNAL');
if kt==1 % Display Carrier
set(findobj(gcf,'Tag','tdis'),'String','CARRIER');
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
% title 'TIME DOMAIN CARRIER SIGNAL'
set(get(gca,'Title'),'String','TIME DOMAIN CARRIER SIGNAL');
end
if newStrValmod==2
[tsM,xM,yM]= amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,t,DSBFC]=DSBFCfun(yM,yC,xM,AC);
plot(t,DSBFC);
% title 'TIME DOMAIN DSBFC SIGNAL'
set(get(gca,'Title'),'String','TIME DOMAIN DSBFC SIGNAL');
elseif newStrValmod==3
[tsM,xM,yM]= amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,t,DSBSC]=DSBSCfun(yM,yC,xM);
plot(t,DSBSC);
% title 'TIME DOMAIN DSBSC SIGNAL'
set(get(gca,'Title'),'String','TIME DOMAIN DSBSC SIGNAL');
elseif newStrValmod==4
[tsM,xM,yM]= amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,t,SSBSC]= SSBSCLSB(yM,yC,xM,F,FC);
plot(t,SSBSC);
% title 'TIME DOMAIN SSBSC SIGNAL'
set(get(gca,'Title'),'String','TIME DOMAIN SSBSC SIGNAL');
elseif newStrValmod==5
[tsM,xM,yM]= amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,t,SSBSC]= SSBSCUSB(yM,yC,xM,F,FC);
plot(t,SSBSC);
% title 'TIME DOMAIN SSBSC SIGNAL'
set(get(gca,'Title'),'String','TIME DOMAIN SSBSC SIGNAL');
end
set(get(gca,'XLabel'),'String','Time (sec) ------>'); %Labeling the X-axis
set(get(gca,'YLabel'),'String','Amplitude (Volt) ------>');
set(findobj(gcf,'Tag','TFreq'),'String','TIME');
if TF==1
set(findobj(gcf,'Tag','CRO'),'String','SPECTRUM ANALYZER');
set(gca,'XGrid','on','YGrid','on');
set(findobj(gcf,'Tag','TFreq'),'String','FREQUENCY');
if newStrValmod==1&& kt==0
[tsM,xM,yM]=amardacM(newStrVal,A,F,fr);
spectrum_analyzer(yM,xM,tsM,'MESSAGE SIGNAL');
elseif newStrValmod==1&& kt==1
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
spectrum_analyzer(yC,xC,tsC,'CARRIER SIGNAL');
elseif newStrValmod==2
[tsM,xM,yM]=amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,x,y]=DSBFCfun(yM,yC,xM,AC);
spectrum_analyzer(y,x,ts,'DSBFC SIGNAL');
elseif newStrValmod==3
[tsM,xM,yM]=amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,x,y]=DSBSCfun(yM,yC,xM);
spectrum_analyzer(y,x,ts,'DSBSC SIGNAL');
elseif newStrValmod==4
[tsM,xM,yM]=amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,x,y]=SSBSCLSB(yM,yC,xM,F,FC);
spectrum_analyzer(y,x,ts,'SSBSC LSB SIGNAL');
elseif newStrValmod==5
[tsM,xM,yM]=amardacM(newStrVal,A,F,fr);
[tsC,xC,yC]= amardacC(newStrValC,AC,FC,frC);
[ts,x,y]=SSBSCUSB(yM,yC,xM,F,FC);
spectrum_analyzer(y,x,ts,'SSBSC USB SIGNAL');
end
end
set(gca,'XGrid','on','YGrid','on');
drawnow % for redraw purpose
end % ending (initialization)
%===========================Main Program Ends=============================%
%%%==========SUBFUNCTIONS=================%%%
function [ts,t,outcurv]=sincurve(A,F)
NN=9001;
% NN(F>10)=F*20;
% NN(F>100)=2000;
ts=1/NN;
t=linspace(0,1,NN);
outcurv=A*sin(2*pi*t*F);
h=plot(t,outcurv,'linew',1.5);
set( h,'tag','surface1'); % Optional
%------ Cosine Wave Function--------------%
function [ts,t,outcurv]=coscurve(A,F);
NN=9001;
ts=1/NN;
t=linspace(0,1,NN);
outcurv=A*cos(2*pi*t*F);
h=plot(t,outcurv,'linew',1.5);
set( h,'tag','surface1'); % Optional
%------ Square Wave Function--------------%
function [ts,t,b]=squarew(A,F)
NN=9001;
ts=1/NN;
t=linspace(0,1,NN);
b=A*square(2*pi*t*F,50);
ts=1/length(b);
h=plot(t,b,'y','linew',2.5);
set( h,'tag','surface1'); % Optional
%------ Triangular Wave Function--------------%
function [ts,t,x]=track1(A,F)
NN=9001;
ts=1/NN;
t=linspace(0,1,NN);
x=A*sawtooth(2*pi*F*t,0.5);
h=plot(t,x,'linew',2);
set( h,'tag','surface1'); % Optional
ts=1/length(x);
%------ Swatooth Wave Function--------------%
function [ts,t,x]=sawto(A,F)
NN=9001;
ts=1/NN;
t=linspace(0,1,NN);
x=A*sawtooth(2*pi*F*t,1);
h=plot(t,x,'linew',2);
set( h,'tag','surface1'); % Optional
%-----------amardac-------------%
function [ts,x,y]=amardacM(newStrVal,A,F,fr)
%------for each popup button's value run respective function type-----%
if newStrVal==1
[ts,x,y]=sincurve(A,F);
elseif newStrVal==2
[ts,x,y]=coscurve(A,F);
elseif newStrVal==3
[ts,x,y]=squarew(A,F);
elseif newStrVal==4
[ts,x,y]=track1(A,F);
elseif newStrVal==5
[ts,x,y]=sawto(A,F);
end
function [ts,x,y]=amardacC(newStrValC,AC,FC,frC)
%------for each popup button's value run respective function type-----%
if newStrValC==1
[ts,x,y]=sincurve(AC,FC);
elseif newStrValC==2
[ts,x,y]=coscurve(AC,FC);
elseif newStrValC==3
[ts,x,y]=squarew(AC,FC);
elseif newStrValC==4
[ts,x,y]=track1(AC,FC);
elseif newStrValC==5
[ts,x,y]=sawto(AC,FC);
end
%%%%%----------------MODULATION SCHEMES-------------------%%%%%
function [ts,t,DSBFC]=DSBFCfun(XM,XC,t,Ac)
ts=1/length(t);
DSBFC=(1+(XM/Ac)).*XC;
function [ts,t,DSBSC]=DSBSCfun(XM,XC,t)
ts=1/length(t);
DSBSC=XM.*XC;
function [ts,t,SSBSC]=SSBSCLSB(XM,XC,t,F,FC)
ts=1/length(t);
DSBSC=XM.*XC;
Maxdsbsc=max(DSBSC);
Maxdsbsc(Maxdsbsc<=1)=4;
N=length(XM);
Wp=2*[FC-F FC-F+1]/N;
Ws=2*[FC-F-2 FC-F+2]/N;
Rp=log10(Maxdsbsc);
Rs=log10(Maxdsbsc+25);
[n,Wn]=cheb1ord(Wp,Ws,Rp,Rs);
[num den]=cheby1(n,Rp,Wn);
SSBSC=filter(num,den,DSBSC);
function [ts,t,SSBSC]=SSBSCUSB(XM,XC,t,F,FC)
ts=1/length(t);
DSBSC=XM.*XC;
Maxdsbsc=max(DSBSC);
Maxdsbsc(Maxdsbsc<=1)=4;
N=length(XM);
Wp=2*[FC+F FC+F+1]/N;
Ws=2*[FC+F-2 FC+F+2]/N;
Rp=log10(Maxdsbsc);
Rs=log10(Maxdsbsc+25);
[n,Wn]=cheb1ord(Wp,Ws,Rp,Rs);
[num den]=cheby1(n,Rp,Wn);
SSBSC=filter(num,den,DSBSC);
%-----------Spectrum Analyzer--------------%
function spectrum_analyzer(A,t,ts,str)
Lfft=length(t)/2;
Lfft=2^ceil(log2(Lfft));
B=fftshift(fft(A,Lfft))/Lfft;
w=(-Lfft/2:Lfft/2-1)/(Lfft*ts);
plot(w,abs(B),'linew',1);
xlabel('Frequency (Hz) ----> ');
ylabel('Magnitude ---->');
% grid on
title(sprintf('FREQUENCY DOMAIN MAGNITUDE SPECTRUM OF %s',str));
%%%%================================END================================%%%%
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!