Mobile Computing GNU Radio Laboratory1: Basic test 1. Now, let us try a python file. Download, open, and read the file base.py, which contains the Python code for the flowgraph as in the previous test. The simple flowgraph is composed of the following blocks: a signal source gr.sig_source_f, producing a stream of floats a multiplier gr.multiply_const_ff, accepting float inputs and producing float outputs a signal sink audio.sink, accepting a stream of floats and sending them to the speakers. 2. Run it from the terminal ( $ chmod 0755 base.py to make it executable): $./base.py 3. Try another python file, base_gui.py. Read the file. It does the same thing as base.py, but also has a GUI with two graphs. The upper graph shows the signal in the time domain the same way as an oscilloscope. The lower graph shows a power spectrum of the signal in db scale based on an FFT. 4. Run it from the terminal ( $ chmod 0755 base_gui.py ): $./base_gui.py 5. Download test.wav $ wget http://academic.csuohio.edu/yuc/buf/test.wav Modify base_gui.py to replace the following line self.src = gr.sig_source_f(fs_src, gr.gr_sin_wave, 440, 1.0) with the following self.src = gr.wavfile_source( test.wav, True) 6. Repeat step 4
Mobile Computing GNU Radio Laboratory2: BER Performance & AM A. Introduction Performance of digital communication is oftentimes measured in BER (bit error rate) in the presence of noise, i.e., SNR (signal to noise ratio). For example, the BER of 10-3 denotes 1 bit out of 1000 bits would be corrupted on the average. If the packet size is 1000 bits (125 bytes), what is the probability that the receiver fails to get the packet successfully? (Hint: Any bit position is corrupted, the entire packet is considered lost.) Obviously, BER greatly depends on SNR because a stronger noise increases BER and a stronger signal power decreases BER. Note that BER also depends on how the message is encoded. Suppose you re sending a series of binary number using voltage values between 0~3V. 0V and 3V denote binary number 0 and 1, respectively. However, if the receiver detects, for example, 0.8V, it can be considered as 0 because it is closer to 0V. There exists a high tolerance to noise. The tolerance margin is about 1.5V. On the other hand, if you arrange differently so that the voltage value represent two binary digits. I.e., 0V for 00, 1V for 01, 2V for 10, and 3V for 11. Communication efficiency is improved at the cost of resistance to noise. Now the tolerance margin is reduced to about 0.5V. In this lab, we will learn the BER performance versus SNR with different modulation schemes such as ASK, 4-ASK and QAM. The corresponding BER performance differs because they exhibit different tolerance margin to noise. Next, we also conduct experiments on AM-modulated analog signals. B. Amplitude Shift Keying (ASK) and 4-ASK Amplitude-shift keying (ASK) is a form of modulation that represents digital data as variations in the amplitude of a carrier wave. The simplest and most common form of ASK operates as a switch, using the presence of a carrier wave to indicate a binary one and its absence to indicate a binary zero. This type of modulation is called on-off keying. More sophisticated encoding schemes have been developed which represent data in groups using additional amplitude levels. For instance, a four-level encoding scheme can represent two bits with each shift in amplitude (4-ASK); an eight-level scheme can represent three bits (8-ASK); and so on. (From Wikipedia) Step 1: In ASK, 1 is used to represent binary digit 1 and -1 for binary digit 0. The following are the blocks in grc for this lab. Random Source (Sources category) Chunks to Symbols (Misc Conversions category) Noise Source (Sources category) Add (Operators category) Constellation Decoder (Modulators category) File Sink (Sinks category) File Sink (Sinks category) WX GUI Constellation Sink (WX GUI Widgets category) WX GUI Scope Sink (WX GUI Widgets category) Here are the details of the blocks. Random source: We will use Random Source as an input source (a series of binary digits 0 and 1). It generates random numbers based on the parameters.
[min, max) is [0,2) Output type is Byte 10 M samples and No repeat. For the above parameters, 10M samples of 0 and 1 are generated randomly. Chunks to Symbols: This block is used to modulate the input source based on the ASK modulation rule (binary digit 1 to +1 and binary digit 0 to -1). It converts Bytes to symbols and achieves Amplitude shift keying. Byte to Complex, 1 dimension Symbol table: 1, -1 Noise Source: The above symbol is added with noise from the Noise Source block. Complex output, Gaussian, Any seed number Amplitude: 0.2 (Noise amplitude can be adjusted by varying this field.) Add: Add symbol and noise. Complex type Constellation Decoder: The SN (source and noise) is then fed to Constellation Decoder block, which converts the symbol back to binary digits. SNR can be adjusted by changing the amplitude of the Noise Source while that of symbols from Chunks to Symbols is 1. Symbol position: 1, -1 Symbol value: 0, 1 You may want to add Throttle block just after the Add block to control the signal flow and thus, to avoid CPU congestion. Please see the warning message window in the grc. Step 2: To find out the BER performance, have two File Sink blocks, one from the Random Source and the other one from Constellation Decode. Specify the files names. To get the BER, execute the grc file and do the following. $ cmp -l file1 file2 wc -l Calculate BER for noise amplitudes 0.707, 0.630, 0.562, 0.501, 0.446, 0.398, 0.354, 0.316, 0.282, 0.251, and 0.224 for SNR=0dB, 1dB,, 10dB, respectively. (Explain these numbers.) Plot the BER vs SNR curve. In the plot, make the SNR on the db scale and BER on the log scale. * Hint: r.m.s (root mean square) of signal = root((1^2+1^2)/2) = 1 noise amplitude = sqrt(no/2), or No=2*amplitude^2 Therefore, to make SNR=0, No=1 and thus, noise amplitude is 0.707 Similarly, to make SNR=1dB, No=0.7938 and thus, noise amplitude is 0.630 Step 3: To visualize the effect of noise, add Scope Sink after the Add block and another Scope Sink after the Chunks to Symbols block. Make their window size (500,100). (What is your observation?) Also, add Constellation Sink after the Add block. (Explain what you see?) To dynamically change the amplitude of noise, add WX GUI Slider block in WX GUI Widgets category. Change the ID to noiseamp, default value 0.2, minimum 0, maximum 1, and Num steps 20. Open the Noise Source block to change the amplitude to noiseamp. Now, when you execute the grc, you can dynamically change the amplitude of the noise. Step 4: Repeat the above experiment for 4-ASK. Here are the changes that should to be made. - Random Source: [0,4) - Chunks to Symbols Symbol table: 1.342, 0.447, -0.447, -1.342 (Explain these numbers.) - Constellation Decoder Symbol position: 1.342, 0.447, -0.447, -1.342 Symbol value: 0, 1, 2, 3 Calculate BER for noise amplitudes 0.707, 0.630, 0.562, 0.501, 0.446, 0.398, 0.354, 0.316, 0.282, 0.251, 0.224, 0.199, 0.177, 0.158, 0.141, 0.125, and 0.112 for SNR=0dB, 1dB,, 16dB, respectively.
(Explain these numbers.) Plot the BER vs SNR curve. How are the two plots (ASK and 4-ASK) different? Is it similar to those found in textbooks? Hint: r.m.s. of signal = sqrt((1.342^2+0.447^2+0.447^2+1.342^2)/4) = 1 C. 4-QAM Quadrature amplitude modulation (QAM) is both an analog and a digital modulation scheme. It conveys two analog message signals, or two digital bit streams, by changing (modulating) the amplitudes of two carrier waves, using the amplitude-shift keying (ASK) digital modulation scheme or amplitude modulation (AM) analog modulation scheme. These two waves, usually sinusoids, are out of phase with each other by 90 and are thus called quadrature carriers or quadrature components hence the name of the scheme. The modulated waves are summed, and the resulting waveform is a combination of both phase-shift keying (PSK) and amplitude-shift keying (ASK), or in the analog case of phase modulation (PM) and amplitude modulation. In the digital QAM case, a finite number of at least two phases, and at least two amplitudes are used. (From Wikipedia) Step 5: In QAM, digital information is contained in both amplitude and phase then what should be dimension field in the Chunks to symbols block? Hint: a+ia, a-ia, -a+ia, -a-ia rms of signal = sqrt(2a^2 *4/4) = 1.414 a = 1, thus, a=0.707. In other words, 0.707+i0.707, 0.707-i0.707, -0.707+i0.707, -0.707-i0.707 D. Analog Communication - AM Receiver Amplitude modulation (AM) is a technique used in electronic communication, most commonly for transmitting information via a radio carrier wave. AM works by varying the strength of the transmitted signal in relation to the information being sent. For example, changes in the signal strength can be used to specify the sounds to be reproduced by a loudspeaker, or the light intensity of television pixels. (From Wikipedia) This part of the lab is borrowed from Prof. the homepage of S. Katz, California State University, Northridge. It uses a data file that contains several seconds of recorded signals from the AM broadcast band, which was obtained from the USRP. Step 6: Download and unzip the file, am_usrp710.dat (>20MB). (wget http://academic.csuohio.edu/yuc/buf/am_usrp710.dat) Step 7: In grc, construct the flow graph shown below consisting of a File Source (Sources category) and Low Pass Filter (Filters category). Place one FFT Sink (WX GUI Widgets category) at the output of the File Source and another FFT Sink at the output of the Low Pass Filter. Set the Sample Rate in the variable block to 256000. This is the rate at which the saved data was sampled. Place Variable (Variable category) to set the decimation rate. Place a Throttle block right after the File Source block. File Source: Locate the am_usrp710.dat file in the File parameter. Set Output Type to Complex. Set Repeat to Yes. This will cause the data to repeat so that you have a continuously playing signal. Throttle: Put it in between File Source block and Low Pass Filter block. Variable:
Set the ID to resamp_factor and the Value to 4. Low Pass Filter: This is to select the station at 710 KHz (or 0KHz) and thus, to eliminate all but the one station that we want to receive. Since the station at 710 KHz has been moved to 0 KHz (in the USRP), a low pass filter is used. Set Cutoff frequency to 5 KHz (5000) because the station bandwidth is 10 KHz. Set Transition width to 100 Set Decimation factor to resamp_factor. (This is to decimate the incoming data. That means that it will divide the incoming data rate by the decimation factor. In this example, the incoming 256K samp/sec data will be converted down to 256K/4 = 64K samp/sec.) Set Sample Rate to samp_rate/resamp_factor FFT Sink(1) Set Window size to 500,100 Set Grid Position (1,1,1,1) FFT Sink(2) Set the Sample Rate to samp_rate/resamp_factor Set Window size to 500,100 Set Grid Position (2,1,1,1) Step 8: Execute the flow graph. You should observe an FFT display peaked at several places including 0 KHz. Note the followings: (i) This data was recorded with a USRP set to 710KHz. Thus, the signal you see at the center (indicated as 0 KHz) is actually at 710 KHz. Similarly, the signal at 80 KHz is actually at 710KHz + 80KHz = 790KHz. (ii) The display spans a frequency range from just below -120KHz to just above 120KHz. This exact span is 256KHz, which corresponds to the Sample Rate that the data was recorded at. (iii) The peaks that you observe on this display correspond to the carriers for AM broadcast signals. You should also be able to observe the sidebands for the stronger waveforms. In another FFT display, you can view the signals with greater resolution within the cutoff range defined in the Low Pass Filter. I.e., you should now observe a frequency span of only 10KHz, -5 KHz to +5KHz. (What actual frequency range does this correspond to?) You may need to click on Autoscale button to scale the data. You may also find it useful to click the Stop button on the FFT plot to see this more clearly. (Do they work well? If not, why?) You may need to Force Quit to stop the flow graph execution. Step 9: The next step is to demodulate the signal and to view/listen to the demodulated AM waveform. We need to eliminate the two FFT Sink s and add the following blocks. Complex to Mag (Type Conversions category): Place it at the output of the Low Pass Filter. In the case of AM, the baseband signal is the envelope or the magnitude of the modulated waveform. Use this block to demodulate the signal. Scope Sink (Graphical Sinks category): Place it at the output of the Complex to Mag. Change its Type to Float. Set Window size to (500,100). Multiply Const (Operators category): As can be seen from the Scope Sink in the above, the values of the samples from the AM demodulator (Complex to Mag) are too large for the speaker (Audio Sink). We need to apply an attenuator to reduce the size of the samples. Place a Multiply Const block at the output of the Complex to Mag block. Set the IO Type of the block to Float. Set the Constant in the Multiply Const block to volume WX GUI Slider (WX GUI Widgets category) Add a WX GUI Slider block to control the volume of Multiply Const block.
Set Default to 0.05, Minimum to 0, Maximum to 0.1, and Num Steps to 100. Scope Sink (Graphical Sinks category): Place another Scope Sink at the output of the Multiply Const block to see the values of the volume-controlled signal. Change its Type to Float. Set Window size to (500,100). Execute the flow graph. Observe the difference in signal values of the two scope displays. Change the volume of the Multiply Const from the WX GUI Slider to observe that the signal values become smaller (appropriate for the speaker). Step 10: Audio Sink (Sinks category): Now, remove the second Scope Sink and place Audio Sink at the output of the Multiply Const block. Set Sample Rate to 48KHz. Execute the flow graph. You will probably hear a distorted signal coming out of the speaker. Reduce the slider until the audio is easy to understand. This will probably be around 3m (.003). You now have a functioning AM receiver. Step 11: Rational Resampler (Filters category): However, note that the sample rate out of the Complex to Mag block is 64K and most current audio cards require a sample rate of at least 44.1KHz. In order to convert 64K to 48K (close to 44.1), we need to divide (decimate) by 4 and multiply (interpolate) by 3. Place this block between Multiply Const and Audio Sink block. Set Decimation to 4 and Interpolation to 3. Set its Type to Float to Float. Execute the flow graph. You will hear a better signal coming at the volume of around 3m (.003). Step 12: In step 8, we observed there exist other stations too. To see it again, place an FFT sink at the output of the file source, leaving the rest of the flow graph unchanged. Execute the flow graph and observe the location of the other stations in the spectrum. Note that there is a fairly strong signal at 80 KHz (really 710 + 80 = 790 KHz). Let us listen to 790KHz. In order to receive this signal we need to shift it down to zero frequency so that it will pass through the low pass filter. One way to accomplish this is to multiply it by a sinusoid. Signal Source (Sources category): Set its parameters to output a Cosine at a frequency of -80000. This negative frequency will shift the entire spectrum to the left by 80KHz. Multiply (Operators category): Disconnect the flow between the File Source and Low Pass Filter (1 st and 3 rd bock in step 7) Place a Multiply block. Two inputs to this block are the File Source (1 st block in step 7) and the Signal Source (just above). The output connects to the Low Pass Filter block (3 rd block in step 7). Execute the flow graph. You will hear a different station, probably best heard at the volume of around 20m. Step 13: Add another WX GUI Slider block (WX GUI Widgets category) so that you can adjust the frequency with a slider. In other words, name the variable to station_freq and the Frequency
parameter of the Signal Source block is set to station_freq. How to set the parameter for this Slider? Test your flow graph and demonstrate that it works. You may need to adjust your volume slider for each station. This is because the stations are at varying distances away from the receiver and have different transmitted power. Step 14: The volume adjustment can be automated with an Automatic Gain Control (AGC) block. This block works by sampling its own output and adjusting its gain to keep the average output at a particular level. Insert the AGC2 block (Level Controls category) between the Low Pass Filter and the Complex to Mag block. The audio card can only accept values between -1.0 and 1.0. We want the AGC2 to adjust the gain so that the sample values are always in this range. Set Gain to 0.2 and Maximum Gain to 1. This means the AGC2 block will adjust its gain so that the average output value is 0.2. Set the Attack to 6.25E-4 and the Decay to 1E-5. Leave the other parameters at their default values. Once the volume to a comfortable level on the first station you hear, you no longer need to adjust the volume again. The radio functions the same as a hardware radio.