{"id":36,"date":"2021-10-25T17:31:58","date_gmt":"2021-10-25T17:31:58","guid":{"rendered":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/?page_id=36"},"modified":"2021-11-18T17:07:02","modified_gmt":"2021-11-18T17:07:02","slug":"development","status":"publish","type":"page","link":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/development\/","title":{"rendered":"Development"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">MATLAB<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">SDR Data Manipulation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">In order to understand the structure of the data that the SDR sends and how to manipulate it, signals were captured in the FM band and stored in a .dat file for manipulation in MATLAB. The RTL-SDR v3 sends 8 bits of I data and 8 bits of  unsigned data sequentially. Using this knowledge of the data format and the tuning of the SDR, and sampling rate, the FFT was performed within MATLAB. <\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"520\" height=\"306\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.43.51-AM.png\" alt=\"\" class=\"wp-image-49\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.43.51-AM.png 520w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.43.51-AM-300x177.png 300w\" sizes=\"auto, (max-width: 520px) 100vw, 520px\" \/><figcaption>FFT of Real SDR Data<\/figcaption><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Windowing<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The FFT assumes continuity of the signal it is being performed on; in other words, it treats the N samples as if they contain a perfectly even number of cycles. Since this is often not the case in reality, spectral leakage becomes an issue. For this project, spectral leakage poses a threat as the IMD products are already naturally close to the fundamental signals. For that reason, windowing is implemented. Windowing is nothing more than a kind of envelope that pinches the ends of the sample data towards 0, which ultimately reduces the presence of smearing but also loses granularity in terms of frequency accuracy. Several different windowing functions were tested in MATLAB.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"585\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.49.45-AM-1024x585.png\" alt=\"\" class=\"wp-image-50\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.49.45-AM-1024x585.png 1024w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.49.45-AM-300x172.png 300w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.49.45-AM-768x439.png 768w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.49.45-AM.png 1137w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Windowing Functions<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The FM data is not a great example for the effects of windowing, but they are still present. The primary purpose of the usage of MATLAB here was to generate text files of the windowing function that the C code later can read and select from a variety of functions to observe which provides the best results.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"652\" height=\"326\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.52.06-AM.png\" alt=\"\" class=\"wp-image-51\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.52.06-AM.png 652w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.52.06-AM-300x150.png 300w\" sizes=\"auto, (max-width: 652px) 100vw, 652px\" \/><figcaption>Reading MATLAB Generated Windowing Functions from Text in C<\/figcaption><\/figure><\/div>\n\n\n\n<h4 class=\"wp-block-heading\">Peak Detection Algorithm<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The goal of the project requires the identification of peaks in the frequency spectrum. Visually this is a very simple task, but programmatically requires some thought. MATLAB contains functions in toolboxes that can be called to aid in this but since the goal is to port to C, a custom lightweight algorithm was developed instead.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"576\" height=\"678\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.55.47-AM.png\" alt=\"\" class=\"wp-image-52\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.55.47-AM.png 576w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.55.47-AM-255x300.png 255w\" sizes=\"auto, (max-width: 576px) 100vw, 576px\" \/><figcaption>MATLAB Peak Finding Algorithm<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The algorithm is most likely far from ideal, but for now is a functional option. The loop simply sweeps across the frequency bins looking for indices that contain a max that has not yet been found. It also defines a minimum margin between peaks, meaning that if a peak is found at 5 kHz, there is a range around that were data is discarded. This needs to be wisely chosen based on how the data is expecting to be.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"433\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.59.04-AM-1024x433.png\" alt=\"\" class=\"wp-image-53\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.59.04-AM-1024x433.png 1024w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.59.04-AM-300x127.png 300w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.59.04-AM-768x325.png 768w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.59.04-AM-1536x650.png 1536w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.59.04-AM.png 1713w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Peak Finding Overview<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The MATLAB code was then written in C after verification.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"563\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1024x563.png\" alt=\"\" class=\"wp-image-57\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1024x563.png 1024w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-300x165.png 300w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-768x422.png 768w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1536x844.png 1536w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image.png 1629w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Peak Detection Visualization<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The above figure visualizes the peak detection algorithm. A dark line denotes a left margin and light gray line denotes a right margin. Each pair when moving from left to right has a peak in the middle. A benefit of the algorithm is that it inherently stores signals in order of magnitude, which simplifies future comparisons. The above visualization hides data beneath the noise floor. The full signal is shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-style-default\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"559\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1-1024x559.png\" alt=\"\" class=\"wp-image-59\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1-1024x559.png 1024w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1-300x164.png 300w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1-768x419.png 768w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1-1536x838.png 1536w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/11\/image-1.png 1614w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Full Frequency Spectrums before Processing<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Data Transfer Implementation<\/h2>\n\n\n\n<h4 class=\"wp-block-heading\">SDR \u2013 Raspberry Pi Communication<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The first task of the software implementation was to find a means to transfer SDR data to the GPIO pins. After investigating the underlying code in open-source SDR software such as GQRX or GNU-Radio, it was determined that the most lightweight option was to use the&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/librtlsdr\/librtlsdr\" target=\"_blank\">librtlsdr<\/a>&nbsp;library. The library offers several terminal commands to tune the SDR and capture data to a file. Details on that can be found on the Github page or&nbsp;<a rel=\"noreferrer noopener\" href=\"http:\/\/www.aaronscher.com\/wireless_com_SDR\/RTL_SDR_AM_spectrum_demod.html\" target=\"_blank\">here<\/a>. The primary command to be used is&nbsp;<em>rtl_sdr<\/em>, which can write live SDR data to a file. A less used advertised of the command however, is that it can dump that same data to stdout continuously. Using this functionality the stdout of the&nbsp;<em>rtl_sdr<\/em>&nbsp;command is piped to a C program that stores 65k* bytes of data in a buffer to be sent to the FPGA. Recall that the FFT size specified is 32k* points; the 65k number comes from the fact that the SDR sends 1 byte of I data and 1 byte of Q data sequentially, so one sample is really 2 bytes. This needs to be instantiated for both SDRs with their specific GPIO pins.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"77\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.15.35-PM-1024x77.png\" alt=\"\" class=\"wp-image-30\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.15.35-PM-1024x77.png 1024w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.15.35-PM-300x22.png 300w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.15.35-PM-768x57.png 768w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.15.35-PM.png 1096w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Example Command<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">*<em>32k and 65k are used interchangeably for 32,768 and 65,536.<\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Pi \u2013 FPGA Communication<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The main_control program mentioned above is what interfaces with the Pi\u2019s GPIO and therefore the FPGA.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"416\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.18.56-PM-1-1024x416.png\" alt=\"\" class=\"wp-image-32\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.18.56-PM-1-1024x416.png 1024w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.18.56-PM-1-300x122.png 300w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.18.56-PM-1-768x312.png 768w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-25-at-1.18.56-PM-1.png 1286w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Code Snippet of main_control.c<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The above code snippet shows how code is read into the buffer and processed. Once the GPIO pins are updated, the handshaking scheme discussed in the preliminary design page is implemented.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.31.00-AM.png\" alt=\"\" class=\"wp-image-48\" width=\"539\" height=\"244\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.31.00-AM.png 479w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Screen-Shot-2021-10-26-at-10.31.00-AM-300x136.png 300w\" sizes=\"auto, (max-width: 539px) 100vw, 539px\" \/><figcaption>C Code Handshaking Example<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">For the sending portion of the Pi&#8217;s code,  the Pi asserts high and then waits indefinitely until it reads a response from the FPGA and asserts a low signal to indicate the reception. Finally when the FPGA responds, the loop breaks and starts over with new data. The print statement was simply for debugging purposes but will not be present in final implementation to improve speed. In order to verify the functionality of the interface, the Pi writes all data that it sends to a text file and all data it receives to a text file. For this, the FPGA must simply store all the data in a BRAM and then send it all back untouched.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"673\" height=\"438\" src=\"http:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Data_Integrity_Verification-1-edited.png\" alt=\"\" class=\"wp-image-29\" srcset=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Data_Integrity_Verification-1-edited.png 673w, https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-content\/uploads\/sites\/197\/2021\/10\/Data_Integrity_Verification-1-edited-300x195.png 300w\" sizes=\"auto, (max-width: 673px) 100vw, 673px\" \/><figcaption>Data Integrity Test Structure<\/figcaption><\/figure><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The above diagram illustrates the testing procedure for data integrity.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MATLAB SDR Data Manipulation In order to understand the structure of the data that the SDR sends and how to manipulate it, signals were captured in the FM band and stored in a .dat file for manipulation in MATLAB. The RTL-SDR v3 sends 8 bits of I data and 8 bits of unsigned data sequentially. &hellip; <a href=\"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/development\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Development<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":380,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"ngg_post_thumbnail":0,"footnotes":""},"class_list":["post-36","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-json\/wp\/v2\/pages\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-json\/wp\/v2\/users\/380"}],"replies":[{"embeddable":true,"href":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-json\/wp\/v2\/comments?post=36"}],"version-history":[{"count":0,"href":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-json\/wp\/v2\/pages\/36\/revisions"}],"wp:attachment":[{"href":"https:\/\/engprojects.tcnj.edu\/rf-nonlinear-component-analyzer\/wp-json\/wp\/v2\/media?parent=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}