{"id":5332,"date":"2014-05-23T09:00:42","date_gmt":"2014-05-23T13:00:42","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/?p=5332"},"modified":"2017-05-04T11:07:42","modified_gmt":"2017-05-04T15:07:42","slug":"automatic-activity-detection-using-hilbert-transform","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2014\/05\/23\/automatic-activity-detection-using-hilbert-transform\/","title":{"rendered":"Automatic activity detection using Hilbert transform"},"content":{"rendered":"<div class=\"content\">\r\n\r\n<a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46139-automatic-enveloping--variance-change-and-activity-detection-with-hilbert-transform\">\"Automatic enveloping, variance change and activity detection with Hilbert Transform\"<\/a> by <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/151595\">Hooman Sedghamiz<\/a>.\r\n\r\nThis entry by Hooman brought back memories from my graduate school days. Back then, I was involved with experimental biomechanics.\r\nOne of the types of measurements I took was <a href=\"http:\/\/en.wikipedia.org\/wiki\/Electromyography\">EMG (electromyography)<\/a>, which represents muscle activity. Depending on the quality and the placement of the sensors, the measured signals can vary\r\ngreatly in quality. From the EMG, I needed to determine the frequency and the duration of the muscle activations. Back then,\r\nI investigated a few different methods, ranging from manual inspection to using signal processing techniques with <a href=\"http:\/\/en.wikipedia.org\/wiki\/Wavelet\">wavelets<\/a>. That was when I really got to learn and use the <a href=\"https:\/\/www.mathworks.com\/products\/wavelet\/\">Wavelet Toolbox<\/a>.\r\n\r\nThis function by Hooman would have certainly helped me with this task. It uses <a href=\"http:\/\/en.wikipedia.org\/wiki\/Hilbert_transform\">Hilbert transform<\/a>, smoothing, and adaptive thresholding to identify the activations of the signal. The function has a few parameters you can\r\nspecify:\r\n<div>\r\n<ul>\r\n\t<li>(2nd input) Smoothing window length<\/li>\r\n\t<li>(3rd input) Whether or not to use adaptive thresholding<\/li>\r\n\t<li>(4th input) Minimum number of samples where the signal needs to stay above the threshold in order to be considered active<\/li>\r\n\t<li>(5th input) Whether or not to create a summary plot<\/li>\r\n<\/ul>\r\n<\/div>\r\n<pre style=\"background: #F9F7F3; padding: 10px; border: 1px solid #c8c8c8;\">load <span style=\"color: #a020f0;\">data<\/span>\r\n\r\nact = envelop_hilbert_v2(sig,20,true,20,false);\r\n\r\nplot(sig)\r\nhold <span style=\"color: #a020f0;\">on<\/span>\r\nplot(act,<span style=\"color: #a020f0;\">'r'<\/span>)\r\nlegend(<span style=\"color: #a020f0;\">'Raw signal'<\/span>,<span style=\"color: #a020f0;\">'Activations'<\/span>)<\/pre>\r\n<img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/jiro\/potw_activitydetection\/potw_activitydetection_01.png\" alt=\"\" hspace=\"5\" vspace=\"5\" \/>\r\n\r\n&nbsp;\r\n\r\n<b>Comments<\/b>\r\n\r\nLet us know what you think <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=5332#respond\">here<\/a> or leave a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46139-automatic-enveloping--variance-change-and-activity-detection-with-hilbert-transform#comments\">comment<\/a> for Hooman.\r\n\r\n<script>\/\/ <![CDATA[\r\nfunction grabCode_bedd08e8966b4fc7963e23fe2ad39a9e() {\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='bedd08e8966b4fc7963e23fe2ad39a9e ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' bedd08e8966b4fc7963e23fe2ad39a9e';\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 = '';\r\n        copyright = 'Copyright 2014 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('\r\n\r\n<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>\r\n\r\n\r\n\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }\r\n\/\/ ]]><\/script>\r\n<p style=\"text-align: right; font-size: xx-small; font-weight: lighter; font-style: italic; color: gray;\">\r\n<a><span style=\"font-size: x-small; font-style: italic;\">Get\r\nthe MATLAB code\r\n<noscript>(requires JavaScript)<\/noscript><\/span><\/a>\r\n\r\nPublished with MATLAB\u00ae R2014a<\/p>\r\n\r\n<\/div>\r\n<!--\r\nbedd08e8966b4fc7963e23fe2ad39a9e ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007 % Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46139-automatic-enveloping--variance-change-and-activity-detection-with-hilbert-transform \"Automatic % enveloping, variance change and activity detection with Hilbert % Transform\"> by\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/151595 % Hooman Sedghamiz>.\r\n%\r\n% This entry by Hooman brought back memories from my graduate school days.\r\n% Back then, I was involved with experimental biomechanics. One of the\r\n% types of measurements I took was\r\n% <http:\/\/en.wikipedia.org\/wiki\/Electromyography EMG (electromyography)>,\r\n% which represents muscle activity. Depending on the quality and the\r\n% placement of the sensors, the measured signals can vary greatly in\r\n% quality. From the EMG, I needed to determine the frequency and the\r\n% duration of the muscle activations. Back then, I investigated a few\r\n% different methods, ranging from manual inspection to using signal\r\n% processing techniques with <http:\/\/en.wikipedia.org\/wiki\/Wavelet % wavelets>. That was when I really got to learn and use the\r\n% <https:\/\/www.mathworks.com\/products\/wavelet\/ Wavelet Toolbox>.\r\n%\r\n% This function by Hooman would have certainly helped me with this task. It\r\n% uses <http:\/\/en.wikipedia.org\/wiki\/Hilbert_transform Hilbert transform>,\r\n% smoothing, and adaptive thresholding to identify the activations of the\r\n% signal. The function has a few parameters you can specify:\r\n%\r\n% * (2nd input) Smoothing window length\r\n% * (3rd input) Whether or not to use adaptive thresholding\r\n% * (4th input) Minimum number of samples where the signal needs to stay\r\n% above the threshold in order to be considered active\r\n% * (5th input) Whether or not to create a summary plot\r\n\r\nload data\r\n\r\nact = envelop_hilbert_v2(sig,20,true,20,false);\r\n\r\nplot(sig)\r\nhold on\r\nplot(act,'r')\r\nlegend('Raw signal','Activations')\r\n\r\n%%\r\n% If you ask for a summary plot, it generates the following plot.\r\n%\r\n% <html>\r\n% <img decoding=\"async\" % src=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/screenshots\/20819\/original.jpg\" % width=700>\r\n% <\/html>\r\n%\r\n% *Comments*\r\n%\r\n% Let us know what you think\r\n% <https:\/\/blogs.mathworks.com\/pick\/?p=5332#respond here> or leave a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/46139-automatic-enveloping--variance-change-and-activity-detection-with-hilbert-transform#comments % comment> for Hooman.\r\n\r\n##### SOURCE END ##### bedd08e8966b4fc7963e23fe2ad39a9e\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/pick\/files\/potw_activitydetection_01.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\n\r\nJiro's pick this week is \"Automatic enveloping, variance change and activity detection with Hilbert Transform\" by Hooman Sedghamiz.\r\n\r\nThis entry by Hooman brought back memories from my graduate... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2014\/05\/23\/automatic-activity-detection-using-hilbert-transform\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":8571,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5332"}],"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\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=5332"}],"version-history":[{"count":7,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5332\/revisions"}],"predecessor-version":[{"id":7270,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/5332\/revisions\/7270"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media\/8571"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=5332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=5332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=5332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}