contentsreu.wireless.vt.edu/pdfs/final paperamosajoandsamhenderson.pdf · dynamic spectrum access...

24
Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University of Kentucky Mentors : Dr. Louis Beex, Professor and Dr. Carl Dietrich, Research Assistant Professor ECE Department Virginia Tech University Contents Abstract................................................................................................................................................... 2 1 Introduction ..................................................................................................................................... 2 1.1 Dynamic Spectrum Access ....................................................................................................... 2 1.2 Background.............................................................................................................................. 3 2 Primary User Establishment ............................................................................................................. 3 2.1 BPSK....................................................................................................................................... 3 2.2 Primary Transmitter ................................................................................................................. 4 2.2.1 Implementation in MATLAB ........................................................................................... 5 2.3 Primary Receiver ..................................................................................................................... 5 2.3.1 Implementation in MATLAB ........................................................................................... 6 2.4 Results of PU ........................................................................................................................... 7 3 Secondary User Establishment ......................................................................................................... 8 3.1 GNU Radio Implementation ..................................................................................................... 8 3.1.1 Blocks .............................................................................................................................. 9 3.1.2 Python Scripting ............................................................................................................... 9 3.2 Sensing Algorithm ................................................................................................................. 10 3.2.1 PU+SU........................................................................................................................... 11 3.2.2 Results ........................................................................................................................... 11 4 Discussion of Results ..................................................................................................................... 11 5 Conclusion .................................................................................................................................... 12 6 Further Work ................................................................................................................................. 12 7 Appendix ....................................................................................................................................... 13 7.1 Appendix A............................................................................................................................ 13 7.2 Appendix B............................................................................................................................ 15 7.3 Appendix C............................................................................................................................ 18

Upload: hoangthien

Post on 07-Sep-2018

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

Dynamic Spectrum Access Using Audio

Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University of Kentucky

Mentors : Dr. Louis Beex, Professor and Dr. Carl Dietrich, Research Assistant Professor

ECE Department Virginia Tech University

Contents Abstract ................................................................................................................................................... 2

1 Introduction ..................................................................................................................................... 2

1.1 Dynamic Spectrum Access ....................................................................................................... 2

1.2 Background .............................................................................................................................. 3

2 Primary User Establishment ............................................................................................................. 3

2.1 BPSK ....................................................................................................................................... 3

2.2 Primary Transmitter ................................................................................................................. 4

2.2.1 Implementation in MATLAB ........................................................................................... 5

2.3 Primary Receiver ..................................................................................................................... 5

2.3.1 Implementation in MATLAB ........................................................................................... 6

2.4 Results of PU ........................................................................................................................... 7

3 Secondary User Establishment ......................................................................................................... 8

3.1 GNU Radio Implementation ..................................................................................................... 8

3.1.1 Blocks .............................................................................................................................. 9

3.1.2 Python Scripting ............................................................................................................... 9

3.2 Sensing Algorithm ................................................................................................................. 10

3.2.1 PU+SU ........................................................................................................................... 11

3.2.2 Results ........................................................................................................................... 11

4 Discussion of Results ..................................................................................................................... 11

5 Conclusion .................................................................................................................................... 12

6 Further Work ................................................................................................................................. 12

7 Appendix ....................................................................................................................................... 13

7.1 Appendix A............................................................................................................................ 13

7.2 Appendix B ............................................................................................................................ 15

7.3 Appendix C ............................................................................................................................ 18

Page 2: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

7.4 Appendix D............................................................................................................................ 21

8 References ..................................................................................................................................... 24

Abstract This paper details an experiment to model a Dynamic Spectrum Access system using two

software defined radios (SDR), one a primary user (PU) and the other a secondary user (SU).

Both radios are implemented such that they communicate data over audio waves via computer

soundcards. We program a PU which owns an audio channel centered at 4 kHz and

communicates BPSK modulated data in periodic bursts, as well as a SU who is cognitive radio

(CR) that wishes to access the PU channel during the null periods of the PU’s traffic. The PU

link is executed in MATLAB, and the SU is defined in GNU Radio with a separate python

control module to implement its cognition. We detail the implementation of both communication

links, and describe the performance of our system with bit error rate (BER) calculations of our

PU with and without the presence of our SU.

1 Introduction New generation wireless devices are designed to meet the increasing demands of mobile users.

Wireless devices are expected to support high transfer data rates which in turn requires larger

bandwidths in the Radio Frequency (RF) spectrum. The challenge this poses to wireless

providers have prompted the Federal Communications Commission FCC to take certain actions

which included auctioning of parts of the TV spectrum. Although telecommunications providers

like AT&T and Verizon Wireless have made use of the additional spectrum to deploy their 4Th

Generation (4G) networks, evidence have shown that most of the spectrum operated by primary

users are underutilized. According to RF engineers, most mobile communication links

communicate through short burst of transmission with inter—burst times within transmission.

These inter—burst times are considered as underutilization of the electromagnetic spectrum

known to RF engineers as spectrum holes [1]. In order for a secondary user to utilize these

spectrum holes available on a primary user network, engineers have developed the concept of

Dynamic Spectrum Access. Moreover, several research projects have been completed and are

ongoing in Dynamic spectrum Access.

1.1 Dynamic Spectrum Access

Dynamic Spectrum Access is considered to be the opposite of the conventional static spectrum

management policy where a PU purchases a license from the FCC to operate within a specific

frequency band [2]. However, several DSA models are categorized as (a) Dynamic Exclusive

Use model: in which spectrum bands a licensed to services for exclusive use. This model is of

the current structure however licensees are allowed to sell and trade spectrum [2]. (b) Open

Sharing model: this model employ open sharing among peer users as the basis for managing a

spectral region [2]. (c) Hierarchical Access model: this model adopts a hierarchical access

structure with a PU and a SU [2]. The SU is given open access to the PU spectrum while limiting

Page 3: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

interference to the license user. Our research project is based on the Hierarchical Access model

mentioned above.

1.2 Background DSA is made possible by the advent of SDR and CR technology. SDR’s are radios which can be

configured and implemented in software, and CR’s are SDR’s which use software algorithms to

dynamically adjust and reconfigure themselves to optimize performance. In DSA, CR’s are used

to employ spectrum sensing to opportunistically access unused regions of spectrum called

‘spectrum holes’. This paper will describe the methods used to model a DSA system with SDRs

which communicate via audio waves.

2 Primary User Establishment Establishment of the PU link serves as the foundation of our project. We implement two separate

MATLAB modules for the PU transmitter (TX) and receiver (RX). The end goal is to create a

reliable communication link in which the PU TX modulates binary data onto a 4 kHz audio

frequency carrier, and the PU RX receives, demodulates and accurately recovers the data which

has been sent to it. The primary user is named so because it owns primary rights to the spectrum

in which it operates- in our demonstration this is a channel of about 1 kHz in bandwidth which is

centered at 4 kHz. To modulate binary data onto this 4 kHz frequency we employ a digital

modulation scheme called Binary Phase Shift Keying (BPSK), for which a brief discussion is

presented in the following subsection.

2.1 BPSK Binary Phase Shift Keying (BPSK) changes the phase of a sign wave to represent 1 bit of data.

Therefore, BPSK transmits 1 bit of data per symbol rate, either 1 or 0. The binary bits of 1s and

0s are represented as +1v and -1v respectively. When the binary data stream is multiplied by a

carrier sine wave, the carrier sine wave phase is modulated based on the current data. If the

current data is 1 the carrier sine wave has no phase shift and the phase of the carrier is 0 degree.

This is represented by sin 𝜔𝑡 as shown in Figure 1. When the current data is 0 represented by -1v

the carrier phase shifted by 180 degrees and therefore the carrier is represented by −sin 𝜔𝑡 as

illustrated in Figure 1 bellow.

Page 4: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

Figure 1: BPSK modulation [3]

To implement BPSK in the PU transmitter module, it is necessary to minimize the effects of

intersymbol interference. Intersymbol interference is caused when the signal bandwidth becomes

larger than the channel bandwidth. To reduce such intersymbol interference in the transmitter

we applied a pulse shaping filter. A pulse shaping filter transforms the waveform of the

transmitted pulses by limiting the bandwidth of the signal and therefore determining the signals

spectrum. Any filter can be used for pulse shaping however the root raise cosine filter is suited

for its simplicity, configurable excess bandwidth and spectral efficiency, hence, is widely used in

communication systems

2.2 Primary Transmitter We followed the following block diagram in Figure 2 to generate the proper MATLAB signal

processing routines for transmitting BPSK modulated data.

Figure 2: BPSK Transmitter [4]

In Figure 1, symbol index indicates a sequence of binary digits to be modulated and the BPSK

block here simply represents a translation of digital values 1 and 0 to real number values of 1 and

-1. This discrete sequence is first upsampled and then passed through a raised root cosine pulse

shaping filter to generate the continuous baseband data signal. This signal is then mixed onto an

audio frequency carrier, whose frequency we choose to be 4 kHz. In the following sub-section

we explain these blocks in further detail along with their implementation in MATLAB.

Page 5: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

2.2.1 Implementation in MATLAB The following is a code excerpt in MATLAB that displays the transmission of a single one

second BPSK burst:

In our final implementation of the transmitter we modified the above code slightly such that we

generate, modulate, and transmit 5 bursts of binary symbols, in which we declare burst and

interburst times to be 2 and 4 seconds respectively (see Appendix A.)

2.3 Primary Receiver We followed the following block diagram in Figure 2 to generate the proper MATLAB signal

processing routines for receiving and demodulating our BPSK modulated data.

Figure 3: BPSK Receiver [4]

The block diagram of the above demodulator works to inverse the operations of the modulator.

To retrieve our baseband data signal we again mix our signal with our 4 kHz carrier and lowpass

filter the double frequency component, and pass our signal through a matched pulse shaping

%Parameters of Transmission burst_time = 1; %Burst Time in seconds fs = 48e3; %Sampling Rate os = 100; %upsampling factor Rs = fs/os; %Symbol Rate(symbols/second) N = burst_time*Rs; %Number of bits

%Symbol Generator/BPSK/Upsampling tx = rand(1,N)>0.5; %generating 0,1 with equal probability txsym = 2*tx-1; % BPSK modulation 0 -> -1; 1 -> 0 txsymup=upsample(txsym,os);

%Raised Root Cosine Filter for Pulse Shaping alpha=0.1; % roll-off factor of Root Raised Cosine Filter pt = srrc(os,alpha); % impulse response of SRRC filter txps=conv(txsymup,pt); %Pulse Shaping BPSK signal

%% Modulation n = 1:length(txps); amp = 0.5; fc = 4000; omegac = fc/fs;

carrier = cos(2*pi*omegac*n); txps = amp*txps*sqrt(2).*carrier;

%% Transmitter End of Channel sound(txps, fs);

Page 6: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

filter. After recovering our data signal we inversely downsample it to retrieve a discrete signal

whose values correspond to binary symbols, positive samples yielding 1 and negative samples

yielding 0.

2.3.1 Implementation in MATLAB The following MATLAB code excerpt displays the process of receiving and demodulating a

single burst of BPSK transmission. (Appendix B shows code we used to demodulate multiple

bursts):

load('params.mat');

%% Record Transmitted Wave extra = 100; txrx = wavrecord(length(txps)+extra,fs,1); txrx = txrx.';

%% Demodulation txrx = txrx*sqrt(2).*carrier;

%Low Pass Filtering % Design filter with linear phase least-squares method No = 127; % Order Fpass = Rs/2; % Passband Frequency Fstop = 1000; % Stopband Frequency Wpass = 1; % Passband Weight Wstop = 1; % Stopband Weight % Calculate the coefficients using the FIRLS function. b = firls(No, [0 Fpass Fstop fs/2]/(fs/2), [1 1 0 0], [Wpass Wstop]); % Filtering txrx = filter(b, 1, txrx);

Page 7: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

Note the section of the code above labeled ‘Correlate received data with transmitted.’ This is a

necessary to properly align our transmitted symbols with our received, demodulated baseband

signal for BER checking.

In this demodulation code we do not properly accomplish carrier recovery of our signal. Rather

than assuming phase coherence between the carriers at the transmitter and receiver ends, it is

necessary to properly account for phase offsets which are incurred as our carrier travels through

the air.

2.4 Results of PU The following data display BER of the PU seen after transmitting 100k bits. 4800 bits are

transmitted by the PU in each run thus 21 runs were required to transmit 100k bits, for each run

we calculate the average BER observed:

Figure 4: Bit Error Rate Plot

0

0.1

0.2

0.3

0.4

0.5

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

BER

SAMPLES

Bit Error Rate Plot

%Matched filtering rxsymup = conv(txrx,pt); %recovered baseband data signal

%Correlate received data with transmitted %partial cross correlation of rx to tx, to determine offset for lag = 1:length(rxsymup)-length(txsymup)-1 cor(lag) = txsymup*rxsymup(lag:length(txsymup)-1+lag)'; end offset = find(cor == max(cor))-1;

%correct for delay rxsymup = rxsymup(offset+1:length(txsymup)+offset);

%if correlation is negative invert (flip bits) [Crude method to account

for 180deg phase offsets]

if abs(min(cor)) > max(cor) rxsymup = rxsymup*-1; end

%Downsample/Decision/Bit Error Checking rx = real(downsample(rxsymup,os))>0; %downsample and threshold %BER calculation nErr = size(find([tx- rx]),2) bit_error_rate = nErr/N

Page 8: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

The average BER was observed to be 1.59%, however in the data above we see that some test

runs returned very errant BER results. Within these runs the effects of carrier incoherence is

significant. Unfortunately, due to lack of time this we weren’t able to properly correct this issue.

3 Secondary User Establishment The integral component of our DSA system is the SU, and its ultimate goal is to gain access to

the 4 kHz channel owned by the PU. During the PU interburst times its allotted 4 kHz channel is

available and can be safely occupied by the SU. However, if the SU remains present on the

channel as the PU returns, the PU transmissions will suffer from co-channel interference. This is

an undesirable and, in some cases, unacceptable effect and for this reason the SU must vacate the

PU channel; in our experiment we set aside a channel at 6 kHz for the SU to vacate to. The job of

the SU is to then perform spectrum sensing in order to determine when to occupy and when to

vacate the PU channel. The SU must dynamically adjust itself to modulate its data onto two

different carrier frequencies, this is what makes our SU a cognitive radio. Using GNU Radio

software and Python scripts we were able to implement the spectrum sensing and cognition of

our SU.

3.1 GNU Radio Implementation GNU Radio is an open source SDR development environment, where a variety of real-time

signal processing blocks can be dragged and dropped to implement radio systems. We built the

following GNU Radio flowgraph which implements our SU functionality in software:

Figure 5: GNU Radio Flowgraph for SU

Page 9: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

The upper trace in the above figure (starting with Random Source block) implements the

transmission of QPSK modulated data to be output through our soundcard, and the lower trace

(starting with Audio Source block) implements spectrum sensing of the PU channel. In the

section below we discuss the functionality of the above flowgraph by describing some of its

critical blocks.

3.1.1 Blocks In the upper trace of the flowgraph, the Random Source block generates random bytes of binary

data. We specify this source to generate 1 million bytes of data and repeat, allowing the SU to

transmit continuously with no interbursts. This binary data is then streamed into the DPSK Mod

block which we configure to QPSK modulate, upsample, and pulse shape our bits- a similar

procedure to our MATLAB implementation. From here our trace is split into parallel, where the

pulse shaped QPSK signal can choose to modulate a 4 kHz carrier, occupying the PU channel, or

a 6 kHz carrier, vacating the PU channel. This decision is made by the two Multiply Constant

blocks which act as on-off switches for the two parallel streams. These streams are summed

together by the Add block and output by the Audio Sink block to our computer soundcard.

In the lower trace of the flowgraph, the Audio Source block is used to stream the A/D output of

our computer microphone into our flowgraph; this allows us to capture and analyze the audio

band. We then throttle this audio, as recommended for optimum data transfer, into a Log Power

FFT block which acts as an audio spectrum analyzer by continuously updating a 1024 point FFT

of the observed audio. We use a Probe Signal Vector block to record this FFT into an observable

python variable.

3.1.2 Python Scripting When a GNU Radio flowgraph is executed, a python script is generated which defines each of its

blocks, connections, and variables as members of a class[5]; (see Appendix C for our GNU

Radio flowgraph script). After importing this class as well as the each of the modules imported

within it, we can create a separate python script in which we can execute this flowgraph and

dynamically control each of its blocks, variables, and connections. After generating a top block

module from our GNU radio flow graph, we create such a script to implement a cognitive

algorithm for spectrum sensing and dynamic spectrum access.

Page 10: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

3.2 Sensing Algorithm We define the cognition of our SU with the simplified flowchart below:

The above proposes a very simple spectrum sensing algorithm. The first task of our SU cognition

is to determine a few thresholds: we need to determine the threshold of the SU power as well as

the noise floor of the PU channel. The SU power threshold tells us the power level which the SU

never exceeds, and the power of the noise floor determines for us the power which corresponds

to no signal present on the channel. When this is done we turn on our PU and begin the spectrum

access portion of our algorithm. We analyze the FFT of our channel to determine whether or not

the PU is absent or present.

If the PU is absent we occupy its 4 kHz channel, and continue to monitor the FFT of the channel

to ensure that power does not exceed the SU power threshold- for if this occurs we know that the

PU has returned to the channel. As the PU returns to the channel the SU must vacate to the

reserved 6 kHz channel (where bandwidth of signals are such that they do not interfere). Again

we continuously monitor the power of the PU channel. When the power at the PU channel center

frequency drops below the noise floor, we know that the channel is again vacant and the SU

occupies it. This process repeats infinitely.

The python script which implements our SU cognition is given below in Appendix D. Note that

we added a portion of code to calibrate the SU power to match the power level of the PU. The

scenario in which the SU transmits at the same power as the PU tests our system by modeling a

worst case scenario, we discuss the implications of this in the subsection to follow.

Figure 6: Flowchart for SU Cognition

Page 11: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

3.2.1 PU+SU The final test of our project calls for us to run the PU and SU simultaneously, and the

performance of our DSA system is simply measured by the BER of the PU. We note that two

factors will primarily affect the performance of our DSA System.

