{"id":7855,"date":"2016-10-07T09:00:08","date_gmt":"2016-10-07T13:00:08","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=7855"},"modified":"2017-08-27T19:50:20","modified_gmt":"2017-08-27T23:50:20","slug":"data-acquisition-tool","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2016\/10\/07\/data-acquisition-tool\/","title":{"rendered":"Data Acquisition Tool"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <introduction>\r\n      <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495\">Sean<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44234-data-acquisition\">Data Acquisition Tool<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/471214\">Isaac Noh<\/a>.\r\n      <\/p>\r\n   <\/introduction>\r\n\r\n   <h3>Data Acquisition Hardware<a name=\"1\"><\/a><\/h3>\r\n   <p>Have you ever wanted to bring data directly from hardware into MATLAB or control something via a data acquisition board?<\/p>\r\n   <p>Working with data acquisition hardware was my very first project in MATLAB back in the winter of 2008.  I had a miniature\r\n      load frame, transparent to x-rays, for applying a load to a concrete cylinder. There were three sensor inputs: two displacements,\r\n      and force, and one output: a voltage to a piezoelectric actuator that applied a force.  Here's a figure from my thesis:\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/maindaqtool\/loadframe.png\"> <\/p>\r\n   <p>I built a user interface in GUIDE to allow me to apply the load while recording and plotting the signals.  To complicate matters,\r\n      the session based interface for the <a href=\"https:\/\/www.mathworks.com\/products\/daq\/\">Data Acquisition Toolbox<\/a> didn't exist yet, so I was also doing everything with timers on my own.\r\n   <\/p>\r\n   <p>I can only imagine how much easier it would've been with this app.  I no longer have access to the load frame, so instead\r\n      here's an example getting data from an <a href=\"http:\/\/www.analog.com\/en\/design-center\/evaluation-hardware-and-software\/evaluation-boards-kits\/Eval-ADALM1000.html#eb-overview\">ADALM1000<\/a>, a low cost data acquisition device.\r\n   <\/p>\r\n   <p>Let's control it with the app.  First, I'll just get connected and pull some data from the attached RC circuit.  Note I previously\r\n      had to <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/supportpackageinstaller.html (link no longer works)\">install the hardware support package<\/a> for this board.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/maindaqtool\/setup.png\"> <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/maindaqtool\/firstacq.png\"> <\/p>\r\n   <p>Seems to work, great!<\/p>\r\n   <p>Now I want to output some data to it.  There are two channels, the first will be a sine wave and the second a cosine wave.\r\n       The board can take 0-5V so add 1 to the waves keep them positive.\r\n   <\/p><pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid rgb(200,200,200)\">t = linspace(0,8*pi,100000)';\r\nx = [sin(t) cos(t)]+1; <span style=\"color: #228B22\">%<\/span><\/pre><p>In order to get them into the output, we simply pick the variable:<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/maindaqtool\/pickx.png\"> <\/p>\r\n   <p>And then run the session:<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/maindaqtool\/acqx.png\"> <\/p>\r\n   <p>From here, the data can be exported or equivalent code can be generated from the file menu to automate this acquisition session.<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/maindaqtool\/generatedcode.png\"> <\/p>\r\n   <p>My only point of feedback is that error messages are not all exposed via dialogs.  For example, the first time I selected\r\n      <i>x<\/i> with the range -1:1, it errored at the command line with a useful message that I didn't see because the app was maximized.\r\n   <\/p>\r\n   <p>Going back to my use case in college, I was trying to control load, with displacement so that the loading rate would be roughly\r\n      linear.  To do this, I ran a bunch of experiments and fit an equation to the load v. displacement curve for many cylinders.\r\n       At the time, I knew nothing about <a href=\"https:\/\/www.mathworks.com\/products\/simulink\/\">Simulink<\/a> or how it could help me.  If challenged with the same task today, I would likely use the <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/daq\/examples\/live-data-acquisition-signal-processing-and-data-output.html (link no longer works)\">data acquisition blocks<\/a> in Simulink R2016b to control the actuator. This would allow me to then use the PID block and its tuning capabilities to\r\n      accomplish what I was doing much more quickly.\r\n   <\/p>\r\n   <p>For nostalgia's sake, I put together a quick a model of the system.<\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/Sean\/maindaqtool\/simulinkex.png\"> <\/p>\r\n   <h3>Comments<a name=\"3\"><\/a><\/h3>\r\n   <p>Do you work with data acquisition hardware?  Give it a try and let us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=7855#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44234-data-acquisition#comments\">comment<\/a> for Isaac.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_83705298530740468ba0cdc33642f4cf() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='83705298530740468ba0cdc33642f4cf ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 83705298530740468ba0cdc33642f4cf';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Sean de Wolski';\r\n        copyright = 'Copyright 2016 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_83705298530740468ba0cdc33642f4cf()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2016b<br><\/p>\r\n<\/div>\r\n<!--\r\n83705298530740468ba0cdc33642f4cf ##### SOURCE BEGIN #####\r\n%% Data Acquisition Tool\r\n%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/3208495 Sean>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44234-data-acquisition Data Acquisition Tool> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/profile\/authors\/471214 Isaac Noh>.\r\n% \r\n\r\n%% Data Acquisition Hardware\r\n% Have you ever wanted to bring data directly from hardware\r\n% into MATLAB or control something via a data acquisition board?\r\n%\r\n% Working with data acquisition hardware was my very first project in\r\n% MATLAB back in the winter of 2008.  I had a miniature load frame,\r\n% transparent to x-rays, for applying a load to a concrete cylinder. There\r\n% were three sensor inputs: two displacements, and force, and one output: a\r\n% voltage to a piezoelectric actuator that applied a force.  Here's a\r\n% figure from my thesis:\r\n%\r\n% <<loadframe.png>>\r\n% \r\n% I built a user interface in GUIDE to allow me to apply the load while\r\n% recording and plotting the signals.  To complicate matters, the\r\n% <https:\/\/www.mathworks.com\/help\/daq\/about-the-session-based-interface.html\r\n% session based interface> for the <https:\/\/www.mathworks.com\/products\/daq\/\r\n% Data Acquisition Toolbox> didn't exist yet, so I was also doing\r\n% everything with timers on my own.\r\n%\r\n% I can only imagine how much easier it would've been with this app.  I no\r\n% longer have access to the load frame, so instead here's an example\r\n% getting data from an\r\n% <http:\/\/www.analog.com\/en\/design-center\/evaluation-hardware-and-software\/evaluation-boards-kits\/Eval-ADALM1000.html#eb-overview\r\n% ADALM1000>, a low cost data acquisition device.\r\n%\r\n% Let's control it with the app.  First, I'll just get connected and pull\r\n% some data from the attached RC circuit.  Note I previously had to\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/matlab\/ref\/supportpackageinstaller.html\r\n% install the hardware support package> for this board.\r\n%\r\n% <<setup.png>>\r\n%\r\n% <<firstacq.png>>\r\n%\r\n% Seems to work, great!\r\n%\r\n% Now I want to output some data to it.  There are two channels, the first\r\n% will be a sine wave and the second a cosine wave.  The board can take\r\n% 0-5V so add 1 to the waves keep them positive.\r\n%\r\n\r\nt = linspace(0,8*pi,100000)';\r\nx = [sin(t) cos(t)]+1; %\r\n\r\n%%\r\n% In order to get them into the output, we simply pick the variable:\r\n%\r\n% <<pickx.png>>\r\n%\r\n% And then run the session:\r\n%\r\n% <<acqx.png>>\r\n%\r\n% From here, the data can be exported or equivalent code can be generated\r\n% from the file menu to automate this acquisition session.\r\n%\r\n% <<generatedcode.png>>\r\n%\r\n% My only point of feedback is that error messages are not all exposed via\r\n% dialogs.  For example, the first time I selected _x_ with the range -1:1,\r\n% it errored at the command line with a useful message that I didn't see\r\n% because the app was maximized.\r\n%\r\n% Going back to my use case in college, I was trying to control load, with\r\n% displacement so that the loading rate would be roughly linear.  To do\r\n% this, I ran a bunch of experiments and fit an equation to the load v.\r\n% displacement curve for many cylinders.  At the time, I knew nothing about\r\n% <https:\/\/www.mathworks.com\/products\/simulink\/ Simulink> or how it could\r\n% help me.  If challenged with the same task today, I would likely use the\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2016b\/daq\/examples\/live-data-acquisition-signal-processing-and-data-output.html\r\n% data acquisition blocks> in Simulink R2016b to control the actuator.\r\n% This would allow me to then use the PID block and its tuning capabilities\r\n% to accomplish what I was doing much more quickly.\r\n%\r\n% For nostalgia's sake, I put together a quick a model of the system.\r\n%\r\n% <<simulinkex.png>>\r\n\r\n%% Comments\r\n% \r\n% Do you work with data acquisition hardware?  Give it a try and let us\r\n% know what you think <https:\/\/blogs.mathworks.com\/pick\/?p=7855#respond\r\n% here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/44234-data-acquisition#comments\r\n% comment> for Isaac.\r\n%\r\n \r\n\r\n##### SOURCE END ##### 83705298530740468ba0cdc33642f4cf\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/acqx.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\n   \r\n      Sean's pick this week is Data Acquisition Tool by Isaac Noh.\r\n      \r\n   \r\n\r\n   Data Acquisition Hardware\r\n   Have you ever wanted to bring data directly from hardware into MATLAB or... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2016\/10\/07\/data-acquisition-tool\/\">read more >><\/a><\/p>","protected":false},"author":87,"featured_media":7862,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[25,16,6,24],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/7855"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/87"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=7855"}],"version-history":[{"count":4,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/7855\/revisions"}],"predecessor-version":[{"id":8835,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/7855\/revisions\/8835"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/7862"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=7855"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=7855"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=7855"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}