simple sinusoidal signal source and FFT plot diagram + some useful GNURADIO tips

*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.
this is the scope result and it definitely supports my explanation. The cosine component is successfully placed in the ‘real’ part and the the ‘imaginary’ component is zero. This is a 100% pure cosine ‘complex’ wave which will undoubtedly give us the ‘two-peak’ FFT plot. 

installing gnuradio to use usrp

the gnuradio is the software to control the USRP device. you can make a flow of diagrams to command the USRP to do the job you want.

let’s skip the boring list of background information about gnuradio and lets find out how to install the gnuradion under the Ubuntu 12.04.
first, install the ubuntu. 
second, and this is important, make sure that all the updates have been completed. When you first install ubuntu, there’s going to be a bunch of software updates that needs to be done. Normally, the ‘update manager’ program pops up after the installation of ubuntu where all you have to do is click ‘install updates’. If you accidently closed this window or missed it, you can easily access it by clicking the ‘crank’ icon on the right-top corner, and then you’ll see a phrase “software update… blah blah something”. I’m sorry but right now my computer is all upto date so I’ve forgotten the exact words but if you click it, the update manager will show up again.
third, after you’ve complete all the updates, then you can actually install it. open a terminal(you can open one by pressing Ctrl+Alt+T) and then type in :
wget && chmod a+x ./build-gnuradio && ./build-gnuradio
of course, you should have an access to the internet. when you type this in and press enter, there’s going to be some text and then it will ask you “blah blah blah `~~…. proceed?”
type in ‘y’ and then press enter..
then there’s going to be a bit more text and then another ‘blah blah ~~~ proceed?’ comes up.
again, type in ‘y’ and press enter.
then it should show ‘THIS MAY TAKE SOME TIME’.
when they say it may take some time, they really mean it. 
the terminal screen may look like as if it halted and the system is malfunctioning but don’t believe everything what you see: it is actaully installing the program. only that it isn’t printing the details up on the terminal screen. A really good laptop may only take 1~2 hours. A very sucking laptop like mine will take give or take 6 hours. If you think your computer is pretty much similar to mine, I recommend you to install it before going to bed. 
anyway wait for it.
then, it shall be done. the final text will ask you if you will send your successful installation log to the ettus company. you can either say ‘y’ or ‘n’. 
In some cases, during the installation, it may fail. Even though you’ve done all the updates before doing the installation and it still fails, I’m sorry. that’s out of my league.  The only advice I could give you is to start googling.

usrp connection ip setting/configuration

현재 사용하는 usrp 기종은 usrp n210 이다.
일단 usrp 의 ip는 디폴트로로 지정되어 있다.
따라서 usrp를 컴퓨터로 연결해서 사용하고 싶다면, 아래와 같이 컴퓨터의 ip를 세팅해주어야 접속하여 사용할 수 있다.(usrp를 다루기 위한 소프트웨어로 gnuradio를 사용하고 있다. 이 프로그램은 리눅스 기반의 우분투에 설치하여 사용하고 있으므로 스샷은 윈도우가 아닌 우분투 환경이다.)

I am using the ‘usrp n210’

as I found out, the usrp has a default ip address:

so in order to connect to the usrp with your computer, you shall need to configure your network setting like the following:(since I’m using gnuradio software in Ubuntu 12.04 in order to control the usrp, the interface of the screenshots are ubuntu)

ip 세팅이 제대로 안된 상태에서 gnuradio로 간단한 usrp 작동을 실험한 경우 밑에 에러메시지가 뜨는 것을 볼 수 있다. 의미는 로 가는 기기를 발견하지 못했다…
비록 usrp를 컴퓨터와 랜선으로 연결하였고 ‘연결되었음’이라고 떳다고 하더라도 컴퓨터가 아직 usrp를 인식하지 못한것이다.

here’s an example of an error that comes up in the ‘gnuradio companion’ software when the software cannot find the usrp device that should have the ip address of . This is normal since my computer doesn’t have the right ip configuration eventhough I’ve connected my computer to the usrp with a LAN cable. 

ip를 건드려주기 위하여 우분투의 ‘환경설정’ 버튼을 눌러주면 위와 같은 환경설정 창이 뜬다. 그 중에서 network 아이콘을 눌러준다.

we need to edit the ip configuration so lets click the ‘system settings’ button on the desktop menubar(on the left) and then click the ‘network’ icon.

이제 이런 창이 뜨는데 우리는 랜선, 즉 wired connection의 설정을 바꿔줘야 하므로 wire를 클릭하고 option 버튼을 클릭한다. 사실 이 화면은 이미 세팅이 끝난 화면이므로 ip address 등의 내용물이 내 스샷과 동일하게 나오지 않더라도 당황할 필요가 없다.

this window pops up. we need to change the ‘wired’ connection so click on ‘wired’, and then click the ‘options’ button. This screenshot was taken after I did all the right edits so you don’t have to bother even though your window doesn’t match with my screenshot.

아마 method는 처음에 automatic으로 되어 있을 텐데, 이거를 manual로 바꾸면 밑에 addresses가 활성화 될것이다. 여기서 중요한건 곧바로 address, netmask, gateway에 입력하라는 것이다. 괜히 ‘add’ 버튼을 누를 필요가 없다! 나 괜히 이랬다가 밑에 ‘save’ 버튼이 안눌리는 경험을 하였으니.. 여러분은 ‘add’ 버튼 누를 생각말고 그냥 곧바로 address,netmask,gateway 입력하시길 ㅜㅜ

유의할 점은 address는 현재 자기 컴퓨터가 가질 ipaddress 인데 형식은 무조건 192.168.10.x 이어야 하는 것이다. 여기서 x는 2를 제외한 어떤한 숫자든 된다. 근데 보통 로 해두는게 좋은 것 같다.

netmask는 subnet mask를 의미하는데으로 해두자. 그렇게 하랜다. 이유는 나도 몰라.
마지막에 gateway는 당연히 우리가 사용하는 usrp의 ip 주소인로 해주어야 한다. 게이트웨이의 뜻이 결국 컴퓨터가 어디로 데이터를 주고받을 것인지를 뜻하는 주소이므로…

아무튼, save 버튼을 누르면 끝!

When this window first appears, the ‘method’ shall be set on ‘autumatic’. change this to ‘manual’ and then the ‘addresses’ part will activate for editing. Now here’s the important tip: click on the addresses, netmask, gateway right away and don’t touch the ‘add’ button on the right. I first made a mistake of clicking the ‘add’ button which gave this wired connection a second blank ip address. Of course, it didn’t work. There will be no need to click on the ‘add’ button or whatsoever. After you type in the address,netmaks,gateway, the ‘save’ button at the below will activate. click on ‘save’ right away.

The keypoint here is what you will type in the ‘address’ section. This address will be the ip address of your computer and the format is ‘192.168.10.x’. The ‘x’ can be any integer except 2. but in most cases, it would be preferable to use ‘1’. So, I typed in

The ‘netmask’ is the same thing as ‘subnet mask’ and the value is It shouldn’t be anything else. I don’t know the reason so don’t ask me.

As for the ‘gateeway’, it is obvious that we should type in which is the ip address of the ursp. the gateway is the destination where your computer will send its data so there’s no doubt that it should be

anyway, when you click on ‘save’, it’s done!


* 참고로 컴퓨터의 랜이 1Gbps 이상이 되지 않으면… 이걸 해도 아마 연결이 안될 거다. 되더라도 잠깐 연결되었다가 안될걸? 그러니까 usrp 사용하고 싶으면 랜 대역폭이 1기가 넘는 걸 써야 한다. 듣기로 100mbps 대역폭 가져도 usrp 연결 할 수 있는 방법이 있다고 하는데, 1Gbps 대역폭 가지는 공유기를 usrp와 컴퓨터 사이에 두어서 usrp에게 컴퓨터의 대역폭이 1Gbps라고 ‘속이는’ 꼼수가 있다고 한다. 정확한건 나도 몰라… 님들이 알아서 구글링해봐

*Just for your information, if your computer doesn’t support 1Gbps ethernet bandwidth, then all this ip configuration is done for nothing. A lot of laptops and computers have 100Mbps ethernet which will not be able to communicate with usrp properly. In fact, the ursp will not even recognize your computer at all! In my case, I have a laptop that has a 100Mbps ethernet bandwidth, and even I did all the ip configuration, the computer reported that the wired connection was ‘unconnected’. It only connected for a few seconds and then it was ‘unconnected’. That’s why I’m forced to use the laboratory labtop which has a 1Gbps bandwidth.
I recently heard that there is a trick to let 100Mbps ethernet laptops to connect with usrp. It utilized an internet sharer that had an 1Gbps ethernet port. I should be placed between the usrp and the computer in order to trick the usrp to think that the computer has an 1Gbps. Of course I don’t know the details and if you really need to know how to do this, don’t ask me. ask google.