The first is power of our SU. If the power of the SU is low enough, near the noise floor of our

PU, the SU transmission will effectively go unnoticed by the PU; and in such, the BER recorded

by the PU should maintain near 0. As power of the SU is increased, the effects of co-channel

interference on the PU become greater and greater; in times that the two access the channel

simultaneously PU data may become unrecoverable. Maintaining the power level of the SU to

match the PU, we run this risk.

The second factor to consider is the length of our PU bursts, and this deals with the performance

of our SU algorithm. After sensing the spectrum and triggering the SU to modulate onto into or

out of the PU channel, we notice about a 1 second delay before our GNU Radio generated

module responds. This means if the PU transmits in 2 second bursts, nearly half of the data will

be severely corrupted by SU interference. In the section below, we show results of PU BER

obtained when transmitting at two different burst lengths.

3.2.2 Results

4 Discussion of Results In the data above we show the BER plotted for PU with 2 second bursts and 3 second bursts, in

both we plot the BER obtained for enough PU runs such that 100k bits of data were sent. Data

from our tests with a 2 second PU burst length showed that with the SU turned on the average

PU BER was 13.24%, where the average BER measured from the PU alone was 1.59%. When

PU transmits in 3 second bursts with the SU turned on we saw the average BER of the PU drop

to 5.24%, and with the PU alone average BER was measured to be 1.08%.

Figure 7: BER comparison for two different duty cycles

Page 12: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

This data confirms our expected results that when the lag of the SU switching is compensated for

with longer PU bursts times, BER will decrease. Unfortunately, in the extensive testing of our

PU routines we see that some runs are badly affected by the lack of proper carrier recovery,

producing some errant BER results.

5 Conclusion We were able to establish a workable model for a DSA audio communication system. In

designing our PU we learned to use MATLAB to transmit and receive BPSK modulated data

over an audio channel, and learned of the practical considerations involved in properly

recovering data from wirelessly transmitted signals. In designing our SU we gained valuable

experience in creating GNU Radio waveforms. We also became familiar with the Python

programming language and learned how to create a python script to control GNU Radio

flowgraphs to implement cognitive radio systems.

In our research has we learned that, while promising and increasingly necessary, DSA

implementations are quite difficult. However, smarter and faster CR algorithms can be employed

to ensure non-intrusive navigation of the RF spectrum allowing for efficient sharing and

utilization of this most precious resource.

6 Further Work Much further work can be implemented to improve our research. Firstly and most importantly,

proper carrier recovery needs to be added to our PU receiver code. A second suggestion is to

implement a system with more than one SU vying to access the PU channel. Also, the ultimate

goal of our project would be to implement the system in the CORNET CR testbed, migrating our

system from the audio band to RF with USRPs.

Page 13: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

7 Appendix

7.1 Appendix A %% PU Transmitter Code

%(Uncomment to load stored transmission) %load('transmitter_params.mat');

%% Transmitter End of Channel

%Transmitter Parameters (Comment to transmit stored transmission) %Burst and Interburst times burst_time = 3; interburst_time = 5; %Sampling Rate fs = 48e3; %upsampling factor os = 100; %Symbol Rate Rs = fs/os; %(symbols/second) %Number of bits N = Rs*burst_time; %Number of zeros Nz = Rs*interburst_time; %number of pulses no_pulse = 5;

%Generating random bursts of BPSK symbols %generating bursts of 0,1 with equal probability tx = zeros(no_pulse, N); for i = 1:no_pulse tx(i,:) = rand(1,N)>0.5; end % BPSK modulation 0 -> -1; 1 -> 0 txsym = zeros(no_pulse, N); for i = 1:no_pulse txsym(i,:) = 2*tx(i,:)-1; end

%Upsample txsymup = zeros(no_pulse, N*os); for i = 1:no_pulse txsymup(i,:)=upsample(txsym(i,:),os); end

tx_whole = []; for i = 1:no_pulse tx_whole = [tx_whole upsample(zeros(1,Nz),os) txsymup(i,:)]; end

%% Pulse Shaping our BPSK bursts for transmission

Page 14: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

%Raised Root Cosine Filter for Pulse Shaping alpha=0.1; % roll-off factor of Root Raised Cosine Filter pt = srrc(os,alpha); % impulse response of SRRC filter

%Pulse Shaping BPSK signal txps = filter(pt,1,tx_whole);

% figure; % freqz(txps, 1, 2^12, 'half', fs);

%% Modulation

%center frequency amp = 1; fc = 4000; omegac = fc/fs; n = 1:length(txps); txps_mod = txps.*(amp*sqrt(2)*cos(2*pi*omegac*n));

%Channel- Transmitter End sound([txps_mod zeros(1,0.5*fs)], fs);

