⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chap1a.asv

📁 显示采样率的GUI源码
💻 ASV
字号:
function varargout = Chap1a(varargin)
% CHAP1A M-file for Chap1a.fig
%      CHAP1A, by itself, creates a new CHAP1A or raises the existing
%      singleton*.
%
%      H = CHAP1A returns the handle to a new CHAP1A or the handle to
%      the existing singleton*.
%
%      CHAP1A('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CHAP1A.M with the given input arguments.
%
%      CHAP1A('Property','Value',...) creates a new CHAP1A or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Chap1a_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Chap1a_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 Chap1a

% Last Modified by GUIDE v2.5 31-Jan-2007 19:18:02

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

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = Chap1a_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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if (get(handles.radiobutton2,'Value') == get(handles.radiobutton2,'Max')) % Verifies if Sine wave was selected
    t=linspace(0,1,60); % Creates the time variable from 0 to 1 with a length of 60 or 60 points
    y=sin(2*pi*t); % Creates a sine wave of frequency 1 with the t vector 
    axes(handles.axesanalog) % Select the proper axes  
    plot(t,y); 
    xlabel('Time');
    ylabel('Amplitud');
    grid on;
elseif (get(handles.radiobutton3,'Value') == get(handles.radiobutton3,'Max')) % Verifies if Random signal was selected
    t=linspace(0,60,60) % Creates the time variable from 0 to 60 with a length of 60 or 60 points
    y=rand([1 60]); % Creates a random signal of length 60 or with 60 points
    axes(handles.axesanalog) % Select the proper axes    
    plot(t,y);
    xlabel('Time');
    ylabel('Amplitud');
    grid on;
end
handles.amp=y; % Saves the input signal y in the amp variable at the handles structure
handles.time=t; % Saves the input signal t in the time variable at the handles structure
guidata(gcbo,handles); % Save the changes made to the handles structure


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close; % Close the application



% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if (get(handles.radiobutton4,'Value') == get(handles.radiobutton4,'Max'))
    t=handles.time; % recover the saved variable t from the handles structure
    y=handles.amp; % recover the saved variable y from the handles structure
    p=ones(1, length(t)); % creates a vector containing only ones 
    outideal=p.*y; % Multiplies the two vectors to get the output of an ideal sampler
    axes(handles.axessampled) % Select the proper axes
    stem(t,outideal,'ro');
    xlabel('Time');
    ylabel('Amplitud');
    grid on;
elseif (get(handles.radiobutton5,'Value') == get(handles.radiobutton5,'Max'))
    t=handles.time; % recover the saved variable t from the handles structure
    y=handles.amp; % recover the saved variable y from the handles structure
    p=ones(1, length(t)); % creates a vector containing only ones 
    outhold=p.*y; % Multiplies the two vectors to get the output of an ideal sampler
    axes(handles.axessampled) % Select the proper axes
    stairs(t,outhold,'r'); %Plot the signal in a stairs shape making it looks like a zero order hold sampler
    xlabel('Time');
    ylabel('Amplitud');
    grid on;
elseif (get(handles.radiobutton6,'Value') == get(handles.radiobutton6,'Max'))
    t=handles.time; % recover the saved variable t from the handles structure
    y=handles.amp; % recover the saved variable y from the handles structure
    test1=eval(get(handles.edit1,'String')); % Evals the value that is contained in the Edit 1
    if isnan(test1) % Test if it is a number or not. If not it displays an error message
        errordlg('You must enter a numeric value','Bad Input','modal')
    end
    lenp=length(t)/length(test1); %Calculates the length of the vector so it can make it a periodic signal with the 
    %right size so it can work properly
    p=ones(1, lenp); %  Creates a vector of only ones of lenght lenp 
    per=test1'*p; % Creates a 
    per=per(:);
    disp(size(per))
    disp(size(y))
    outnormal=per'.*y;
    axes(handles.axessampled) % Select the proper axes
    plot(t,outnormal,'r');
    xlabel('Time');
    ylabel('Amplitud');
    grid on;    
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


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 radiobutton6.
function radiobutton6_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton6
if (get(handles.radiobutton6,'Value') == get(handles.radiobutton6,'Max'))    
    set(handles.edit1,'Enable', 'on');
end


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -