A demo video is shown below to put the potentials of the SVL suite into prospective. The video shows the SVL suite being used in examining the signals sampling and reconstruction. One major improvement when compare to the SVL suite's first release is the fact that users can draw connections between devices as if they were using Simulink, however, the customized characteristics of the individual GUI remains. In other words, the SVL suite utilizes the connection functionality of Simulink, but retains the same GUI for each device.
In the video, the function generator output is fed to a signal splitter, with one splitter output going to the oscilloscope, and the other going into the sampling box. One by one, the sampling waveform and the sampled signal are examined using the oscilloscope. To reconstruct the original signal, the sampled signal then goes through a low-pass filter. Spectrum of the various signals are observed.
Note that as long as the function generator and oscilloscope are used, any Signals lab can be transformed into the virtual lab if the corresponding signal processing components are created.
In the third tutorial of the series, we will look at a walk-around for the missing mouse over function for the uicontrols. We will be coding in the WindowButtonMotionFcn callback. Whenever the mouse moves in the figure, we will capture the mouse location, capture the boundaries of the uicontrol, and finally, determine whether the mouse is over the uicontrol or not.
Step-by-step guide 1. Download mouse2.zip and ready the files in a working folder in MATLAB. 2. Add a static text to the GUI, rename its tag to lbl_target and set its unit to pixel 3. Copy and paste the following code to the end of the WindowButtonMotionFcn
% get position information of the uicontrol bounds = get(handles.lbl_target,'position'); lx = bounds(1); ly = bounds(2); lw = bounds(3); lh = bounds(4); % test to see if mouse is within the uicontrol. if x >= lx && x <= (lx + lw) && y >= ly && y <= (ly + lh) set(handles.lbl_target, 'string', 'IN'); set(handles.lbl_target, 'backgroundcolor', 'red'); else set(handles.lbl_target,'string', 'OUT'); set(handles.lbl_target, 'backgroundcolor', 'green'); end
In the second tutorial of the series, we will look at how we can track the mouse actions such as pressing and releasing. We will start with the GUI we created in the first tutorial, and we will add a text field that details the last mouse action and its location.
Step-by-step guide
1. Download mouse1.zip, and ready the files in a working folder of MATLAB.
2. Open gui_mouse.fig using GUIDE.
3. Add a static text to the GUI and rename its tag to lbl_last_action
4. Open the property window of the figure (double click on the figure), click on WindowButtonDownFcn to populate the callback and paste the following code: pos = get(hObject, 'currentpoint'); % get mouse location on figure x = pos(1); y = pos(2); % assign locations to x and y set(handles.lbl_last_action, 'string', ['Mouse pressed @ X: ', num2str(x), ', Y: ', num2str(y)]);5. Click on WindowButtonUpFcnto populate the callback and paste the following code: pos = get(hObject, 'currentpoint'); % get mouse location on figure x = pos(1); y = pos(2); % assign locations to x and y set(handles.lbl_last_action, 'string', ['Mouse released @ X: ', num2str(x), ', Y: ', num2str(y)]);
6. Press F5 (or click on run button) to start up the GUI.
Anytime when the mouse is pressed (down) or released (up), the text field is updated with the action and the location of the action. Note that if the button is released quickly after pressed, the text field may be updated too quickly as if there is no press action.
Video
Files:
Files can be downloaded here. Note some changes have been made to the GUI to make it more presentable.
This is a brief tutorial on how to insert background image to push button and toggle button in MATLAB GUI. The idea is simple, read in the background image as a matrix, and then assign the matrix to CData property to the buttons.
1. Create a new GUI in MATLAB using GUIDE, and save the file.
2. Add uicontrols push button (or toggle button), rename their tag as pb (or tb).
3. In the OpeningFcn in the corresponding m-file, copy and paste the following code:
Note, you may want to set pixel as the figure's unit so that you can easily figure out the size of the button that will show you the entire background image. In other words, the size of the button and the size of the background image should match.
pos = get(hObject, 'currentpoint'); % get mouse location on figure x = pos(1); y = pos(2); % assign locations to x and y set(handles.lbl_x, 'string', ['x loc:' num2str(x)]); % update text for x loc set(handles.lbl_y, 'string', ['y loc:' num2str(y)]); % update text for y loc
Save all files and run the GUI or M-file.
Note: anytime the mouse is moved over the GUI, it will trigger the WindowButtonMotionFcn on the figure, which will then update the labels with the current location of the mouse pointer on the figure.
I am planning to create a tutorial series on how to incorporate mouse movements and actions into MATLAB GUI. Traditionally, the GUIs are designed to accept user input via a variety of uicontrols (or components). While having the components are sufficient in most applications, there are still cases where the user experience may be drastically enhanced by utilizing mouse movements and actions.
The end-product of the series is a GUI that allows user dragging and dropping an object in the GUI. The series will contain a number of tutorials, each dealing with a specific subject (or sub-problem). Each tutorial will be built on the earlier tutorials, either provides a different functionality or a more advance usage of the same functionality (or both).
The series of tutorials may cover the following topics (subject to change)
My submission of SVL Suite to MATLAB Central File Exchange was rejected. The reason for the rejection is because my submission contains p-files. Having the p-files, which hides the source code, kind of defeats the purpose of File Exchange, which is to allow users to learn from each other by looking at the source code. It is fair, but I wish they had spelled it out in their Guidelines for New Submissions.
In any case, I believe SVL suite is a very useful application/learning tool and I am determined to at least try to give it a bit of exposure on the Internet. And therefore, I updated the project website I created for the SVL Suite (in 2010), and package up the first release for download. I also submitted the link of the project website to the Link Exchange on MATLAB Central. Let's see where it takes us.
Signals Virtual Lab (SVL) Suite is a collection of MATLAB GUIs that was developed for the introductory Signals course at the University of New Brunswick. The goal of the suite is to provide students with a good learning experience while maintaining the look-and-feel of the equipment used in the lab.
The video below shows a brief and basic demo of the Signal Virtual Lab Suite. It involves connecting the function generator to the oscilloscope, changing parameters of the input signal, changing the display parameters on the oscilloscope, and finally, computing and displaying the spectrum of the input signal. Cursors are also used in the demo as to measure magnitudes and frequencies of data points on the spectrum.