Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function varargout = Lab2(varargin)
- % LAB2 MATLAB code for Lab2.fig
- % LAB2, by itself, creates a new LAB2 or raises the existing
- % singleton*.
- %
- % H = LAB2 returns the handle to a new LAB2 or the handle to
- % the existing singleton*.
- %
- % LAB2('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in LAB2.M with the given input arguments.
- %
- % LAB2('Property','Value',...) creates a new LAB2 or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before Lab2_OpeningFcn gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to Lab2_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 Lab2
- % Last Modified by GUIDE v2.5 16-Mar-2022 21:28:07
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @Lab2_OpeningFcn, ...
- 'gui_OutputFcn', @Lab2_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 Lab2 is made visible.
- function Lab2_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 Lab2 (see VARARGIN)
- % Choose default command line output for Lab2
- handles.output = hObject;
- % Update handles structure
- guidata(hObject, handles);
- % UIWAIT makes Lab2 wait for user response (see UIRESUME)
- % uiwait(handles.figure1);
- % --- Outputs from this function are returned to the command line.
- function varargout = Lab2_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;
- function edit2_Callback(hObject, eventdata, handles)
- % hObject handle to edit2 (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 edit2 as text
- % str2double(get(hObject,'String')) returns contents of edit2 as a double
- % --- Executes during object creation, after setting all properties.
- function edit2_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit2 (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
- function edit3_Callback(hObject, eventdata, handles)
- % hObject handle to edit3 (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 edit3 as text
- % str2double(get(hObject,'String')) returns contents of edit3 as a double
- % --- Executes during object creation, after setting all properties.
- function edit3_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit3 (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
- 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
- function edit6_Callback(hObject, eventdata, handles)
- % hObject handle to edit6 (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 edit6 as text
- % str2double(get(hObject,'String')) returns contents of edit6 as a double
- % --- Executes during object creation, after setting all properties.
- function edit6_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit6 (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
- function edit7_Callback(hObject, eventdata, handles)
- % hObject handle to edit7 (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 edit7 as text
- % str2double(get(hObject,'String')) returns contents of edit7 as a double
- % --- Executes during object creation, after setting all properties.
- function edit7_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit7 (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 pushbutton1.
- function pushbutton7_Callback(hObject, eventdata, handles)
- handles.StopAkvizicija=0;
- guidata(hObject,handles);
- Kanal = str2num(get(handles.edit1,'String'))
- Trajanje = str2num(get(handles.edit3,'String'))
- sempl = str2num(get(handles.edit2,'String'))
- refresh=str2double(get(handles.edit8,'String'))
- AI = analoginput('mcc',0);
- addchannel(AI,Kanal);
- % set(AI,'SampleRate',sempl);
- % set(AI,'SamplesPerTrigger',Trajanje*sempl);
- AI.SampleRate=sempl;
- AI.SamplesPerTrigger=AI.SampleRate*Trajanje;
- start(AI);
- axes(handles.axes1);
- cla reset;
- grid on;
- xlabel('Vrijeme sec.');
- ylabel('Amplituda');
- title('Akvizicija signala');
- ylim([0 5]);%%Podeševat u oisnosti od ocekivanog ulaza
- hold on;
- i=0;%%vrijeme
- %isrunning(AI)
- while isrunning(AI) && i<=Trajanje && handles.StopAkvizicija==0
- tic
- data=peekdata(AI,fix(refresh*AI.SampleRate));
- [m,~]=size(data);
- t=linspace(i,i+refresh,m);
- if (i>=refresh)
- xlim([i-refresh i]);
- end
- plot(t',data);
- time=toc;
- i=i+refresh;
- pause(refresh-time);
- handles = guidata(hObject);
- drawnow
- end
- hold off
- delete AI
- % --- Executes on button press in pushbutton3.
- function pushbutton3_Callback(hObject, eventdata, handles)
- handles.StopGenSignal = 0;
- guidata(hObject,handles);
- amp=str2double(get(handles.edit7,'String'));
- frek=str2double(get(handles.edit6,'String'));
- Trajanje=str2double(get(handles.edit9,'String'));
- %A0=analogoutput('mcc',0);%%Vjezba
- A0=analogoutput('winsound');%%Kuca
- addchannel(A0,1) % Definiranje kanala koji ?e se koristiti (mono)
- set(A0,'SampleRate',8000) % Postavljanje brzine uzorkovanja:
- t=0:1/8000:Trajanje-1/8000;
- y=amp*sin(2*pi*frek.*t)+amp;
- cla reset;
- axes(handles.axes2);
- plot(t,y-amp);
- xlabel('Vrijeme [sec]');
- ylabel('Amplituda [V]');
- title('Generisani signal');
- hold on;
- grid on;
- putdata(A0,y');
- start(A0);
- tic;
- time=0;
- while toc<Trajanje && handles.StopGenSignal==0
- xlim([time toc]);%%Pomjeranje ose
- time=toc;
- handles = guidata(hObject);%%Update
- pause(0.1);%%Simbolicna pauza da mozemo osvjeziti stopgensignal
- end
- stop(A0);
- function pushbutton5_Callback(hObject, eventdata, handles)
- handles.StopGenSignal = 1;
- guidata(hObject,handles);
- pause(0.1);
- % 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)
- % --- Executes on button press in pushbutton6.
- function pushbutton6_Callback(hObject, eventdata, handles)
- handles.StopAkvizicija=1;
- guidata(hObject,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)
- function edit8_Callback(hObject, eventdata, handles)
- % hObject handle to edit8 (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 edit8 as text
- % str2double(get(hObject,'String')) returns contents of edit8 as a double
- % --- Executes during object creation, after setting all properties.
- function edit8_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit8 (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
- function edit9_Callback(hObject, eventdata, handles)
- % hObject handle to edit9 (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 edit9 as text
- % str2double(get(hObject,'String')) returns contents of edit9 as a double
- % --- Executes during object creation, after setting all properties.
- function edit9_CreateFcn(hObject, eventdata, handles)
- % hObject handle to edit9 (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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement