california state university, northridge automatic real-time spectrum

73
CALIFORNIA STATE UNIVERSITY, NORTHRIDGE AUTOMATIC REAL-TIME SPECTRUM SENSING USING ENERGY DETECTION IN SOFTWARE DEFINED RADIO A graduate project submitted in partial fulfillment of the requirements For the degree of Master of Science in Electrical Engineering By Jyh-Chyuan Sun May 2012

Upload: others

Post on 19-Mar-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

CALIFORNIA STATE UNIVERSITY, NORTHRIDGE

AUTOMATIC REAL-TIME SPECTRUM SENSING USING ENERGY DETECTION

IN SOFTWARE DEFINED RADIO

A graduate project submitted in partial fulfillment of the requirements

For the degree of Master of Science in

Electrical Engineering

By

Jyh-Chyuan Sun

May 2012

ii

The graduate project of Jyh-Chyuan Sun is approved:

Professor James Flynn Date

Dr. Xiyi Hang Date

Dr. Sharlene Katz, Chair Date

California State University, Northridge

iii

DEDICATION

To my family, for letting go of their dreams so I could pursue a better future.

iv

ACKNOWLEDGEMENTS

I would like to express my deepest gratitude to Dr. Sharlene Katz, Professor James Flynn,

and Dr. David Schwartz for their guidance throughout my educational career at

California State University, Northridge. The genuine interests they show in engineering

are an inspiration to all students at the university, and I know I would not be in the

fortunate position that I am in today without them. Their wisdom and guidance made all

of this possible, and I am forever grateful for the opportunity to work with them for both

my undergraduate group project as well as this graduate project.

A special thanks to Dr. Xiyi Hang for serving on my committee and providing insights in

MATLAB programming. I sincerely appreciate the candid feedback.

Lastly, I would also like to recognize the rest of the faculty and staff in the Electrical and

Computer Engineering Department for always being available and ready to assist me in

my educational endeavors.

v

TABLE OF CONTENTS

Signature Page .................................................................................................................... ii

Dedication .......................................................................................................................... iii

Acknowledgements ............................................................................................................ iv

List of Tables .................................................................................................................... vii

List of Figures .................................................................................................................. viii

Abstract ................................................................................................................................x

Chapter 1: Introduction ........................................................................................................1

1.1 History of Software Defined Radio ...................................................................1

1.2 Background: Spectrum Sensing .........................................................................2

1.3 Project Overview ...............................................................................................3

Chapter 2: Technical Overview ...........................................................................................4

2.1 Overview ............................................................................................................4

2.2 Periodogram .......................................................................................................5

2.3 Threshold Detection ...........................................................................................8

2.4 Peak Signal Detection ........................................................................................9

Chapter 3: Hardware ..........................................................................................................12

3.1 Universal Software Radio Peripheral...............................................................12

3.2 Daughterboard: Wide Bandwidth Transceiver ................................................14

3.3 Agilent 33250A ................................................................................................16

Chapter 4: Software ...........................................................................................................17

4.1 MATLAB .........................................................................................................17

Chapter 5: Spectrum Sensing .............................................................................................19

vi

5.1 Overview ..........................................................................................................19

5.2 Graphical User Interface ..................................................................................21

5.3 Simulink Data Input .........................................................................................26

5.4 Periodogram .....................................................................................................31

5.5 Threshold Detection .........................................................................................34

5.6 Peak Signal Detection ......................................................................................34

5.7 Results Display ................................................................................................38

Chapter 6: Discussion of Test Results ...............................................................................40

6.1 Results for Amplitude Modulation ..................................................................40

6.2 Results for Frequency-Shift Keying ................................................................46

6.3 System Limitations ..........................................................................................49

Chapter 7: Conclusion........................................................................................................50

7.1 Summary ..........................................................................................................50

7.2 Future Work .....................................................................................................50

Bibliography ......................................................................................................................52

Appendix A: .......................................................................................................................53

Appendix B: .......................................................................................................................60

Appendix C: .......................................................................................................................62

vii

LIST OF TABLES

3.1 USRP N210 Technical Specifications .........................................................................13

3.2 WBX Daughterboard Technical Specifications ...........................................................15

3.3 Agilent 33250A Technical Specifications ...................................................................16

6.1 Default Test Conditions for Amplitude Modulation ....................................................40

6.2 Default Test Conditions for Frequency-Shift Keying ..................................................46

viii

LIST OF FIGURES

2.1 Block Diagram for Main Algorithms .............................................................................5

2.2 Normal FFT (Top) versus Periodogram (Bottom) .........................................................7

2.3 Band-Pass Filter in Spectrum Sensing .........................................................................10

3.1 Traditional Receiver versus Software Defined Radio Receiver ..................................12

3.2 Universal Software Radio Peripheral N210 .................................................................13

3.3 Wide Bandwidth Transceiver (WBX) ........................................................................15

5.1 Spectrum Sensing Overall Flow Chart ........................................................................20

5.2 Main GUI Window ......................................................................................................21

5.3 Program Code for Starting Additional MATLAB Workers ........................................25

5.4 Top Level Simulink Model File ...................................................................................27

5.5 Inside of the USRP Receiver Block .............................................................................29

5.6 Enabled Subsystem ......................................................................................................30

5.7 Program Code for Sorting Data into Segments............................................................31

5.8 Periodogram Code .......................................................................................................32

5.9 Task Manager Showing Main MATLAB Application and Four Workers ..................33

5.10 Program Code for Frequency Axis and Power Spectral Density Creation ................33

5.11 Program Code for Threshold Detection .....................................................................34

5.12 Program Code for Initializing Peak Signal Detection................................................35

5.13 Program Code for Determining Peak Signal .............................................................36

5.14 Program Code for Recording Possible Peak values ...................................................37

5.15 Program Code for GUI Graphing and Updating ........................................................38

6.1 Amplitude Modulation of 10 kHz ................................................................................41

ix

6.2 Amplitude Modulation of 10 kHz and Carrier of 75 MHz ..........................................42

6.3 Amplitude Modulation of 10 kHz and Display Bandwidth of 20 kHz ........................43

6.4 Amplitude Modulation of 10 kHz and Resolution Bandwidth of 100 Hz ...................43

6.5 Amplitude Modulation of 10 kHz and Resolution Segment of 1024 ..........................44

6.6 Amplitude Modulation of 10 kHz and Pfa of 0.1 ........................................................45

6.7 Amplitude Modulation of 10 kHz and Baseband of 20 kHz .......................................45

6.8 FSK Modulation with Resolution Segment of 256 .....................................................47

6.9 FSK Modulation with Resolution Segment of 64 .......................................................47

6.10 FSK Modulation with Resolution Bandwidth of 100 ................................................48

x

ABSTRACT

AUTOMATIC REAL-TIME SPECTRUM SENSING USING ENERGY DETECTION

IN SOFTWARE DEFINED RADIO

By

Jyh-Chyuan Sun

Master of Science in Electrical Engineering

The purpose of this graduate project is to design a real-time spectrum sensing system

using software defined radio. The uniqueness of software defined radio is the concept of

replacing many of the hardware components in a traditional radio communication system

with software algorithms and coding. The scope of this project will be on spectrum

sensing – to be able to automatically detect active signals in the desired frequency

spectrum.

The hardware components used in this graduate project are the Universal Software Radio

Peripheral and the Agilent function generator. The graphical user interface and algorithm

programming are performed in MATLAB. The spectrum sensing system will scan a

portion of the frequency spectrum, determine the presence of signals, and display the

three highest signal peaks in a given band. This paper will elucidate spectrum sensing’s

strengths and weaknesses as well as possible future work.

1

CHAPTER 1

Introduction

1.1 History of Software Defined Radio

Traditional radio communication systems are typically hardware in nature. The

components include an antenna, local oscillator, intermediate frequency (IF) amplifier,

demodulator, and an output medium such as a graphic display or audio speakers. There

are several disadvantages to having these components in hardware: First, the system takes

up space. This is especially important in military applications where the payload is

extremely critical. Second, once the system is designed and built, it is essentially

permanent. This makes updates and repairs cumbersome – and in some cases,

impractical. Third, a hardware radio communication system will need to be calibrated and

tuned due to drifting issues as well as being susceptible to temperature sensitivity. As a

result, this can make the hardware system unreliable at times.

The advancement in technology in recent years, however, has allowed the functionalities

of these components to be shifted into the personal computer. Collectively, these

advancements brought forth software defined radio. A software defined radio

communication system places much of the signal manipulation into the digital domain

where the computer is then able to process the data.[1]

The disadvantages of traditional hardware radios are addressed in software defined radio

systems. Space: Software defined radio, by definition, is a reduction in hardware via

2

software processing, and a decrease in physical space requirement results. Flexibility:

Due to performing the signal processing in software, adding new modes, modulation

schemes, or fixes are much simpler than in hardware counterpart.[2]

These changes can be

done via a software update – without the user having to modify the hardware. Reliability:

Minimizing the number of hardware components means fewer problems with drifting due

to temperature change or the aging of hardware components.

1.2 Background: Spectrum Sensing

One application within the world of software defined radio is spectrum sensing. Spectrum

sensing is part of a bigger system called cognitive radio, which is a radio that can modify

various parameters autonomously for communication purposes without the need for user

intervention. Spectrum sensing is the first stage in cognitive radio in which the radio

scans a section of the frequency spectrum for any active signal. There are two main

applications of spectrum sensing: Scanning for white space, and scanning for signals.

These two applications are closely associated with each other. The former is typically for

a transmitter design where the system looks at a range of frequency spectrum and uses

internal algorithm to decide if there is any white space, and if so, where is it in the

spectrum. This allows the system to transmit without interfering another existing signal at

the same frequency. The latter is more commonly found in a receiver system where the

purpose is to detect any active signal. These two parts form a complete transceiver

system. The second application of scanning for active signals is the focus of this graduate

project.

3

1.3 Project Overview

The main goal of this graduate project is to design an automatic software receiver system

that will scan a section of the frequency spectrum to look for active signals. First, the user

will be able to input specific parameters into a graphical user interface in the computer.

The software will adjust the system parameters based on the user inputs. Second, the

software will scan the frequency spectrum and analyze for signals. Third, the software

will use the graphical user interface to present the results to the user.

Chapter 2 will expound the hardware equipment used throughout this graduate project.

Chapter 3 will elaborate on the software components and the reasons those components

are used. In Chapter 4, in-depth analyses of each portion of the spectrum sensing system

will be explained. Discussion on the test results will be in Chapter 5, and Chapter 6 will

provide a summary for the work done in this graduate project.

4

CHAPTER 2

Technical Overview

2.1 Overview

The goal of this spectrum sensing system is to detect and display signals that are present

in a specified section of the spectrum by determining if there is energy above the noise in

a particular band.

From reading the incoming data to displaying the results on the graphical user interface

(GUI), there are three main algorithms required: Periodogram, Neyman-Pearson

threshold detection, and peak signal detection. A general block diagram of the system is

shown in Figure 2.1.

The periodogram analyzes the incoming data in order to estimate the power spectrum.

The threshold detection algorithm takes the output of the periodogram and calculates a

discrete boundary line between active signals and noise based on the variance of the data

set from the periodogram. Finally, the peak signal detection algorithm analyzes the data

that exceeds the threshold level and returns the three top peaks back to the GUI. The

resolution segment, probability of false alarm, and resolution bandwidth are parameters

set by the user in the GUI, and these parameters are used by the system for signal

processing. In Chapter 5, the code used to implement each of these algorithms is

discussed in detail.

5

Figure 2.1: Block Diagram for Main Algorithms

2.2 Periodogram

The Fast Fourier Transform (FFT) is an efficient method for transforming data from the

time domain to the frequency domain. The periodogram is based on the Fourier transform

– and most often the Fast Fourier Transform (FFT), which is an efficient way of

calculating the Discrete Fourier Transform.[3]

The difference between the two is that the

periodogram takes the FFT of evenly spaced segments of the data rather than the entire

data at once. The equation for a periodogram is given as the following:

( )

|∑ ( ) |

(2.1)

In the application of spectrum sensing, the periodogram method is superior because it

provides a better variance for the set of input data. Variance represents how far apart a

particular set of data is spread out in amplitude.[4]

The variance of the result of the entire

FFT data set does not accurately reflect how far away the individual data points are from

Input

Data Periodogram

Resolution

Segment

Threshold

Detection

Peak

Signal

Detection

Resolution

Bandwidth

GUI

Probability of

False Alarm

6

their mean value. Typically, the variance of the entire FFT data will be larger than the

FFT of the data in the segments due to the larger data variations in the entire frame versus

the variance of the segments. Because of this, a periodogram will generally produce a

smoother graph and enables the system to detect and display signals in the presence of

noise. Figure 2.2 shows the difference between a normal FFT and a periodogram.

The power spectral density shows the distribution of the total power over a specific range

of frequencies.[5]

The power spectral density is the Fourier transform of the

autocorrelation function, and defined in equation (2.2).[6]

However, assuming white

noise, the autocorrelation function Rxx, reduces to an impulse.[6]

( [ ] [ ] (2.2)

[ ] (2.3)

A two-sided power spectral density will have a mirror image at the negative frequency.

Equation (2.5) is the two-sided power spectral density, with equation (2.4) as angular

frequency ω measured in radians per second.

(2.4)

( ) ∫ [ ]

(2.5)

7

Figure 2.2: Normal FFT (Top) Versus Periodogram (Bottom)

8

The graduate project, however, will only utilize a one-sided power spectral density. The

reason is to simplify the peak signal detection algorithm and prevent the possibility of

counting the same peak twice.

2.3 Threshold Detection

The type of hypothesis testing used is the Neyman-Pearson threshold detection.[7]

This

threshold is defined in equation (2.6).

(

) ( (

( )) ) (2.6)

The variable λ is the threshold and σ2 is the variance of the amplitude data. The function

erfc-1

is the inverse of the complementary error function. The complementary error

function is one minus the error function, which is related to the normalized Gaussian

function.[8]

The Gaussian function is a probability distribution, and has the classic bell-

shaped curve. The variable PFA is the probability of false alarm, which is a parameter that

is set by the user in the GUI. The variance is calculated internally by the system with a

given set of data. Equations (2.7) and (2.8) define the complementary error function and

the normalized Gaussian function, respectively.[8]

( ) ( )

√ ∫

(2.7)

( )

(2.8)

9

By setting a desired probability of false alarm and calculating the variance of a data set,

the system sets a threshold to indicate signals above the noise level.

2.4 Peak Signal Detection

The peak signal detection algorithm determines possible peak signals in the scanned

spectrum. The algorithm uses the concept of band-pass filtering. In a simple RC case, a

low-pass filter cascaded with a high-pass filter will result in a band-pass filter. Equation

(2.9) is the general cutoff frequency used for both low-pass and high-pass filters.[9]

(2.9)

In equation (2.9), the variable fc is the cutoff frequency, which is 3 dB down from the

filter’s center frequency. The center frequency, or resonant frequency, can be represented

in equation (2.10).

√ (2.10)

Even though a software solution has no resistor or capacitor, the same concept can be

applied. By storing the amplitude values in an array, the peak value can be easily

discerned. In this software solution, the difficulty lies not in determining peaks, but to be

able to distinguish one signal’s peak from noise as well as other signals. The assumption

here is that the both the lower cutoff frequency and the higher cutoff frequency are

equidistant from the resonant frequency. The bandwidth is the range between the lower

10

cutoff frequency and the higher cutoff frequency. This bandwidth is a known value

because it is the resolution bandwidth parameter set by the user in the GUI. The equation

for the bandwidth is shown in equation (2.11).[9]

(2.11)

The algorithm will place the midpoint of the bandwidth over the peak value. Data points

within the bandwidth will be considered as the same signal and passed through. Figure

2.3 shows an example of band-pass filtering applied to the spectrum sensing application.

Figure 2.3: Band-pass Filter in Spectrum Sensing

11

Using Figure 2.3 above, assume an fr of 20 kHz and the user sets a bandwidth of 10 kHz.

The middle of the bandwidth will be placed at 20 kHz, and the bandwidth will span 5

kHz to the right and to the left of 20 kHz. Data points below the threshold level are

treated as noise and not included in the peak signal detection algorithm. The algorithm

searches through the data points to find the first peak value. It considers all data points

inside that band and above the threshold level (the red line in Figure 2.3) as from the

same 20 kHz peak signal. The algorithm will remove the peak value at 20 kHz and all

data points inside the bandwidth, and restart the process to see if there is another peak

signal above the threshold. Finally, the algorithm will return a maximum of three peak

values back to the GUI.

In this application, it is assumed that the peak value is at or very close to the center of the

signal or the bandwidth placement might be skewed to the left or the right – potentially

rejecting part of its own signal or passing data points from a neighboring signal. The

filtering enables the algorithm to disregard peak values outside of the bandwidth and only

analyze the values within the bandwidth.

12

CHAPTER 3

Hardware

3.1 Universal Software Radio Peripheral

While many of the components in a software defined radio are shifted to the software

side, some hardware components are still needed. Figure 3.1 below shows the difference

between a traditional radio and a software defined radio.

Figure 3.1: Traditional Receiver vs. Software Defined Radio Receiver

The hardware side has more than one option: In the test instrument industry, there is an

active focus to move towards PXI, or PCI eXtensions for Instrumentation. Originally

introduced by National Instruments in 1997, PXI modules are slot-based card solutions

for traditional hardware instruments like spectrum analyzers and oscilloscopes.[10]

Another system, and the one used in this graduate project, is Universal Software Radio

Peripheral, or USRP for short. USRP is a low-cost solution for a software defined radio

RF

Amplifier x

Local

Oscillator

IF

Amplifier

Demod-

ulator

Traditional / Hardware Receiver

Software ADC Software Defined Radio Receiver

Receiver Front End

13

system. There is a set of generic hardware on the USRP, such as analog-to-digital

converters (ADC) and digital-to-analog converters (DAC). The rest of the work is done

on the computer.

Figure 3.1: Universal Software Radio Peripheral (USRP) N210[11]

The USRP has a set of basic hardware components. Table 3.1 below shows the

specifications for the N210 USRP:

USRP N210 Specifications

FPGA: Xilinx Spartan 3A-DSP 3400

Dual ADC: 100 MSamples/s

Dual DAC: 400 MSamples/s

Connectivity to PC: Gigabit Ethernet

Table 3.1: USRP N210 Technical Specifications[12]

The radio frequency (RF) range of the USRP varies depending on the daughterboard

used. This is a modular approach and mimics the slot-based card solutions

aforementioned in the PXI system. The onboard ADC converts analog signals coming

14

over the air into digital representations for the computer to process. The DAC reverses

this process and converts the digital data from the computer into analog signals to

transmit over the air.

Due to the massive amount of data streamed to the computer, the USRP N210 requires

gigabit Ethernet or the computer will not be able to communicate with the USRP.

Through experimentation, it is believed this limitation is hardcoded into the USRP

firmware to ensure the system will not slow down due to 10/100 Ethernet speed.

However, one workaround for computers that do not have gigabit local area network

(LAN) is to use a gigabit switch. Because the USRP is connected to the gigabit switch,

the former believes it has connected to a computer with gigabit LAN. The gigabit switch

then connects to the computer without gigabit LAN. Although this will allow the

computer with non-gigabit LAN to communicate to the USRP, it is not recommended due

to potential overrun and underrun problems. Overrun occurs when the computer is not

keeping up with the incoming data from the USRP.[13]

Conversely, underrun is when the

computer is not transmitting the data to the USRP fast enough.[13]

This is the reason for

the USRP requiring gigabit LAN speed to minimize overruns and underruns.

3.2 Daughterboard: Wide Bandwidth Transceiver

There are many modular daughterboards that can be used on the USRP depending on the

RF ranges desired. This graduate project uses the wide bandwidth transceiver, or WBX

daughterboard.

15

Figure 3.2: Wide Bandwidth Transceiver (WBX)[14]

The WBX daughterboard covers a range of frequencies from 50 MHz to 2.2 GHz, but the

frequency that will be mainly used in this graduate project is 70 MHz to 75 MHz.

Although the minimum frequency of the WBX daughterboard is 50 MHz, experiments

showed that there was distortion and nonlinearity near the WBX’s minimum frequency.

For this reason, the targeted frequency range for testing purposes is 70 MHz to 75 MHz.

The technical specifications for the USRP WBX daughterboard are provided in Table 3.2

below.

WBX Daughterboard

Minimum Frequency: 50 MHz

Maximum Frequency: 2.2 GHz

Maximum Output Power: 100 mW

Noise Figure: 5 dB

Bandwidth: 40 MHz

Table 3.2: WBX Daughterboard Technical Specifications[15]

16

3.3 Agilent 33250A

The input test signal used in this graduate project is from the Agilent 33250A

Function/Arbitrary Waveform Generator. The generator is readily available in the

laboratory and Table 3.3 provides the specifications for the instrument.

33250A Function/Arbitrary Waveform Generator

Modulation: AM, FM, FSK

AM Carrier: Sine, square, ramp, and arb

AM Modulated Frequency: 2 mHz to 20 kHz

Sine: 1 uHz to 80 MHz

Square: 1 uHz to 80 MHz

Pulse: 500 uHz to 50 MHz

Filter Bandwidth: 50 MHz

Amplitude Resolution: 12 bits

Sample Rate: 200 MSamples/s

Table 3.3: Agilent 33250A Technical Specifications[16]

Because the Agilent 33250A has a maximum frequency of 80 MHz for sine wave

generation, tests were performed in the 70 MHz to 75 MHz range to prevent distortion

and nonlinearity from the generation side. To minimize distortion caused by the 33250A,

a decision was made to lower the maximum test frequency to 75 MHz.

17

CHAPTER 4

Software

4.1 MATLAB

The software used in this graduate project is called MATLAB. Produced by MathWorks,

MATLAB offers a programming environment for developing algorithms, data

processing, and graphical user interface creation.[17]

MATLAB, in the case of this

graduate project, offers the complete package on the software side. Furthermore,

MATLAB is capable of communication with the USRP, eliminating the need to manually

implement a protocol pipeline to communicate with the USRP. MATLAB is a compiler,

meaning that it can compile written code immediately in a similar fashion to Microsoft

Visual Studio. This advantage means prototyping can quickly be built, tested, and

implemented.

Alternatively, another option to interface with the USRP hardware is GNU Radio and

GNU Radio Companion (GRC). GNU Radio is a free and open-source software package

capable of signal processing algorithms and graphical visualizations – similar

functionalities as provided by MATLAB.[18]

GNU Radio mainly operates in the Linux

operating system environment. The source code for GNU Radio is written in the

programming language Python. GRC is a software toolkit that is bundled with GNU

Radio; it is also free and open-source. GRC is a graphical tool, utilizing blocks for

implementation at a systems level.[19]

GRC allows the user to create a general system

template visually and contains a feature to convert the blocks into equivalent Python

18

code. Therefore, the main purpose of GRC is to reduce the amount of programming

needed via GNU Radio alone.

GNU Radio and GRC are not used in this graduate project. MATLAB has very good

built-in documentation and the maturity of Simulink – a toolbox within MATLAB and

acts as the input and output points to communicate with the USRP – is sufficient in this

project. In addition, Simulink is comparable to GRC; in other words, a graphical block

layout tool that allows the user to implement a system without the need to program

manually. This is not to say MATLAB has no disadvantage: MATLAB is a large

software containing various toolboxes and functionalities. Occurrences of overruns and

underruns are more prevalent in MATLAB, thus the reason for gigabit LAN is so crucial.

19

CHAPTER 5

Spectrum Sensing

5.1 Overview

At the system level, the GUI is the central point for all stages in spectrum sensing. The

GUI has a set of basic parameters for the user to change; it acts as both the input and the

output interface for this system. The input refers to the user input and the output is where

the data results are displayed. After the GUI reads the user inputs, it starts the Simulink

toolbox within MATLAB.

Simulink is used to allow the program to communicate with the USRP hardware.

Simulink takes the user inputs and adjusts the USRP accordingly. The USRP will tune to

the desired frequency and stream the data back to the main MATLAB interface. It is

worth noting that the USRP is not a smart radio by itself: The intelligence in a SDR is

due to the program code.

After receiving and storing the data in Simulink, the program code analyzes the data in

order to determine the presence of signals in the scanned frequency spectrum. The top

three peak signals report back GUI and the GUI displays the result. The process repeats

indefinitely or until the user manually stops the system. The implementation of spectrum

sensing in MATLAB using USRP has a general flow chart as Figure 5.1 illustrates. The

algorithm processing block is a multistep process performed in MATLAB, and the main

topic of this graduate project.

20

Figure 5.1: Spectrum Sensing Overall Flow Chart

Graphical User Interface

Read User Inputs

Simulink

Read USRP Inputs

Algorithm Processing

Display Results

21

5.2 Graphical User Interface

The GUI in MATLAB is designed using Guide, which stands for GUI Development. The

GUI has a simple and easy-to-use interface available to the user. When the program first

starts, the GUI appears as shown in Figure 5.2.

On the left-hand side, there is a visual frequency spectrum display. The vertical axis is

the signal amplitude in decibels (dB) and the horizontal axis is the frequency in hertz

(Hz). The screen starts out with a blank graph as shown in Figure 5.2. Below the graph,

there are two buttons: The Start button initiates the spectrum sensing and analysis, and

the stop button manually halts the scanning process. Because this is a continuous system

that runs indefinitely, as long as the user does not explicitly press stop, the system will

continue running.

Figure 5.2: Main GUI Window

22

The right-hand side of the GUI is split into two panels. The top panel is the control panel,

and in this panel all the parameters are changeable by the user. The center frequency is a

parameter required in the Simulink USRP block. This parameter sets the center frequency

of the frequency scan. The display bandwidth adjusts the horizontal axis in the frequency

spectrum display. This flexibility allows the user to look at a wide frequency range as

well as being able to focus and zoom in on a narrow frequency region.

Resolution bandwidth determines whether data points are part of the same signal. Higher

resolution bandwidth results in faster processing, but the output result is not as clear.[20]

As it pertains to this graduate project, resolution bandwidth is used for the peak signal

detection algorithm. Resolution bandwidth is needed because the peak signal detection

algorithm cannot visually discern if data points are from the same signal, multiple signals

nearby, or noise. For example, suppose there is a signal with a peak of 70 MHz. If the

resolution bandwidth parameter is set at 2 MHz, then the algorithm will come to the

conclusion that all data points within 69 MHz to 71 MHz are the same signal. The user

would either need to know the desired signal type or adjust this parameter based on the

spectrum graph in the GUI.

The resolution segment parameter is used at various points throughout the system.

Resolution segment helps determine the fast Fourier transform (FFT) length. Smaller

resolution segment results in more samples when performing FFT. While this means

better clarity in the frequency display, it does come with more acquisition and

23

computation time. Because the resolution segment is used for determining FFT sample

points, powers of two are strongly recommended such as 256, 512, or 1024. The equation

for calculating the FFT length is shown in equation (5.1).

(5.1)

The system designed in this project uses a frame length of 65536. Therefore, using

equation (5.1) with a resolution segment of 64:

The Pfa parameter stands for the probability of false alarm, and used in the Neyman-

Pearson threshold detection. It is a statistical metric used for threshold detection. Setting

the probability of false too small might result in false negatives and setting the value too

high may return false positives. When the probability of false alarm is set too high, the

threshold level for determining whether a signal is active or not is lowered in a reciprocal

fashion. If the threshold level is set very low, for example, at the noise floor, essentially

all data samples are considered active signals – creating many false negative results and

rendering the spectrum sensing system useless.

24

Below the control panel is the display panel. The display panel will show the peak

amplitude signal with its corresponding frequency value to the user for each detected

signal. If no active signal is detected, both text boxes will display -999.

Lastly, there are two notes at the bottom of the display panel to remind the user to set the

resolution segment in powers of two, and -999 in the boxes means no signal was found.

When the GUI is first started, the input boxes are populated with specific default values.

All of these values may be adjusted, but nothing in the display panel can be changed

since they are meant for display purposes only.

When the user clicks on the start button, the static text to the right of the Start and Stop

buttons will be changed from “STOPPED” to “Processing Data.” This informs the user

that the system is readying itself to scan the spectrum. The variables instantiated in

MATLAB cannot be accessed or are they even visible in the variable workspace in

Simulink. This resulted in difficulty when trying to pass variables between MATLAB

and Simulink, such as the center frequency. The solution is to use the command assignin,

which stands for “assign in.” As the name suggests, the command assigns variables into

the workspace. However, this by itself does not create a common workspace between

MATLAB and Simulink. The workspace parameter in the command must be explicitly

set to “base,” as that is the common workspace shared by MATLAB and all derivatives

of MATLAB – including Simulink.

25

Although the input boxes in the control panel look like numbers, they are actually all

strings. Therefore, the code must first convert all the string values into numerical

numbers (in the double format) so MATLAB can take these values and do further

processing. The MATLAB GUI in general communicates in handles. For instance, the

spectrum display is named handles.main_graph, and the center frequency string is

handles.edit_cf.

In in the initialization, the program code will check to see if multiple workers are started.

Workers act as additional processes in the Windows operating system, and MATLAB is

able to take advantage of multiprocessing if paired with the parfor-loop, which will be

discussed in section 5.4. The code in Figure 5.3 will query the how many additional

workers are started. If the result is zero, the code will generate four additional workers

since the computer used has a quad-core central processing unit (CPU). The full

MATLAB program code m-files are located in Appendices A, B, and C.

Figure 5.3: Program Code for Starting Additional MATLAB Workers

26

After the conversion is complete, the program will run Periodogram.m, a MATLAB m-

file. At the top of Periodogram.m, the rest of the input string parameters are converted

into double precision values. After this initialization process, Periodogram.m calls the

Simulink model file.

5.3 Simulink Data Input

At the top level of this Simulink model file, there are only three blocks: a constant source

block, the USRP receiver block, and an enabled subsystem block. The USRP block

requires an input value for the center frequency. This is the input value that the user sets

in the GUI as described in section 5.2.

The constant source block simin_input_signal takes the user carrier frequency input value

from the GUI and sends it to the USRP block. The command assignin allows Simulink to

access and read the center frequency value through a common workspace. The USRP

receiver block is denoted as SDRu Receiver in Figure 5.4 below. The USRP

communicates via the Ethernet LAN port. The static internet protocol (IP) address set by

the USRP firmware is 192.168.10.2.

27

Figure 5.4: Top Level Simulink Model File

The internal parameters for the USRP receiver block are shown in Figure 5.5. The center

frequency parameter does not contain an input box. This is because the center frequency

value is controlled by the constant source block. The rest of the values are default settings

that should be left alone. From experimentation, these values are set at a gain of 10 dB,

decimation of 500, sampling time of 5 x 10-6

seconds, and frame length of 65536.

The onboard digital downconverter (DDC) decimates the input signal from a higher

sampling rate of 100 MSamples/s in the field programmable gate array (FPGA). Using

equation (5.2) below, signal processing in the computer occurs at a lower sampling rate

of 200 kHz.

(5.2)

28

The USRP receiver block in Figure 5.5, however, expects sampling time, not sampling

frequency. Sampling time has an inverse relationship to sampling frequency, and is

shown in equation (5.3).

(5.3)

The data coming out of the USRP receiver block is fed into the input of the enabled

subsystem, and the data length is connected to the enable block inside the enabled

subsystem. This tells the subsystem to run only when a frame is received.

Inside of the enabled subsystem is where the actual signal processing takes place. This is

shown in Figure 5.6. This subsystem sends the incoming signal to the workspace variable

called simout_input_signal. Because there is an integer delay, the variable

simout_input_signal in the Simulink workspace will have multiple rows of length 65536.

29

Figure 5.5: Inside of the USRP Receiver Block

30

Figure 5.6: Enabled Subsystem

Through experimentation, it was discovered that the USRP initially buffers erroneous

data. The exact cause for this is unknown. Setting the delay to three will actually generate

four rows of data because the matrix contains one row of data without delay, and three

rows of data with delays. Therefore, only the last frame is used while the previous ones

are discarded. The integer delay could be set longer, and in fact, has been tested with 10

and 20. However, not only did this increase the processing time, it did not increase the

accuracy or fidelity of the signal. Through testing, a delay of three was found to yield

good data while minimizing the chance of buffering erroneous data. The data type

conversion block is used after the delay block to convert its output to the same signal type

as the stop simulation block. The stop simulation block informs the subsystem to stop

recording data coming from the USRP.

31

Once Simulink has stopped recording data points, it returns control back to

Periodogram.m for the next step in the system process. It should be noted that MATLAB

has access to simout_input_signal, or the Simulink output of the input signal from the

USRP.

5.4 Periodogram

When Periodogram.m has control of the program once again (it pauses while the

Simulink model file is still active), it processes the last frame of the data that was

received. The next step in the process is shown in Figure 5.7. The code takes the 65536

data points into multiple rows based on the resolution segment set by the user in the GUI.

The purpose for doing this is to improve processing time.

Figure 5.7: Program Code for Sorting Data into Segments

After organizing the data into the desired segments, the next process is to compute the

periodogram. In the program code, the periodogram is found by taking the FFT of a

segment. The algorithm can be represented in Figure 5.8. The resolution segment

parameter set by the user in the GUI helps determine the number of FFT points. Recall

the discussion in section 5.2 that smaller resolution segments will result in more data

32

points – and thus finer resolution. In Figure 5.8, the resolution segment, rseg in the

program code, is on the equation’s denominator. Therefore, a smaller resolution segment

will result in a higher number of points for the FFT. The periodogram uses the special

for-loop called parfor. The parfor-loop is a parallel for-loop meant to take advantage of a

multicore computer, and increases speed versus traditional for-loops. Parfor-loops exist in

MATLAB’s Parallel Computing Toolbox.

Figure 5.8: Periodogram Code

It should be noted, however, that the parfor-loop cannot be used in all circumstances.

This is due to MATLAB’s restriction on executing parfor-loops when there are additional

nested loops within. MATLAB internally sends portions of the data to be computed in the

parfor-loop to multiple workers (separate processes at the operating system level), but

with nested loops the workers may work asynchronously due to the nature of nested

loops. There must be only one for-loop so MATLAB implicitly knows how many

computations there are, and splits the workload among its workers evenly. The

initialization of workers is done before the GUI is visible, and was discussed in section

33

5.2. Figure 5.9 shows MATLAB with four additional workers to offload the data from the

main MATLAB process.

Figure 5.9: Task Manager Showing Main MATLAB Application and Four Workers

After the periodogram is computed, the following process creates the frequency axis for

plotting purposes and finds the one-sided power spectral density. The program code in

Figure 5.10 shows this process.

Figure 5.10: Program Code for Frequency Axis and Power Spectral Density Creation

The command “floor” in MATLAB rounds to the nearest lower integer and causes the

horizontal axis to have integer values.

34

5.5 Threshold Detection

Data points above, or “passing”, the threshold count as active signals in the peak signal

detection algorithm. Conversely, data points below the threshold will be viewed as noise.

The threshold is really nothing more than a numeric limit separating the active signals

from the noise. The MATLAB program code for threshold detection is shown in Figure

5.11.

Figure 5.11: Program Code for Threshold Detection

The MATLAB command npwgnthresh is a Neyman-Pearson threshold used in hypothesis

testing for threshold detection.[7]

The npwgnthresh command uses the probability of false

alarm set by the user in the main GUI window. The result is the signal-to-noise (SNR)

threshold in decibels.

5.6 Peak Signal Detection

The final stage in the data processing is the peak signal detection algorithm. This

algorithm is the decision engine that takes the data from periodogram along with the

threshold level and puts them together to determine the presence of signals.

35

The program code shown in Figure 5.12 determines if there is any data point above the

threshold level. If no data point is found to be above the threshold level, there is no need

to even enter the peak signal detection algorithm. This is more efficient, especially if it

turns out that there is no signal in the spectrum to begin with. By default, Periodogram.m

will return -999 for both the amplitude and its respective frequency back to the main GUI

window. This information is used in the last stage of the signal processing, and will be

discussed in section 5.7.

Figure 5.12: Program Code for Initializing Peak Signal Detection

There is an initial check to see if the threshold level calculated is too low. If the threshold

level is below -70 dB, the system assumes an error must have occurred somewhere (user

or otherwise) and returns -999 back to the main GUI window.

36

The main program code for the peak signal detection algorithm is shown in Figure 5.13.

The purpose of the program code in Figure 5.13 is to compare and hold the peak

amplitude values, if they exist. If the size within lock_f is equal to one exactly, there is

only one peak value above the threshold. Therefore, there is no need to do any further

data manipulating and simply hold that value. If the size is less than one – which means

an error has occurred because the spectrum only contains zero and positive values– the

program code will exit the entire if-loop.

Figure 5.13: Program Code for Determining Peak Signal

37

If the size is more than one, the program code will remove non-peak values. This is

determined via the resolution bandwidth, which acts as a filter based on the peak

amplitude value. Data points within the resolution bandwidth of the peak are regarded as

the same signal, and thus ignored by the algorithm.

The last portion of the code in the peak signal detection algorithm is to populate arrays

peak_freq and peak_amp (both contains three elements) with the three top peaks

returning to the main GUI window. However, if the number of peak values is less than

three, the algorithm will fill the empty array elements with -999. The program code for

returning possible peak values is shown in Figure 5.14.

Figure 5.14: Program Code for Recording Possible Peak Values

38

5.7 Results Display

After the execution of Periodogram.m, the main GUI assumes control once again. The

program code shown in Figure 5.15 displays the graph result, draws the threshold level if

it is greater than -70 dB, and displays the three highest signal peaks in the main GUI

window. The code will also readjust the horizontal axis based on the display bandwidth

parameter set by the user.

Figure 5.15: Program Code for GUI Graphing and Updating

39

This reaches the end of the full cycle for the spectrum sensing program. After the graph

has been adjusted and plotted, the GUI will continue indefinitely until the user clicks on

the stop button. The program will not stop immediately because the check to see whether

the stop button has been clicked is located at the beginning of the program run.

Alternatively, the program can contain multiple checks at various key points in the

program run to see whether the stop button has been clicked or not; however, this will

burden the system with even more execution code. In the end, the decision is to avoid

unnecessary conditional checks throughout the code and prevent further speed

degradation.

40

CHAPTER 6

Discussion of Test Results

6.1 Results for Amplitude Modulation

As discussed earlier, a realistic target frequency range due to limitations on both the

USRP WBX daughterboard and the Agilent 33250A generator is 70 MHz to 75 MHz. In

the first test, the generator is set to a carrier frequency of 70 MHz with a baseband

amplitude modulation (AM) of 10 kHz. The default test conditions are shown in table

6.1, and all other tests in section 6.1 will be compared to this default case.

Default Test Conditions

Agilent 33250A GUI

Carrier Frequency: 70 MHz Center Frequency: 70.001 MHz

Baseband Frequency: 10 kHz Display Bandwidth: 50 kHz

Modulation: AM Resolution Bandwidth: 1 kHz

Resolution Segment: 256

Pfa: 1e-4

Table 6.1: Default Test Conditions for Amplitude Modulation

The signal in Figure 6.1 is clearly visible in the main graph. According to the returned

results, the spectrum sensing program found the baseband peak at 11.0 kHz with an

amplitude level of -15.6 dB. The threshold level is set to approximately -32 dB. Because

the peak signal is above the threshold, the spectrum sensing program regarded the signal

as an active signal. The shifted frequency axis is due to the USRP, so the peak signal

centered on zero is actually the 70 MHz carrier. The baseband is at 11 kHz because the

center frequency parameter is shifted by 1 kHz on the control. The display bandwidth is

41

set to 50 kHz, so the horizontal frequency axis is set to a maximum of 5x104 Hz, or 50

kHz.

Figure 6.1: Amplitude Modulation of 10 kHz

Figure 6.1 above is regarded as the default condition, and the following tests in section

6.1 will be to see the result based on parameter changes. Figure 6.2 shows the result with

the generator changing its carrier frequency to 75 MHz. The center frequency set by the

user has an offset of 5 kHz, which is reason the baseband frequency shown in the GUI is

15 kHz instead of 10 kHz.

42

Figure 6.2: Amplitude Modulation of 10 kHz and Carrier of 75 MHz

The next parameter change is the display bandwidth to 20 kHz. Referring to Figure 6.3,

the baseband signal is visually shifted to the middle of the graph because the maximum

horizontal axis is now only 20 kHz.

Shown in Figure 6.4, raising the resolution bandwidth to 5000 Hz resulted in the removal

of the erroneous peak at 2.36 kHz that was present in Figure 6.1. Due to the higher

resolution bandwidth, the system interprets all data points ± 5000 Hz of the peak at 787.4

Hz as the same signal and thus will not report the 2362.2 Hz peak back to the GUI.

43

Figure 6.3: Amplitude Modulation of 10 kHz and Display Bandwidth of 20 kHz

Figure 6.4: Amplitude Modulation of 10 kHz and Resolution Bandwidth of 100 Hz

44

Changing the resolution segment from 256 to 1024 will theoretically have the peaks be

less distinguishable. As shown in Figure 6.5, this is exactly what happens. The display

panel no longer reports back the correct peak of 11 kHz. By lowering the resolution

segment – and thus the FFT length – fewer points will be sampled. The result is the

displayed peak value is incorrect.

Figure 6.5: Amplitude Modulation of 10 kHz and Resolution Segment of 1024

The probability of false alarm affects the threshold level. Setting the probability of false

alarm to 0.1 lowered the threshold level and introduced false peak values.

45

Figure 6.6: Amplitude Modulation of 10 kHz and Pfa of 0.1

Another change is to set the baseband to 20 kHz, and the result is shown in Figure 6.7.

Figure 6.7: Amplitude Modulation of 10 kHz and Baseband of 20 kHz

46

6.2 Results for Frequency-Shift Keying

The generator is also able to generate frequency-shift keying (FSK) signals, and the tests

in section 6.2 are performed with FSK modulation. The default test conditions are shown

in table 6.2.

Default Test Conditions

Agilent 33250A GUI

Carrier Frequency: 69.98 MHz Center Frequency: 70 MHz

Hop Frequency: 70.02 MHz Display Bandwidth: 50 kHz

FSK Rate: 3 kHz Resolution Bandwidth: 1 kHz

Modulation: FSK Resolution Segment: 256

Pfa: 1e-4

Table 6.2: Default Test Conditions for Frequency-Shift Keying

This time, suppose the only parameter known is the input signal’s carrier frequency is at

70 MHz. If this is the case, the default test conditions in the GUI can be the same as

section 6.1. Figure 6.8 shows only a peak at 20 kHz, but nothing else is very

indistinguishable. Therefore, the next step is to lower the resolution segment to 64. Recall

from section 4.2 that lowering the resolution segment will increase the FFT length in the

periodogram, resulting in more data points and a clearer graph display. Figure 6.9 is the

graph display with the resolution segment at 64.

47

Figure 6.8: FSK Modulation with Resolution Segment of 256

Figure 6.9: FSK Modulation with Resolution Segment of 64

48

The result is clearer and the sidebands are close to the peak. However, the threshold level

changed. This is due to the adjustment in resolution segment, which changes the data set

that the system uses to calculate the variance. Another parameter that can be modified is

to set the resolution bandwidth to a lower value. The reason the two lower peaks reported

back incorrectly is because they are less than 1000 Hz from the top peak. To the system,

it is simply concluding that those two values are from the same signal as the one at 20

kHz. Decreasing the resolution bandwidth will reintroduce the two peaks ± 1000 Hz of

the top peak back into consideration. This is shown in Figure 6.10.

Figure 6.10: FSK Modulation with Resolution Bandwidth of 100

The other two peaks are now showing correctly in the display panel. From the

information in Figure 6.10, it is possible to conclude that the hop frequency is 20 kHz

49

higher than the carrier frequency of 70 MHz. In addition, the FSK rate is set to

approximately 0.978 kHz, which is very close to the actual FSK rate of 1 kHz.

6.3 System Limitations

Although the spectrum sensing system passed several test cases in section 6.1 and 6.2, it

is not a perfect system. For instance, the user still needs to read the spectrum display and

adjust several parameters in order to see the correct peak amplitudes and frequencies in

the GUI. In addition, the system introduced erroneous peak values in some instances,

which is due to the resolution bandwidth setting being too high or too low. Currently, the

system is unable to automatically adjust the GUI parameters and rescan to see if a better

result can be gathered. This leads to the user having to adjust the GUI parameters in order

to eliminate erroneous peak values or refine the display. Lastly, the system has not been

tested with multi-tone signals or other modulated signals. The behavior of the system for

these test cases is unknown.

50

CHAPTER 7

Conclusion

7.1 Summary

The main purpose of this project is to design a spectrum sensing receiver program using

software defined radio. The USRP hardware system defined the scope of the project, and

the software program illustrated the potential of what a software defined radio system is

capable of doing.

The spectrum sensing program contains a main GUI window for the user. There are many

parameters that the user can change and set. Once started, the program opens a Simulink

model and interfaces with the USRP hardware. The program tells the USRP the center

frequency to tune to. The USRP streams the data and saves it in a matrix. The program

then initiates the periodogram analysis to not only transform the data to the frequency

domain, but determine whether a signal is viewed as an active signal or not. Once

processed, the program returns the results back to the main GUI window to the user

display. The user is capable of manually adjusting the parameters to fine-tune the details

or scan another portion of the spectrum. This system has been shown to perform as

expected in a number of test cases.

7.2 Future Work

Due to the modular nature of software defined radio, there is potential for future work in

this area. The spectrum sensing system is constructed in such a way that additional

51

coding is simple. For example, if the periodogram method returned no active signal, the

program can then run an alternative method of signal estimation.

Alternatively, the system could instead change the parameters itself and rescan the signal

data until an active signal is determined. As an example, if the returned amplitude peak

values are extremely low, the system would lower the resolution segment as well as the

resolution bandwidth and rescan the spectrum. The reason for the former is that the

sampled data pointed might not be the signal’s true peak, and the reason for the latter is

that the highest peak value could mask other nearby signals with a large resolution

bandwidth.

Lastly, the program can be changed to instantiate another program to try to demodulate

that signal as soon the signal is found by the system. There are many possibilities for

future work that closely relates to the spectrum sensing project. Due to software defined

radio, this is all realizable thanks to its ability to prototype and modify without having to

design an inflexible and complex hardware system.

52

BIBLIOGRAPHY

[1] “Software Defined Radio.” Retrieved 31 March 2012

http://www.arrl.org/software-defined-radio

[2] “Software Defined Radio.” Retrieved 2 April 2012

http://www.converter-radio.com/SDR.pdf

[3] Stoica, Petre, Jian Li, and Hao He. “Spectral Analysis of Nonuniformly Sampled

Data: A New Approach Versus the Periodogram.” Retrieved 8 April 2012

http://plaza.ufl.edu/haohe/papers/RIAA.pdf

[4] “Variance and Standard Deviation.” Retrieved 8 April 2012

http://www.statcan.gc.ca/edu/power-pouvoir/ch12/5214891-eng.htm

[5] Stensby, John. “Chapter 8 – Power Density Spectrum.” Retrieved 9 April 2012

http://www.ece.uah.edu/courses/ee420-500/500ch8.pdf

[6] “Lecture 8: White Noise and Power Spectral Density.” Retrieved 9 April 2012

http://www.idsc.ethz.ch/Courses/signals_and_systems/lectureNotes8.pdf

[7] “Phased Array System Toolbox: npwgnthresh.” Retrieved 9 April 2012

http://www.mathworks.com/help/toolbox/phased/ref/npwgnthresh.html

[8] “Gaussian, Error and Complementary Error Function.” Retrieved 9 April 2012

http://ecee.colorado.edu/~bart/book/gaussian.htm

[9] “Band Pass Filter.” Retrieved 14 April 2012

http://www.electronics-tutorials.ws/filter/filter_4.html

[10] “What is PXI?” Retrieved 6 April 2012

http://zone.ni.com/devzone/cda/tut/p/id/4811

[11] “USRP N210 Picture.” Retrieved 6 April 2012

https://www.ettus.com/content/images/prod_un210-kit_01_md.jpg

[12] “USRP N210.” Retrieved 6 April 2012

https://www.ettus.com/product/details/UN210-KIT

[13] “General Questions.” Retrieved 6 April 2012

http://gnuradio.org/redmine/projects/gnuradio/wiki/UsrpFAQGen

[14] “WBX 50-2200 MHz Rx/Tx Picture.” Retrieved 6 April 2012

https://www.ettus.com/content/images/prod_wbx_01_md_1.jpg

[15] “WBX 50-2200 MHz Rx/Tx.” Retrieved 6 April 2012

https://www.ettus.com/product/details/WBX

[16] “33250A Function / Arbitrary Waveform Generator.” Retrieved 6 April 2012

http://cp.literature.agilent.com/litweb/pdf/5968-8807EN.pdf

[17] “MATLAB: Overview.” Retrieved 7 April 2012

http://www.mathworks.com/products/matlab/?s_cid=wiki_matlab_2

[18] “GNU Radio: Introduction.” Retrieved 7 April 2012

http://gnuradio.org/redmine/projects/gnuradio/wiki

[19] “GNU Radio Companion.” Retrieved 7 April 2012

http://gnuradio.org/redmine/projects/gnuradio/wiki/GNURadioCompanion

[20] “Resolution Bandwidth (RBW).” Retrieved 8 April 2012

http://zone.ni.com/devzone/cda/tut/p/id/3983

53

APPENDIX A

GUI.m

function varargout = GUI(varargin) % GUI MATLAB code for GUI.fig % GUI, by itself, creates a new GUI or raises the existing % singleton*. % % H = GUI returns the handle to a new GUI or the handle to % the existing singleton*. % % GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GUI.M with the given input arguments. % % GUI('Property','Value',...) creates a new GUI or raises the % existing singleton*. Starting from the left, property value

pairs are % applied to the GUI before GUI_OpeningFcn gets called. An % unrecognized property name or invalid value makes property

application % stop. All inputs are passed to GUI_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only

one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help GUI

% Last Modified by GUIDE v2.5 09-Apr-2012 16:02:32

% Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @GUI_OpeningFcn, ... 'gui_OutputFcn', @GUI_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end

if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT

54

% --- Executes just before GUI is made visible. function GUI_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to GUI (see VARARGIN)

%Initialization for the main graph axis(handles.main_graph,[0 8000 -2 2]) xlabel(handles.main_graph,'Frequency (Hz)') ylabel(handles.main_graph,'dB') title(handles.main_graph,'Spectrum','Fontweight','bold','FontSize',14)

matlabpool size; %Will return in variable "ans"

%Worker = 0 means the pool is closed, so 0 or 1 = no extra workers %Workers will persist until MATLAB is closed if ans <= 1 distcomp.feature( 'LocalUseMpiexec', false ); matlabpool open 4; %Spawns new MATLAB workers, which are separate %processes to be used by parfor-loop end

% Choose default command line output for GUI handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes GUI wait for user response (see UIRESUME) % uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line. function varargout = GUI_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure varargout{1} = handles.output;

% --- Executes on button press in pushbutton_start. function pushbutton_start_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_start (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

%Order of operation - since while loop is most dangerous, do other

stuff %and leave while loop until last to run

55

hold(handles.main_graph,'off') set(handles.pushbutton_start,'UserData',1);

%Infinite while loop to keep program continuously running while (get(handles.pushbutton_start,'UserData') == 1) %Process_Pipeline hold(handles.main_graph,'off')

%Changing status text running_status = 'Processing Data...'; set(handles.text_start_stop_status,'String',running_status) pause(0.1); %Pauses for 100 ms before moving on

%All field boxes are strings, so need to convert them to numbers

first %str2double is faster than str2num, but only works on scalars simin_input_signal = str2double(get(handles.edit_cf,'String'));

%Manually assigns variable to base workspace to be read by Simulink %Shift center frequency to the left assignin('base', 'simin_input_signal', simin_input_signal+500);

Periodogram; %Executes Periodogram.m while GUI pauses here

%Grabs the most current display bw from Control Panel disp_bw = str2double(get(handles.edit_disp_bw,'String')); %Display the peak values set(handles.text_frequency_lock_1,'String',peak_freq(1)); set(handles.text_amplitude_lock_1,'String',peak_amp(1)); set(handles.text_frequency_lock_2,'String',peak_freq(2)); set(handles.text_amplitude_lock_2,'String',peak_amp(2)); set(handles.text_frequency_lock_3,'String',peak_freq(3)); set(handles.text_amplitude_lock_3,'String',peak_amp(3));

%If condition is true for any reason, still do the plot, but do not %draw threshold. %If threshold is too low it is assumed center freq is off from

input's %center freq if(peak_freq(1) == -999 && peak_amp(1) == -999) || threshold <=-70 running_status = 'Cannot find signal!'; set(handles.text_start_stop_status,'String',running_status); plot(handles.main_graph,f, SdB, 'Linewidth', 1.5); else %Found an active signal and all parameters look good plot(handles.main_graph,f, SdB, 'Linewidth', 1.5); pause(5); %To ensure threshold line does not get overwritten by %plot due to MATLAB lag line(1:disp_bw,threshold,'color',[1 0 0 ]); end

%Resizes the main graph based on user's set display bw axis(handles.main_graph,[min(f), disp_bw, min(SdB), max(SdB)]); hold(handles.main_graph,'on'); xlabel(handles.main_graph,'Frequency (Hz)'); ylabel(handles.main_graph,'dB');

56

title(handles.main_graph,'Spectrum','Fontweight','bold','FontSize',14); end

% --- Executes on button press in pushbutton_stop. function pushbutton_stop_Callback(hObject, eventdata, handles) % hObject handle to pushbutton_stop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

%Order of operation - stopping while loop is most important set(handles.pushbutton_start,'UserData',0);

%Changing status text stopped_status = 'STOPPED...'; set(handles.text_start_stop_status,'String',stopped_status) guidata(hObject, handles);

function edit_rseg_Callback(hObject, eventdata, handles) % hObject handle to edit_rseg (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_rseg as text % str2double(get(hObject,'String')) returns contents of

edit_rseg as % a double

% --- Executes during object creation, after setting all properties. function edit_rseg_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_rseg (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns

called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function edit_pfa_Callback(hObject, eventdata, handles) % hObject handle to edit_pfa (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_pfa as text % str2double(get(hObject,'String')) returns contents of edit_pfa

as a double

% --- Executes during object creation, after setting all properties.

57

function edit_pfa_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_pfa (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns

called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function edit_cf_Callback(hObject, eventdata, handles) % hObject handle to edit_cf (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_cf as text % str2double(get(hObject,'String')) returns contents of edit_cf

as a double

% --- Executes during object creation, after setting all properties. function edit_cf_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_cf (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns

called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

function edit_disp_bw_Callback(hObject, eventdata, handles) % hObject handle to edit_disp_bw (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_disp_bw as text % str2double(get(hObject,'String')) returns contents of

edit_disp_bw as a double

% --- Executes during object creation, after setting all properties. function edit_disp_bw_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_disp_bw (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB

58

% handles empty - handles not created until after all CreateFcns

called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

% --- Executes on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton1

% --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton2

% --- Executes on button press in radiobutton3. function radiobutton3_Callback(hObject, eventdata, handles) % hObject handle to radiobutton3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton3

function edit_rbw_Callback(hObject, eventdata, handles) % hObject handle to edit_rbw (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_rbw as text % str2double(get(hObject,'String')) returns contents of edit_rbw

as a double

% --- Executes during object creation, after setting all properties. function edit_rbw_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_rbw (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB

59

% handles empty - handles not created until after all CreateFcns

called

% Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'),

get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end

60

APPENDIX B

Periodogram.m

%Make the handles structures available to the main workspace h=gcf; myhandles = guidata(h);

%rseg = Number of segments, higher rseg = more suppression but narrow-

band %signal Might get suppressed as well %rbw = Resolution bandwidth of signal %Pfa = Probability of false alarm %Fs = Sampling frequency rseg = str2double(get(handles.edit_rseg,'String')); rbw = str2double(get(handles.edit_rbw,'String')); Pfa = str2double(get(handles.edit_pfa,'String')); Fs = 200e3; %Fixed value based on USRP: 100e6/500 = 200e3

open('SigGen_USRP_input.mdl'); %Opens simulink model sim('SigGen_USRP_input.mdl'); %Runs simulink model

%Initializing variables xBig = simout_input_signal(4,:)'; %Assumes first few frames are junk

data sum_Sk = 0; w=1; n=length(xBig); %Determines frame length of xBig, for instance 65536

%2-D array for all the segments in the specified spectrum for y=1:rseg for x=((n/rseg)*(y-1)+1):((n/rseg)*y) reference(y,w) = xBig(x); w = w+1; end w=1; end

%Periodogram via squared magnitude of FFT %Takes each segment, FFT it, then add to sum_Sk. Repeat and add other %segments on top of that. parfor y=1:rseg XBig = fft(reference(y,1:end,1), n/rseg); S = ( (abs(XBig).^2)/((n/rseg)) );

%sums that segment sum_Sk = sum_Sk + S; end

%Creates frequency axis: n=length of data, m=segment parfor k=1:floor((n/rseg)/2) f(k) = (k-1)*Fs/(n/rseg);

61

end

%Take 1-sided PSD temp = sum_Sk / rseg; parfor x=1:(n/rseg)/2 S_new(x)=temp(x); end

f = Fs/2*linspace(0,1,length(S_new));

%Converts to dB, then plot 1-sided PSD SdB = pow2db(S_new);

%Calculating threshold for detection variance = var(S_new); %Determines variance of the input data T = npwgnthresh(Pfa); %T is SNR threshold in dB threshold_temp = variance*db2pow(T); threshold = pow2db(threshold_temp);

%Determines any signal above threshold if threshold >= -70 if max(SdB) >= threshold %There are frequencies above threshold lock_S = find(SdB>=threshold); %Finds indices of elements

within SdB %that has values >= threshold lock_f = f(lock_S); %lock_f are the frequency values on

frequency %axis f that have values of lock_S

%Calls function to determine peak signals [peak_freq, peak_amp] = Peak_sig_det(lock_f, lock_S, c_bw, rbw,

SdB);

else %No active signals above threshold, default to -999 for both

amplitude %and freq peak_freq(1:3) = -999; peak_amp(1:3) = -999; end else peak_freq(1:3) = -999; peak_amp(1:3) = -999; end

62

APPENDIX C

Peak_sig_det.m

function [peak_freq, peak_amp] = Peak_sig_det(lock_f, lock_S, c_bw,

rbw, SdB) size_lock_f = numel(lock_f); %Determines # of elements in the array i=1; %Iteration counter

%Only check if there is >1 frequencies that is > threshold (if high %sampling, 2 or more closeby data samples may be of the same signal) if size_lock_f > 1 display_lock_f = lock_f(i); %Starts the iteration by having a

nonzero %number while i < size_lock_f %If it is > bw, then different signal if abs(lock_f(i) - lock_f(i+1)) > 0.5*rbw display_lock_f(i+1) = lock_f(i+1); %Hold peak signal's freq

value i = i+1;

%It is < bw, therefore same signal else %Current iteration max peak > next iteration if SdB(lock_S(i)) > SdB(lock_S(i+1)) display_lock_f(i) = lock_f(i); lock_f(i+1) = []; %Removes element from array lock_S(i+1) = []; %Removes element from array size_lock_f = size_lock_f - 1; %Update new size of

lock_f else %Next iteration max peak > current iteration display_lock_f(i) = lock_f(i+1); lock_f(i) = []; %Removes element from array lock_S(i) = []; %Removes element from array size_lock_f = size_lock_f - 1; %Update new size of

lock_f end end end elseif size_lock_f == 1 %If only 1 value above threshold display_lock_f = lock_f; %Hold peak signal's freq value end

%If variable does not exist, it means no value above threshold if exist('display_lock_f', 'var') == 0 %Checks for variables only %Even though there was an active signal, but it is < bw so %enter default values peak_amplitude = -999 peak_amplitude_freq = -999

else %If this condition is true, that means at least 1 signal present

63

display_lock_f %Displays list of possible frequency channels that

may %be active end

%If at least 1 signal exists if size_lock_f >=1 parfor i=1:size_lock_f %Determine amplitude of the data values

above %the threshold temp_peak_amplitude(i) = SdB(lock_S(i)); end end

peak_freq(1:3) = -999; peak_amp(1:3) = -999;

for i = 1:size_lock_f peak_amp(i) = max(temp_peak_amplitude); pos = find(temp_peak_amplitude == peak_amp(i)); peak_freq(i) = display_lock_f(pos); temp_peak_amplitude(pos) = -999; display_lock_f(pos) = -999; end