%% Save % save paramters and bursts to be seen by receiver save('transmitter_params.mat');

Page 15: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

7.2 Appendix B %% PU Receiver Code

%% Receiver End of Channel %Load transmitter parameters and bursts for BER Checking load('transmitter_params.mat');

%record BPSK bursts extra = 2*fs; len = length(txps_mod) + extra; %number of samples to record txrx1 = wavrecord(len,fs,1)'; %record k = 1e5; txrx1 = txrx1(k:end); %skip soundcard blip figure; plot(txrx1); title('Received Signal');

%% Demodulation n = 1:length(txrx1); txrx = txrx1*sqrt(2).*cos(2*pi*omegac*n); %demodulate

% figure; % freqz(txrx,1,2^12,'half',fs); title('Demodulated Spetrum'); % grid on

%Low Pass Filter Parameters % Design filter with least-squares method No = 127; % Order Fpass = Rs/2; % Passband Frequency Fstop = 1000; % Stopband Frequency Wpass = 1; % Passband Weight Wstop = 1; % Stopband Weight % Calculate the coefficients using the FIRLS function. b = firls(No, [0 Fpass Fstop fs/2]/(fs/2), [1 1 0 0], [Wpass Wstop]);

% figure; % freqz(b,1,2^12,'half',fs); title('Lowpass Filter'); % grid on

% Lowpass filter demodulated signal txrx = filter(b, 1, txrx); % figure; % freqz(txrx,1,2^12,'half',fs); title('Filtered Spetrum'); % grid on

%Matched filtering rxsymup = conv(txrx,pt);

% figure; % subplot(2,1,1); plot(rxsymup); grid on % subplot(2,1,2); plot(tx_whole,'-ro'); % grid on;

Page 16: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

% figure; % subplot(2,1,1); plot(rxsymup); grid on % subplot(2,1,2); plot(txps); grid on

k = 1; span = 10000; thrH = 0.2;

tnErr =0; max_len = round(1.25*size(txsymup,2)); mod = zeros(no_pulse, max_len);

for i = 1:no_pulse %while no samples in span greater than threshold while sum(abs(rxsymup(k:k+span-1)) > thrH*ones(1,span)) < 1 k = k+span; end %save start of pulse start = k;

%until no samples are greater than threshold while sum(abs(rxsymup(k:k+span-1)) > thrH*ones(1,span)) > 0 k = k+span; if k+span-1 > length(rxsymup) k = length(rxsymup)-span+1; break end end %save end of pulse fin = k+span-1;

%record pulse into vector mod(i,1:fin-start+1) = rxsymup(start:fin); % figure; % plot(mod(i,:));

%Correlate to determine bit error rate for lag = 1:length(mod(i,:))-length(txsymup(i,:))-1 cor(lag) = txsymup(i,:)*mod(i,lag:length(txsymup(i,:))-1+lag)'; end offset = find(abs(cor) == max(abs(cor)))-1;

%correct for delay temp = mod(i,:); temp = temp(offset+1:length(txsymup(i,:))+offset);

%if correlation is negative invert (flip bits) if abs(min(cor)) > max(cor) temp = temp*-1; end

fprintf('//////////// Burst %d ////////////\n', i); rx = real(downsample(temp,os))>0; nErr = size(find([tx(i,:)-rx]),2); tnErr = tnErr +nErr;

Page 17: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

bit_error_rate = nErr/N; fprintf('Number of Errors: %d/%d\n', nErr,N); fprintf('Bit Error Rate: %g\n', bit_error_rate);

figure; hold on; plot(temp); grid on plot(txsymup(i,:), 'ro-'); hold off; title('Bit Error Plot') legend('Received', 'Transmitted') grid on end % fprintf('\nFinal Bit Error Calculation\n'); total_BER =tnErr/(no_pulse*N); fprintf('Total Number of Errors: %d\n', tnErr); fprintf('Total Bit Error Rate: %g\n', tnErr/(no_pulse*N));

Page 18: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

7.3 Appendix C #!/usr/bin/env python

##################################################

# Gnuradio Python Flow Graph

# Title: Su Link

# Generated: Wed Jul 24 03:13:55 2013

##################################################

from gnuradio import analog

from gnuradio import audio

from gnuradio import blks2

from gnuradio import blocks

from gnuradio import digital

from gnuradio import eng_notation

from gnuradio import gr

from gnuradio.eng_option import eng_option

from gnuradio.gr import firdes

from grc_gnuradio import wxgui as grc_wxgui

from optparse import OptionParser

import numpy

import wx

class SU_Link(grc_wxgui.top_block_gui):

def __init__(self):

grc_wxgui.top_block_gui.__init__(self, title="Su Link")

