{"id":2349,"date":"2021-08-21T20:59:22","date_gmt":"2021-08-21T18:59:22","guid":{"rendered":"https:\/\/aerospaceresearch.net\/?p=2349"},"modified":"2021-08-23T19:26:02","modified_gmt":"2021-08-23T17:26:02","slug":"gsoc2021-calibratesdr-gsm-support","status":"publish","type":"post","link":"https:\/\/aerospaceresearch.net\/?p=2349","title":{"rendered":"[GSoC2021] CalibrateSDR GSM Support"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Overview<\/h2>\n\n\n\n<p><strong>CalibrateSDR<\/strong>\u00a0developed by\u00a0<a href=\"https:\/\/twitter.com\/andreashornig\">Andreas Hornig<\/a>,\u00a0is a tool developed to determine the frequency drift of Software Defined Radios precisely using sync pulses of various Signal Standards. \u00a0<\/p>\n\n\n\n<p>Cheaper SDRs use a low-quality crystal oscillator which usually has a large offset from the ideal frequency. Furthermore, that frequency offset will change as the dongle warms up or as the ambient temperature changes. The result is that any signals received will not be at the correct frequency, and they would drift as the temperature changes. CalibrateSDR can be used with almost any SDR to determine the frequency offset. <\/p>\n\n\n\n<p>The work on <strong>GSM<\/strong> (2G) has been done by <a rel=\"noreferrer noopener\" href=\"https:\/\/twitter.com\/jyrj_j\" target=\"_blank\">Jayaraj J<\/a>, mentored by Andreas Hornig, as part of <a rel=\"noreferrer noopener\" href=\"https:\/\/summerofcode.withgoogle.com\/projects\/#5561974626189312\" target=\"_blank\">Google Summer of Code 2021<\/a>, the working directory for the same can be found at <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/tree\/jyrj_dev\" target=\"_blank\">Github<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/aerospaceresearch.net\/wp-content\/uploads\/2021\/07\/CalibrateSDRAerospaceResearch-Jayaraj-J.png\" alt=\"\"\/><figcaption><em>proposed working of CalibrateSDR<\/em> &#8211; made GSM signal compatible (the below guide shows how to get started)<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Project Description<\/h2>\n\n\n\n<p>GSM uses time division to share a frequency channel among users. Each frequency is divided into blocks of time that are known as time-slots. 8 time-slots are numbers TS0 \u2013 TS7. Each time slot lasts about 576.9\u00a0 \u03bcs. The bit rate is 270.833 kb\/s, a total of 156.25 bits can be transmitted in each slot.<\/p>\n\n\n\n<p>Each slot allocates 8.25 of its \u201ebits time\u201c as guard-time, split between the beginning and the end of each time slot. Data transmitted within each time slot is called a burst. There are several types of bursts.<\/p>\n\n\n\n<p><em>Frequency correction<\/em> burst is a burst of a pure frequency tone at 1\/4th the bitrate of GSM or (1625000 \/ 6) \/ 4 = 67708.3 Hz. By searching a channel for this pure tone, we can determine its clock offset by determining how far away from 67708.3Hz the received frequency is.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>How is it working?<\/strong><\/h5>\n\n\n\n<ol><li>Scanning of GSM Channels is based on the ARFCN frequency bands. For tuning into GSM Frequency, the ARFCN script can be used. We give the input of band to scan, the result will be the frequency. If we input the &#8222;scan all&#8220; option, it will scan the whole GSM Frequencies in the given band and return the offset calculated from each frequencies. The code for the same can be found at: <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/blob\/jyrj_dev\/calibratesdr\/gsm\/arfcn_freq.py\" target=\"_blank\">https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/blob\/jyrj_dev\/calibratesdr\/gsm\/arfcn_freq.py<\/a><\/li><li>After scanning channels in specific bands using ARFCN, the program will record the sample in the given sample rate. Make sure the SDR is connected with the device, or we can record it and give the input as a wave file.<\/li><li>The determination of the position of FCCH bursts that we receive in SDRs is done by the code in <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/blob\/jyrj_dev\/calibratesdr\/gsm\/fcch_offset.py\" data-type=\"URL\" data-id=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/blob\/jyrj_dev\/calibratesdr\/gsm\/fcch_offset.py\" target=\"_blank\">fcch_ossfet.py<\/a>. We measure it by how much shifted is the FCCH burst, than what we expect, that is at 67708.3 Hz from the frequency centre. Simply, if no offset is there, we could see these tone bursts at 67708.3 Hz offset concerning the centre frequency of the channel. <\/li><li>The final output we receive include <ul><li><strong>Frequency drift<\/strong> from the expected FCCH position<\/li><li>The<strong> Offset of SDR in PPM<\/strong><\/li><\/ul><\/li><li><strong>The whole code works from the main cali.py and inturns<\/strong> <a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/blob\/jyrj_dev\/calibratesdr\/gsm\/gsm.py\" data-type=\"URL\" data-id=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/blob\/jyrj_dev\/calibratesdr\/gsm\/gsm.py\" target=\"_blank\">gsm.py<\/a> files<\/li><\/ol>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>To test with the IQ_file.wave<\/strong>:<\/h5>\n\n\n\n<p>After cloning the repo locally, run the setup to install the requirements using the command:\u00a0<code>python setup.py install<\/code><\/p>\n\n\n\n<p>After that, to run the visualization plots, run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>python cali.py -m gsm -f &lt;location of wav file> -rs &lt;sampling rate> -fc &lt;frequency center><\/code><\/pre>\n\n\n\n<p>First, we will get the plot of the\u00a0<strong>average power spectrum<\/strong>\u00a0plot. Play with the code to increase the N value, and you can see the sharpness of the line.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh5.googleusercontent.com\/VBlZ-uUXlQqOHUFL9uqWbNHA5wCvyUBu2O0nGc6fZ_byErJgcFYBHyWKKSmYNgO4tTQJRWhB9tueG5mvtg-mIo8DKOPHyxr6YOk3gFkY6CevULNOjH8DBryXNgnu4TTn9p7OQ2VN\" alt=\"\"\/><\/figure>\n\n\n\n<p>Further plots generated includes TDMA frames, the position of FCCH bursts visualisation as given below.<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/blob\/jyrj_dev\/tests\/gsm\/Screenshot-spectrogram_hann-Zoomed.png?raw=true\" alt=\"Screenshot-spectrogram_hann-Zoomed.png\" width=\"805\" height=\"302\"\/><\/figure>\n\n\n\n<p>We can see the pure tone FCCH bursts are occurring at specific intervals and can be visualized as small blue dots at a range of 0.25 from the centre.<\/p>\n\n\n\n<p>Thus implementation of a filter bank and calculating the positions of these FCCH bursts will give us the offset frequency since we know these FCCH bursts occur at a distance of 67708.3 Hz from the frequency centre.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/aerospaceresearch.net\/wp-content\/uploads\/2021\/08\/Figure_1.png\" alt=\"\" class=\"wp-image-2394\" width=\"630\" height=\"472\"\/><figcaption>The average power spectrum of Discrete Fourier Transforms<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Usage<\/strong><\/h2>\n\n\n\n<p>Test files for GSM, recorded by Andreas can be found <a rel=\"noreferrer noopener\" href=\"https:\/\/drive.google.com\/drive\/folders\/1tO7BR6EpReL1ratUfFycQoZyVkYU10B4?usp=sharing\" data-type=\"URL\" data-id=\"https:\/\/drive.google.com\/drive\/folders\/1tO7BR6EpReL1ratUfFycQoZyVkYU10B4?usp=sharing\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<ul><li>Setup the environment, make sure the requirements are installed (preferably in a virtualenv). Use the setup.py to install necessary requirements.<\/li><li>To view the parameters for input run <code>~$ python cali.py -h<\/code><\/li><\/ul>\n\n\n\n<p>usage: cali.py [-h] [-f F] [-m {dab,dvbt,gsm}] [-s {rtlsdr}] [-c C] [-rs RS] [-rg RG] [-rd RD] [-nsec NSEC] [-gr] [-v] [-fc FC]<\/p>\n\n\n\n<p>optional arguments:<br><code>-h<\/code>, &#8211;help show this help message and exit<br><code>-f<\/code> F select path to input file<br><code>-m<\/code> {dab,dvbt,gsm} select mode<br><code>-s<\/code> {rtlsdr} scan with rtlsdr<br><code>-c<\/code> C scan by &#8222;all&#8220; channels, by channel number &#8222;0,1,\u2026n&#8220; or by block name<br><code>-rs<\/code> RS file\/scan sample rate<br><code>-rg<\/code> RG scan with gain<br><code>-rd<\/code> RD scan with the device<br><code>-nsec<\/code> NSEC scan for n-seconds<br><code>-gr<\/code>, &#8211;graph activate graphs<br><code>-v<\/code>, &#8211;verbose an optional argument<br><code>-fc<\/code> FC frequency centreSetup the environment, make sure the requirements are installed (preferably in a virtualenv). Use the setup.py to install necessary requirements.<\/p>\n\n\n\n<ul><li>If testing with a recorded wav file, enter the parameters as:<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>~$ python cali.py -m gsm -f &lt;location of wav file> -rs &lt;sampling rate> -fc &lt;frequency center><\/code><\/pre>\n\n\n\n<ul><li>If testing with an SDR stick, specify the ARFCN band, or specific frequency centre to scan for the GSM channel.<\/li><\/ul>\n\n\n\n<p>The ARFCN Bands include: <em>GSM_850, GSM_R_900, GSM_900, GSM_E_900, DCS_1800, PCS_1900.<\/em> For more information about the arfcn, checkout <a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Absolute_radio-frequency_channel_number\" data-type=\"URL\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/Absolute_radio-frequency_channel_number\" target=\"_blank\">here<\/a>.<\/p>\n\n\n\n<p>Example usage:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>~$ python cali.py -m gsm -s rtlsdr -c 900<\/code><\/pre>\n\n\n\n<p>The above parameters can be changed according to user needs. -rs can be specified with sample rate. The exact sample rate will be shown with the result. Make sure the SDR is connected when running the code with <code>-s rtlsdr<\/code> argument. Specify the <code>-fc<\/code> frequency argument, if the scan is to be done with a single frequency.  <\/p>\n\n\n\n<p>The expected output would look like this:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">{'f': None, 'm': 'gsm', 's': 'rtlsdr', 'c': '900', 'rs': 2048000, 'rg': 20, 'rd': 0, 'nsec': 10, 'graph': False, 'verbose': False, 'fc': None}\nlet's find your SDR's oscillator precision\nscanning\u2026\nstarting mode: gsm\nFound Rafael Micro R820T\/2 tuner\nExact sample rate is: 270833.002142 Hz\nScanning all GSM frequencies in band: GSM_900\nOffset Frequency: 31031.66666666667\nOffset in PPM: 33.179448397684716<\/pre>\n\n\n\n<p>The Offset calculated from the frequency drift between fcch positions can be precisely derived and can be used to correct the oscillator.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Potential further improvements:<\/strong><\/h5>\n\n\n\n<ol><li>LTE Signal support need to be included (currently in focus), and much more standards need to be made compatible for a wide usage of the tool.<\/li><li>Making a platform-neutral API to communicate with more SDR devices.<\/li><li>Optimising the user interface (command-line tool can be made more user friendly).<\/li><\/ol>\n\n\n\n<p><strong>References:<\/strong><\/p>\n\n\n\n<p>Find out the project updates in my branch and do give a star for the project in AerospaceResearch org:<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/tree\/jyrj_dev\" target=\"_blank\">https:\/\/github.com\/aerospaceresearch\/CalibrateSDR\/tree\/jyrj_dev<\/a><\/p>\n\n\n\n<ul><li><a rel=\"noreferrer noopener\" href=\"https:\/\/jyrj.hashnode.dev\/how-i-got-selected-for-gsoc\" target=\"_blank\">https:\/\/jyrj.hashnode.dev\/how-i-got-selected-for-gsoc<\/a>\u00a0<em>\u2013 First blog<\/em><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/aerospaceresearch.net\/?p=2208\" target=\"_blank\">https:\/\/aerospaceresearch.net\/?p=2208<\/a> &#8211; <em>Second blog<\/em><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/aerospaceresearch.zulipchat.com\/#narrow\/stream\/281823-CalibrateSDR\" target=\"_blank\">https:\/\/aerospaceresearch.zulipchat.com\/#narrow\/stream\/281823-CalibrateSDR<\/a>\u00a0<em>\u2013 Chat stream for the project<\/em><\/li><li><a rel=\"noreferrer noopener\" href=\"https:\/\/greenteapress.com\/wp\/think-dsp\/\" target=\"_blank\">https:\/\/greenteapress.com\/wp\/think-dsp\/\u00a0<\/a><em>\u2013 For anyone who likes to start with digital signal processing<\/em><\/li><li><a href=\"https:\/\/pysdr.org\/index.html\">https:\/\/pysdr.org\/index.html<\/a>\u00a0\u2013 <em>A simple guide to learning the basics of SDRs and DSP<\/em><\/li><\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview CalibrateSDR\u00a0developed by\u00a0Andreas Hornig,\u00a0is a tool developed to determine the frequency drift of Software Defined Radios precisely using sync pulses of various Signal Standards. \u00a0 Cheaper SDRs use a low-quality crystal oscillator which usually has a large offset from the ideal frequency. Furthermore, that frequency offset will change as the dongle warms up or as &hellip; <a href=\"https:\/\/aerospaceresearch.net\/?p=2349\" class=\"more-link\"><span class=\"screen-reader-text\">\u201e[GSoC2021] CalibrateSDR GSM Support\u201c<\/span> weiterlesen<\/a><\/p>\n","protected":false},"author":29,"featured_media":2270,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[25,33,16,30],"_links":{"self":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts\/2349"}],"collection":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/users\/29"}],"replies":[{"embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2349"}],"version-history":[{"count":13,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts\/2349\/revisions"}],"predecessor-version":[{"id":2400,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/posts\/2349\/revisions\/2400"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=\/wp\/v2\/media\/2270"}],"wp:attachment":[{"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2349"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2349"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aerospaceresearch.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2349"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}