*click on the images to get a larger view
I hope everyone has successfully installed GNURADIO under ubuntu environment by following my other post. So it’s time to do some real action with it.
In this walkthrough, I’m not going to connect the GNURADIO with the USRP since its at the lab and not in my room with me. This is one advantage with GNURADIO. You can fiddle with the GNURADIO itself and see that what we’ve learned in communication theories actually work.
We all know that a single cosine wave will show up as two positive peaks that are symmetric along the y-axis when you plot it in frequency range(Like the image below).
Let’s try doing this simple task with GNURADIO.
First, open up the gnuradio-companion program. You can either search by typing ‘gnuradio’ in the dash home screen….or…
you can either open up a terminal(click the ‘terminal’ icon or press Ctrl+Alt+T) and enter “gnuradio-companion”.
the program will launch and you’ll probably have a blank screen. If not, just click the “create a new flow graph” to get one.
now we’re going to place two components: “signal source” and “WX GUI FFT sink” like the image
Some might say “Q: where do I find the components?”. The answer is, you find the block you need on the list of blocks on the right side of the screen. Of course, even then it’s quite frustrating to click on every folder to find what you seek because you don’t know which one is in which folder since you’re probably a beginner. Here’s how to ‘search’ the block you need.
1. just click anywhere in the block list
2. Press “Ctrl+F” and a small box where you can type in the search keyword will appear below. In that box, let’s type in “signal” in order to search the signal source block. No need to press ‘enter’ after typing in the keyword.
3. Then scroll down the the bottom of the list and there will be a list of search results. There you’ll find the ‘signal source’ block. Just drag this to the center of the flow graph and you’ll have the block you need.
Now you can easily find the block you need. But just by placing the blocks won’t mean that it will automatically connect the blocks for you. Here’s how to connect the blocks.
1. first click the blue ‘out’ bulb and then click the ‘in’ bulb on the other component. Actually, the order of clicking is redundant.
2. Then you’ll have a connection between the two components
3. in case you want to delete the connection, click on the wire. the color will turn into cyan and then press ‘delete’ key.
Now that you’ve successfully connected the components, lets run the simulation.
if you want to run the flow graph, press the two buttons shown in the image accordingly. I’m not sure what the first button(the colorful icon with three different shapes) does but my guess is that I checks if the flow graph has no errors and saves it before executing it. the second button is the one that actually executes the flow graph.
wow! looks like we’ve got something! however, after a few seconds…
the fft plot window turns grey and nothing works. nothing can be clicked and it looks like as if the window is dead.
when you try to close the fft plot window, you’ll be asked whether you’ll abort this window with brute force. Just click abort and get outta there.
What’s the problem? It definitely looked like the fft plot was working then all of a sudden it didn’t work. If you look at the log window at the bottom of the program, you’ll find out what the problem is.
at the log, it says that this flow graph needs a ‘throttle’ block. A throttle block defines the speed of the data stream manually. You’ll see what this means in a short while. Since this flow graph works within the computer itself without any connection to the USRP, the computer CPU will pour all its resources into simulating this flow graph. the problem is, if this is the case, the simulation will be ‘over’supplied with calculating power that the FFT plot graph will be overwhelmed with all the calculated results pouring out from the cpu. As a result, the fft plot will break apart with exhaustion and that why we get a grey FFT plot window after a few seconds. In order to fix this, there needs to be some components that will control/limit the amount of data that will be utilized in this flow graph. that is what the ‘throttle’ block shall do.
Find the throttle block in the block list(use the Ctrl+F method to search it fast) and drag and drop it in the flow graph.
* you’ll find ‘throttle’ and ‘throttle(old)’. I’ve used the ‘throttle’ block.
the throttle block will automatically have its ‘sample rate’ defined as 32k. This means that the throttle block will flush out 32k samples per second when the simulation is executed. But where on earth did the value ’32k’ come from? it comes from the ‘variable’ block where it defined a variable named ‘samp_rate’ and with a corresponding value of 32k. If you double click the throttle block,
you’ll see that the sample rate of the throttle block has been given as ‘samp_rate’ which is the variable with a value of 32k.
connect the blocks like this image.
execute the flow graph and a fully functioning, error-free FFT plot will pop up. you can change the graph with the buttons on the right side of the plot.
But the journey ain’t over yet. we originally wanted to see a symmetrical two peaks on the FFt plot but this only shows one. how can we fix this?
to get straight to the point, here’s the flow graph and the result that gave me the result that I wanted.
before giving you the details on why this flow graph works, let me tell you what changes I’ve made in the flow graph.
the most noticeable change is that I’ve added a few more blocks such as ‘float to complex’, ‘constant source’. you can find these blocks easily by searching them in the block list.
another huge change is that the ‘out’ and ‘in’ bulbs have changed its color from ‘blue’ to ‘orange’!! this means that the data type of the input&output has changed from ‘complex’ to ‘float’. I’m sure that you all know what ‘complex’ and ‘float’ means. Here’s an example of how to change this data type. I’ll use the throttle block in this example.
1. double click the throttle block
2. properties window will show up. from there, change the ‘type’ from ‘complex’ to ‘float’. Then press ‘confirm’
3. there you have it. the in/out bulbs have turned orange!
now repeat this work for all the blocks that have orange in/outs in the flow graph. Remember, the input of the FFT plot block cannot change its data type. It can only receive complex inputs and recalling the function of FFT analysis, this is reasonable. This is why I added the ‘float to complex’ block and connected the ‘real’ part with the throttled signal source(cosine wave) and the ‘imaginary’ part with a null source(constant source with a value of ‘zero’). This way I should have created an absolutely 100% sure ‘pure cosine wave’. I’ll prove that this is true in a while.
Now, its time to give you a brief and ‘messy’ explanation on why the second flow graph gives us two peaks in FFT plot and the original flow graph didn’t. In the original flow graph, we have utilized a signal source with a ‘complex’ data type. this means that a ‘complex’ cosine has been created. WTF does this mean? As everybody knows, sinusodial waveforms have a close relationship with complex numbers and exponential expressions. That relationship is like this:
a sinusodial wave can be created easily with an exponential that has an imaginary index. This will automatically create a ‘real’ cosine and an ‘imaginary’ sine wave. This is what the ‘complex’ version of signal source creates. When the ‘complex’ signal source says that it created a cosine wave, yeah sure it did create a cosine wave in the real part. But it also created a sine wave in the imaginary part as well. this is what we’ve overlooked in the first flow graph.
In the original flow graph, this ‘complex’ signal that actually contains both cosine and sine wave shall be analyzed by the FFT plot block and both cosine and sine wave shall appear on the FFT graph. We know that in the FFT, cosine and sine wave shall have graphs like the following:
if both waveforms are included in the input signal of the FFT graph block, the FFT shall show a FFT that is the sum of both cosine and sine FFT which will result only one peak. Therefore, “one-peak” result that came out from the original flow graph is not a consequence of an error or malfunction.
If you have understood until now, you would’ve have already figured out why I’ve modified the original flow graph into the second one. In order to obtain a ‘two-peak’ FFT plot, the input of the FFT plot block should be a 100% pure cosine signal that has no sine wave or whatsoever. That is why I changed the signal source in to a ‘float’ type so that it will only generate a cosine wave and no sine wave in the imaginary part since there is no imaginary part in a float datatype. The input of the FFT Plot block needs to be ‘complex’, so I added the ‘float to complex’ block. We want to keep the pure ‘float’ cosine, so I have connected the imaginary input of the ‘float to complex’ block to a constant source with a value of ‘0’. In other words, the imaginary part will be always zero and meaningless. In this way, the FFT Plot block shall only recognize a cosine signal and it will show us the ‘two-peak’ FFT plot that we expected at the beginning of this post.
The following images prove that my explanation was right. I have checked the waveforms in time domain in order to see whether the signals were purely cosine or not. Lets look at it one by one.
Here, in the original flow graph I have added a “WX GUI Scope Sink” block in order to check the waveform of the signal in time domain. Think of it has an oscilloscope.
this is the graph that comes from the ‘scope sink’. There’s a green line and a blue line. The two lines come from two channels like in the oscilloscope. Anyway, the two channels each corresponds to ‘real’ and ‘imaginary’ parts of the complex waveform. You can see that one is a cosine wave and the other is a sine wave.
I’ve also added a ‘scope sink’ in the second flow graph like this.