_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"

self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

##################################################

# Variables

##################################################

self.samp_rate = samp_rate = 48000

self.samp_per_sym = samp_per_sym = 50

self.LF_choose = LF_choose = 1

self.HF_choose = HF_choose = 0

self.FFT_Size = FFT_Size = 1024

##################################################

# Blocks

##################################################

self.random_source_x_0 = gr.vector_source_b(map(int,

numpy.random.randint(0, 256, 1000000)), True)

self.fft_probe = blocks.probe_signal_vf(FFT_Size)

self.digital_dxpsk_mod_0_0 = digital.dqpsk_mod(

samples_per_symbol=samp_per_sym,

excess_bw=0.1,

gray_coded=True,

verbose=True,

log=False)

self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1,

samp_rate)

self.blocks_multiply_xx_0_0_0 = blocks.multiply_vcc(1)

self.blocks_multiply_xx_0_0 = blocks.multiply_vcc(1)

self.blocks_complex_to_real_0 = blocks.complex_to_real(1)

Page 19: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

self.blocks_add_xx_0 = blocks.add_vcc(1)

self.blks2_logpwrfft_x_0 = blks2.logpwrfft_f(

sample_rate=samp_rate,

fft_size=FFT_Size,

ref_scale=2,

frame_rate=30,

avg_alpha=0.3,

average=True,

)

self.audio_source_0 = audio.source(samp_rate, "", True)

self.audio_sink_1_0 = audio.sink(samp_rate, "", True)

self.LF_carrier = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE,

4000, 0.5, 0)

self.LF = blocks.multiply_const_vcc((LF_choose, ))

self.HF_carrier = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE,

6000, 0.5, 0)

self.HF = blocks.multiply_const_vcc((HF_choose, ))

##################################################

# Connections

##################################################

self.connect((self.HF_carrier, 0), (self.blocks_multiply_xx_0_0_0,

1))

self.connect((self.digital_dxpsk_mod_0_0, 0),

(self.blocks_multiply_xx_0_0_0, 0))

self.connect((self.digital_dxpsk_mod_0_0, 0),

(self.blocks_multiply_xx_0_0, 0))

self.connect((self.LF_carrier, 0), (self.blocks_multiply_xx_0_0, 1))

self.connect((self.random_source_x_0, 0),

(self.digital_dxpsk_mod_0_0, 0))

self.connect((self.blocks_multiply_xx_0_0_0, 0), (self.HF, 0))

self.connect((self.HF, 0), (self.blocks_add_xx_0, 1))

self.connect((self.blks2_logpwrfft_x_0, 0), (self.fft_probe, 0))

self.connect((self.audio_source_0, 0), (self.blocks_throttle_0, 0))

self.connect((self.blocks_throttle_0, 0), (self.blks2_logpwrfft_x_0,

0))

self.connect((self.blocks_add_xx_0, 0),

(self.blocks_complex_to_real_0, 0))

self.connect((self.blocks_complex_to_real_0, 0),

(self.audio_sink_1_0, 0))

self.connect((self.blocks_multiply_xx_0_0, 0), (self.LF, 0))

self.connect((self.LF, 0), (self.blocks_add_xx_0, 0))

def get_samp_rate(self):

return self.samp_rate

def set_samp_rate(self, samp_rate):

self.samp_rate = samp_rate

self.blocks_throttle_0.set_sample_rate(self.samp_rate)

self.blks2_logpwrfft_x_0.set_sample_rate(self.samp_rate)

self.LF_carrier.set_sampling_freq(self.samp_rate)

self.HF_carrier.set_sampling_freq(self.samp_rate)

def get_samp_per_sym(self):

return self.samp_per_sym

Page 20: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

def set_samp_per_sym(self, samp_per_sym):

self.samp_per_sym = samp_per_sym

def get_LF_choose(self):

return self.LF_choose

def set_LF_choose(self, LF_choose):

self.LF_choose = LF_choose

self.LF.set_k((self.LF_choose, ))

def get_HF_choose(self):

return self.HF_choose

def set_HF_choose(self, HF_choose):

self.HF_choose = HF_choose

self.HF.set_k((self.HF_choose, ))

def get_FFT_Size(self):

return self.FFT_Size

def set_FFT_Size(self, FFT_Size):

self.FFT_Size = FFT_Size

if __name__ == '__main__':

parser = OptionParser(option_class=eng_option, usage="%prog: [options]")

(options, args) = parser.parse_args()

tb = SU_Link()

tb.Run(True)

Page 21: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

7.4 Appendix D #!/usr/bin/env python

##################################################

# Cognitive Algorithm for GNU Radio Flowgraph

# Title: SU Run

