{"id":158,"date":"2016-02-12T00:20:57","date_gmt":"2016-02-12T00:20:57","guid":{"rendered":"http:\/\/weegreenblobbie.com\/?p=158"},"modified":"2016-02-12T00:20:57","modified_gmt":"2016-02-12T00:20:57","slug":"listening-to-gravity-waves-with-nsound","status":"publish","type":"post","link":"http:\/\/weegreenblobbie.com\/?p=158","title":{"rendered":"Listening to Gravity Waves with Nsound!"},"content":{"rendered":"<h1>Gravity Wave Signal Processing<\/h1>\n<p>With all the excitement about LIGO and gravity waves, I&#8217;ve downloaded the raw GW150914 detection data for\u00a0from <a href=\"https:\/\/losc.ligo.org\/events\/GW150914\/\" target=\"_blank\">here<\/a>. \u00a0The file I downloaded was 32 seconds sampled at 4096 samples per second.<\/p>\n<p>Next I reviewed some of the LIGO\u00a0tutorial on signal processing <a href=\"https:\/\/losc.ligo.org\/s\/events\/GW150914\/GW150914_tutorial.html\" target=\"_blank\">here<\/a>, and proceeded to write a Python script using Nsound to process the data. \u00a0Talk about finding a needle in a haystack!<\/p>\n<p>Raw time-series data plot, the detection event occurs around 16.5 seconds in this plot:<\/p>\n<p><a href=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_raw_time.png\" rel=\"attachment wp-att-159\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-159\" src=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_raw_time-1024x341.png\" alt=\"gwav_raw_time\" width=\"1024\" height=\"341\" srcset=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_raw_time-1024x341.png 1024w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_raw_time-300x100.png 300w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_raw_time-768x256.png 768w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_raw_time.png 1586w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>Where&#8217;s the signal? \u00a0It&#8217;s buried in noise! \u00a0Mostly low frequencies. \u00a0But with the help of a band pass filter from 80 to 280 Hz, we can get a hint of the signal:<\/p>\n<p><a href=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_filtered_time.png\" rel=\"attachment wp-att-160\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-large wp-image-160\" src=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_filtered_time-1024x419.png\" alt=\"gwav_filtered_time\" width=\"1024\" height=\"419\" srcset=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_filtered_time-1024x419.png 1024w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_filtered_time-300x123.png 300w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_filtered_time-768x314.png 768w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwav_filtered_time.png 1372w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/p>\n<p>Zooming in:<\/p>\n<p><a href=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_time.png\" rel=\"attachment wp-att-161\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-161\" src=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_time.png\" alt=\"gwave_time\" width=\"812\" height=\"612\" srcset=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_time.png 812w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_time-300x226.png 300w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_time-768x579.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/a><\/p>\n<p>Plotting the spectrogram:<\/p>\n<p><a href=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_spec.png\" rel=\"attachment wp-att-162\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-162\" src=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_spec.png\" alt=\"gwave_spec\" width=\"812\" height=\"612\" srcset=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_spec.png 812w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_spec-300x226.png 300w, http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/gwave_spec-768x579.png 768w\" sizes=\"auto, (max-width: 812px) 100vw, 812px\" \/><\/a><\/p>\n<h2>Audio<\/h2>\n<p>And finally, we can listen to the\u00a0universe! \u00a0The detection is a single blip as show above, however for your listening pleasure I&#8217;ve repeated the blip 4\u00a0times:<\/p>\n<audio class=\"wp-audio-shortcode\" id=\"audio-158-1\" preload=\"none\" style=\"width: 100%;\" controls=\"controls\"><source type=\"audio\/wav\" src=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/out.wav?_=1\" \/><a href=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/out.wav\">http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/out.wav<\/a><\/audio>\n<p>Link to the .wav <a href=\"http:\/\/weegreenblobbie.com\/wp-content\/uploads\/2016\/02\/out.wav\">here<\/a>.<\/p>\n<h1><strong>Python Code<\/strong><\/h1>\n<p>Here is the Python code I used which uses my Nsound Python library:<\/p>\n<pre class=\"lang:python decode:true \" title=\"Process GW150914\">\"\"\"\r\nReads in the LIGO gravity wave data for GW150914, a file named\r\n'H-H1_LOSC_4_V1-1126259446-32.txt', and performs a band pass filter from 80 to\r\n280 Hz. The data are then written out to a .wav file so it can be played on a\r\ncomputer.\r\n\r\nBy Nick Hilton\r\n2016-02-11\r\n\"\"\"\r\n\r\nimport Nsound as ns\r\nplt = ns.Plotter()\r\n\r\n#------------------------------------------------------------------------------\r\n# read in time series data\r\n\r\nwith open('H-H1_LOSC_4_V1-1126259446-32.txt', 'r') as fd:\r\n    lines = fd.readlines()\r\n\r\nsr = 4096.0\r\n\r\na = ns.AudioStream(sr, 1)\r\n\r\nfor l in lines:\r\n    l = l.strip()\r\n\r\n    # skip comments\r\n    if l.startswith('#'):\r\n        continue\r\n\r\n    s = float(l)\r\n\r\n    a &lt;&lt; s\r\n\r\na.normalize()\r\n\r\n# The data don't start and end at zero so there's an initial step function, which\r\n# causes a big spike in the spectrogram.  So I'm going to apply a Gaussian\r\n# window to smooth the start and stop of the data.\r\n\r\ndur = a.getDuration()\r\n\r\ngen = ns.Generator(sr)\r\n\r\ngau = gen.drawFatGaussian(dur, 0.99)\r\n\r\nwhile len(gau) &lt; len(a):\r\n    gau &lt;&lt; 0.0\r\n\r\na *= gau\r\n\r\n#-----------------------------------------------------------------------------\r\n# band pass filter to region of interest\r\n\r\nbpf = ns.FilterBandPassIIR(sr, 5, 80, 280, 0.01)\r\n\r\na2 = bpf.filter(a)\r\n\r\na2.normalize()\r\n\r\na2.plot('Filtered Time Series GW150914')\r\n\r\nplt.show()\r\n\r\n#-----------------------------------------------------------------------------\r\n# spectrogram\r\n\r\nspec = ns.Spectrogram(a2[0], sr, 0.0625, 0.0039, ns.PARZEN)\r\nspec.plot('Gravity Freakin\\' Waves!', False, 0.5)\r\n\r\n# zoom in on region\r\nplt.xlim(16.15, 16.63)\r\nplt.ylim(15, 460)\r\n\r\na2.plot('Time Domain Signal')\r\n\r\n# zoom in on region\r\nplt.xlim(16.15, 16.63)\r\n\r\n#------------------------------------------------------------------------------\r\n# pull out 2 second around the gravity wave and repeat it several times for\r\n# playback\r\n\r\na3 = a2.substream(16.0, 2.0)\r\n\r\n# remove any step function around the edges\r\n\r\ngau = gen.drawFatGaussian(2.0, 0.99)\r\n\r\nwhile len(gau) &lt; len(a3):\r\n    gau &lt;&lt; 0.0\r\n\r\na3 *= gau\r\n\r\na3 &lt;&lt; a3 &lt;&lt; a3\r\n\r\na3 &gt;&gt; \"out.wav\"\r\n\r\nns.Plotter.show()\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Gravity Wave Signal Processing With all the excitement about LIGO and gravity waves, I&#8217;ve downloaded the raw GW150914 detection data for\u00a0from here. \u00a0The file I downloaded was 32 seconds sampled at 4096 samples per second. Next I reviewed some of &hellip; <a href=\"http:\/\/weegreenblobbie.com\/?p=158\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,3,7,8],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-computing","category-nsound","category-programming","category-science"],"_links":{"self":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":8,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":171,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions\/171"}],"wp:attachment":[{"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/weegreenblobbie.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}