# Generated: Thu Jul 18 23:04:24 2013

##################################################

from gnuradio import analog

from gnuradio import audio

from gnuradio import blks2

from gnuradio import blocks

from gnuradio import digital

from gnuradio import eng_notation

from gnuradio import gr

from gnuradio import window

from gnuradio.eng_option import eng_option

from gnuradio.gr import firdes

from gnuradio.wxgui import fftsink2

from gnuradio.wxgui import forms

from grc_gnuradio import wxgui as grc_wxgui

from optparse import OptionParser

import numpy

import wx

from SU_Link import SU_Link

import time

import math

import numpy

if __name__ == '__main__':

parser = OptionParser(option_class=eng_option, usage="%prog: [options]")

(options, args) = parser.parse_args()

tb = SU_Link()

tb.start()

def find_power():

vector = tb.fft_probe.level()

return vector[85]

def calc_max_power():

for i in range(1000):

temp = find_power()

if i == 0:

max_pow = temp

elif temp > max_pow:

max_pow = temp

return max_pow

def vacate():

tb.LF.set_k((0,))

tb.HF.set_k((1,))

def occupy():

tb.HF.set_k((0,))

tb.LF.set_k((1,))

return

def off():

tb.HF.set_k((0,))

Page 22: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

tb.LF.set_k((0,))

return

def yes_no(message):

yes = set(['yes','y', 'ye', ''])

choice = raw_input(s).lower()

if choice in yes:

return True

else:

return False

#---------------------Calibrations-------------------------------------

off()

#Turn on Primary User to Calibrate SU Power

print 'Calibrating Secondary User Power\n-----------------------'

raw_input('Turn on PU and press Enter')

PU_thresh = calc_max_power()

raw_input('Press Enter when PU tone is finished')

print 'Primary User power Threshold:', PU_thresh, 'dB'

time.sleep(1)

#Turn on SU to calibrate to match PU

print '\nTurning On SU...'

occupy()

time.sleep(0.1)

SU_pwr = calc_max_power()

print 'Secondary User power Threshold:', SU_pwr, 'dB'

while SU_pwr > PU_thresh + 10 or SU_pwr < PU_thresh - 10:

if SU_pwr > PU_thresh + 10:

print 'Power too high, lower volume'

else:

print 'Power too low, increase volume'

raw_input('Press Enter')

SU_pwr = calc_max_power()

print 'Secondary User power Threshold:', SU_pwr, 'dB'

SU_thresh = SU_pwr + 10

off()

time.sleep(2)

#Find Noise Floor

#Shift/Turn-Off SU

vacate()

print 'HF on'

time.sleep(3)

noise = calc_max_power() + 10

print 'Noise Floor Threshold:', noise, 'dB'

#Turn Off SU and on PU

off()

time.sleep(1)

print "Turn on PU User Link"

Page 23: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

#------------------DSA Algorithm--------------------------------

#Initial State

pwr = find_power()

if (pwr < noise):

channel = 0

else:

channel = 1

while True:

#

if channel == 0:

#Channel is idle, Turn on SU

occupy()

#While power is less than SU threshold continue

while pwr < SU_thresh:

pwr = find_power()

channel = 1

else:

#Primary User is active, Turn off SU or vacate

vacate()

#While channel is active

while pwr > noise:

pwr = find_power()

channel = 0

tb.stop()

Page 24: Contentsreu.wireless.vt.edu/pdfs/Final Paperamosajoandsamhenderson.pdf · Dynamic Spectrum Access Using Audio Amos Ajo , Virginia Commonwealth University & Samuel Henderson, University

8 References 1.) S. Haykin, "Cognitive radio: brain-empowered wireless communications," IEEE Journal, vol. 23,

pp. 201-220, 2005.

2.) Z. Qing and B. . M. Sadler, "A survey of dynamic spectrum access. Signal Processing Magazine,,"

IEEE, vol. 24.3, pp. 79-89, 2007.

3.) C. Yao, "DP-QPSk in a 100G Fiber optic Transmission," Fiber Optic 4sale. Co, 13 03 2013.

[Online]. Available: FO4SALE.COM. [Accessed 29 07 2013].

4.) "Simulink Exercises for "Digital Communications: A Discrete-Time Approach," by M. Rice."

Simulink Exercises for "Digital Communications: A Discrete-Time Approach," by M. Rice. N.p., n.d.

Web. 25 July 2013. <http://ricesimulink.groups.et.byu.net/bpsk.phtml>.

5.) "Tutorials Write Python Applications." GNU Radio. Redmine, n.d. Web. 31 July 2013.

<gnuradio.org/redmine/projects/gnuradio/wiki/TutorialsWritePythonApplications>.