 In this lecture, we are going to introduce the QT GUI histogram sync of GNU radio that allows you to essentially count the set of values that fall within a range. The histogram sync comes in handy when you want to visualize the probability distribution function of a certain source or a certain sequence of data. We will be using this to good effect to study the impact of noise in terms of similar rates and bitter rates as well as well as see how Gaussian noise or some other noise essentially manifest in terms of the set of values which they can take. Let us begin our discussion with an evaluation of the histogram sync that will come in handy when we perform evaluations of similar rate and several such measurements. So we press CTRL F or CMD F and type histogram HIST we then grab our histogram sync and place it here. Now the histogram sync has several parameters in particular it has number of points which is the number of points using which it actually performs the histograming or counting which we will get to in a minute. Parameters like grid, autoscale and all are familiar to you. There is something called accumulate that we will discuss later. There is something called min x-axis and max x-axis. Now these are the range of values for which the histogram is going to be evaluated. Let us go straight into an example and then we can analyze what this actually does. We will then go in the reverse order and grab a throttle. So CTRL F for CMD F, throttle. We will make the throttle into a float and one change I have made is that I want the sampling rate to be 192000 so that our simulation runs a little bit faster. Finally I am going to start with a vector source. So CTRL F for CMD F type VEC I have this vector source and I am going to double click it make it a float and I am going to choose a special vector and the vector I am going to choose is something like within square brackets 0.2 comma 0.7 comma 1.5 comma 0.7. This is a four length list. So the same four values are going to be repeated again and again because I have set repeat to yes. Now if I press OK and I have this vector source I am going to connect it to the throttle and connect the throttle to the histogram sync. When I now execute this flow graph I get this kind of plot where I have a peak at let's say the value 0.2 and a peak at 0.7 and these peaks have some specific amplitudes which we will see in a minute but there is a peak at 1.5 which is not even visible. The reason for this is that we have to make these values more appropriate. So let us actually make this let us say minus 0.5 and our highest value is 1.5 so let us make this go up to 2. Now if I execute this flow graph you will see the three peaks. This peak is at 0.2 actually it's very close to 0.2 and there is a reason why it's like that close to 0.2 this peak is close to 0.7 this peak is close to 1.5 okay and let us look at the heights of these peaks. This peak has a height of 256 actually if you zoom in further you will see that its height is about 256 let's see I have to zoom in let's say I zoom in even further you will see that this height is close to 256. This height is 512 and this height is 256 again. Now what is the meaning of this? The meaning of this is that the histogram sink essentially reads in a 1024 values and counts the number of values that fall into these bins. So what are these bins? So you essentially take the interval between 2 and minus 0.5 which is about 2.5 in length break it down into several evenly sized parts in fact 100 evenly sized parts you then count the number of values that fall within them. Let us say 2.5 is the length of this interval you can break it into 100 evenly spaced bins or buckets each of size 2.5 upon 100 which is 0.025. Now any value which falls between minus 0.5 and minus 0.5 plus 0.025 is now that basically increases the count of that particular location or bin by 1. Now if you now look at our input it is very specific we are sending 0.2.7 1.5.7 therefore the bin in which 0.2 is present every time 0.2 appears the count goes up by 1. The bin in which 0.7 comes in every time 0.7 comes the count goes up by 1. Now we have about 1024 points like these vector source gets repeated I mean if you want 1024 points these vector source essentially gets sent out repeatedly 256 times. So among 1024 points you will exactly have 256.2s 256 1.5s and exactly 512.7s because the order doesn't matter 0.7 appears twice as many times as the other two numbers. So if you see in this particular bin which contains 0.2 you have 256 in this bin which contains 0.7 you have a height of 512 and in this particular bin which contains 1.5 you have a height of 256 which is exactly the same as that which you had for 0.2. Adding these gives you 1024. If you want to change this out you can actually just change this to let's say we'll make this for just a change we'll make this 5000. If you make it 5000 you will see that 2500 of those are 0.7 1250 each are your 0.2 and 1.5. So the histogram essentially counts the number of occurrences of each of these numbers. Now this particular vector source is not that interesting because we know a priori that you're going to send 0.2 you're going to send 1.5 you're going to send 0.7 twice so the result is not very surprising it is very obvious where a histogram sync can come in handy is where you want to visualize the potential distribution of values in a scenario where you don't really know what it is for example let's say that you have a random source over here what kind of values does the random source emit that could be something which is useful to know now let us get rid of this vector source by just clicking here and hitting delete and let us get a random source so let's do control f and type random rand so we'll get a random source and this random source outputs integers okay the minimum value is zero the maximum value is two in this case keep in mind that the outputs are always zero and one because the maximum value is always not output what is output is zeros and ones so now to verify whether we get an even fraction of zeros and ones let us just try to histogram this so the x axis is between minus 0.5 and 2 which will cover the value zero and one we just need to convert this random source to the right type so control f for command f int to float we will grab an int to float place it in between wire these things up and if you now observe the histogram you get this kind of structure okay it's I think you have approximately 2004 50 of this 2005 50 of this they are not exact because when you actually perform any random kind of simulation you will not get exactly half half even though they are equally likely you are going to get slightly different answers the number of samples here is thousand number of points here is 5000 let's set this back to a thousand and let's now execute the flow graph you can see that it's about 500 about 500 which makes complete sense let us actually make some changes let us make this random source go from 0 through 4 and let us also change our axis to be from minus 0.5 to let's say 4.5 now you can see that you're generating you have a random source of 1000 and you have exactly a thousand points in the histograms thing if you execute this you will get this kind of structure you expect that since there are a thousand points all of these should be equally likely and close to 250 unfortunately this realization had many more threes than two more twos than ones and ones and zeros let us execute it again now this time you got more ones this is something which you should be aware of that the fraction essentially is ever so slightly different because of the size you have chosen and another important thing is that the random source essentially generates a thousand samples once and keeps repeating them which is why there is no real change in these values as more and more cycles come in in any case I had the maximum had to be five if you wanted to see the fourth value also and you'll start seeing more gaps so this is something that you can understand through probability but the more important point I wish to convey is that a random source is not the right way to generate something like noise or some continuous pattern it will only generate the number of samples you want like thousand and keep repeating the same set of samples often when you do communication simulations you want a continuously moving set of random values and therefore it is not a good idea to use a random source as a noise source let us now move on to using an actual noise source for our analysis so I am going to delete the random source delete the into float I will say control for command f and I will type no i se and I'll get a noise source double click the noise source we'll use float initially and we will start with uniform the amplitude is one now a uniform noise source with amplitude one it turns out that in GNU radios terminology this is going to give you uniform random values between minus one and one so let us double click this and let's say this is minus 1.2 to 1.2 sorry 1.2 and run this now you can see that you get this kind of movement the first thing is that the movement is because every time the random source generates a new set of values a histogram is generated in other words you are getting one histogram for every thousand or thousand points that the noise source generates now it is evident that the thousand points doesn't give you a very very stable histogram structure so one thing we can do is we can increase the number of points which are used to construct the histogram so let us make it a thousand maybe a hundred thousand now if you observe the histogram with a hundred thousand of course the updates are slow but it is very evident that the histogram looks much more you know neat and clean okay now another an important thing that you must note is that this height is at the actual count of the number of points which fall into that bin now this is something which we must understand a little better to do so let us do one thing let us actually just change this to have just let's say a really small number of bins let us say we will have just two bins and execute the flow graph if you have just two bins it turns out that let me just middle click this and say autoscale x no if you have just two bins then you end up getting the values let's say I think they fall into the bins which are close to minus two and zero which is not what we want let us just change this a little let's say that we have let's say four bins I think or maybe let's say 10 bins that is a better idea let us execute the flow graph yeah so now what happens is that the values over here are stable but the values I mean the values over here indicate that all the bins have the same amount but there seem to be a couple of bins which don't have the same amount which is a little surprising because these values are you mean you have a uniform source and you expect the values between minus one and one to be the same what can you attribute this to well let us actually play a trick over here let's actually go double click on our histogram sync go to config and then or before that let's double click on the histogram sync make the minimum as minus one and makes the maximum as minus one and we have the number of bins as 10 we therefore will assume that the interval between minus one and one is being divided into 10 equal parts and each of those 10 must have approximately 10 1 lakh upon 10 that is 10,000 such values it's also at a grid let us see whether that is the case now if you execute the flow graph it looks like over here there is seems to be a bin which has a height which is appropriate but over here these things seem okay but there seems to be a fall over here now what is happening to understand this we must just see what our exact bins are so if you double click on your histogram sync and go to config there is a marker for line one we will just make it let's say something which we can see easily let's say x cross and say okay remember we asked GNU radio to create the intervals 10 intervals in between sorry 10 bins uniform the space bins between minus one and one now executing the flow graph gave us these crosses these crosses are actually in slightly stranger places so this is 0.884 let's say this is around 0.88 this is around 0.66 there on 0.44 and so on and if you see the first one it is let's say I'll just move it up here so you can see around minus 1.1 so what GNU radio is doing is that even though you asked it for the interval minus one through one it is actually starting slightly to the left of minus one and going to the right of you know plus one over here and the exact bin center points are not the places where you asked it to ask the bins to be so that is the reason why you have this kind of issue so if you look at it for example the bins are at minus 1.09 minus 0.88 minus 0.77 minus and sorry there'll be minus 0.66 minus 0.44 minus 0.22 and so on so you are effectively your bins are in these locations and not exactly at between minus one and let's say minus one to one if you divide into 10 equal parts each bin should be 0.2 so it's not minus one to minus 0.8 minus 0.8 to minus 0.6 those are not the bins if you're really interested in finding out how GNU radio exactly partitions the bins you can go through the source code but in this particular example what GNU radio does is this it uses these bins so minus 1.11 to minus 0.88 is a bin minus 0.88 to minus 0.67 is a bin and so on so if you look at the last bin 0.88 to 1.11 it turns out that one falls right in the middle and therefore it is this is the bin that is chosen and if you look at minus one then again it falls right in between and therefore some of one of these is chosen and this is a little it's a little bit of a strange situation because of floating points and all those you may choose one or the other and several such issues can happen. Given this this is what ends up happening and you have to just be aware of the fact that you have to be aware of the fact that GNU radio's choice of the bin intervals is slightly different from what you may think that it is nevertheless you should just be aware that the qualitative plot is good and this problem is not very evident when you increase the number of bins then you can get a rough idea of the histogram by observing this and finally there is an option called accumulate what accumulate does is that after computing the histogram once using these 100,000 points for the next 100,000 points it just adds to the counts in other in other words let's say out of these 100,000 it has got 2,000 values in a bin in the next 100,000 it gets 2010 it adds this 2000 and 2010 to make 4,010 for the bin therefore if you observe the y-axis the y-axis is constantly going to see an increase for example let us see over here if you look at the y-axis the y-axis is constantly increasing but and relatively speaking this uniform nature of the source is very very evident it's very very clear that this is a uniform source and therefore this is something that can come in very very handy when you want just a qualitative but more accurate version because the counts are constantly going to get added and the accumulation will result in a more stable histogram let us now just remove this accumulation let us then just make a couple of changes so just to show you that you can now start making some very minor changes you may be aware that you can use a uniform random variable to create a an exponential random variable but that is of course by taking the logarithm of a uniform random variable whose values are between 0 and 1 so to see whether that is possible over here we can play a trick so first this uniform noise source gives you values that are between minus 1 and 1 let us now just shift these to make them between 0 and 1 so to do so we can do control f for command f and we can say add we can say add constant in fact because we are going to add a constant double click float and we're going to add the constant 1 and we are also going to multiply by a constant which is divide by 2 so control f for command f m u l t multiply constant so we are going to divide this by 2 so 0.5 float okay now this we will verify should be a uniform random variable between 0 and 1 so as you can see values are largely concentrated between 0 and 1 let us now take the negative logarithm or negative natural logarithm of this particular random source after at this point now if you just delete this wire control f for command f and we say l o g for log maybe log 10 this log 10 operator can be brought in here we can now double click this log 10 and there are two parameters called n and k so if you look at the documentation the output of this is n times log 10 of input plus k so we want the natural logarithm but we get only log 10 and to get the natural logarithm we have to divide this particular log 10 by log to the base 10 of e now to do so we can always just calculate the constant but i am a little i don't want to take such risks i'm just going to say control f for command f i'm going to say import or let's yeah we will say import and we will import num pi double click and we will say import num pi as np and we can now double click over here and write this constant as we need to get the negative log so minus 1 upon np dot log 10 np dot exp of one what this will do is that this will essentially get the natural logarithm and multiply it by minus one which is what we need for an exponential so we'll connect these out and if you connect these out and execute the flow graph you can see that you get an exponential like shape let us change the intervals to be between zero and let's say five and if you now execute this flow graph you can see that this definitely looks like an exponential random variables pdf that's what the histogram is next let us make a very small change and observe other sources of other random sources or in specifically let us see how gaussians appear so let me actually delete this delete this delete this and connect our noise source back directly and change this noise source to make it gaussian and say okay and we'll double click this we'll remove the autoscale also autoscale can be there sorry number of bins being 100 is fine let's make it go between minus four and four and now let us just run this flow graph and as you can see you get a nice bell shaped indicating that it's like a gaussian the reason it is shaking is because every time the gaussian source produces new points and for every 100,000 points a new histogram is generated therefore as you can see the bell shape is not perfect because of the realization of the sequence of random variables now it is common for us to change some parameters of this gaussian like for example we may want to change its variance or standard deviation now something you may remember from our discussions is that when a gaussian has zero mean like it is in this case the amplitude can be changed rather the standard deviation can be changed by just changing the amplitude so let us actually add a range so control f for command f we'll say range and we'll grab a qtgy range and double click this range and call it noisestd noise standard deviation default value we will keep as one start will make me keep it a zero stop at three and step 0.1 and before we start we should just change the amplitude over here to noise std and we are ready oops it should be std i apologize now if you execute this flow graph you get a range over here and you get the same behavior as earlier let us just take the extreme step of making this range go to zero if you make this range go to zero then the gaussian essentially outputs its mean and the sources mean is essentially zero and you are getting values which are close to i mean you're always getting zero and that's why all the hundred thousand values uh fall into this particular bin now if you start increasing the noise standard deviation you can see that when your standard deviation is 0.1 you can see that if you get a relatively stable plot because only a few bins essentially receive values the other bins are very rarely active which is why you don't see much and if you see largely all the values in these bins are concentrated i mean stable rather now if you start increasing it to let's say 0.6 you can see a reasonably shaped gaussian more bins are active if you look at these lower bins right the probability that you will get values within here is low but not zero therefore on occasion you will get some of these values as you can see over here this goes up and down and so on let's actually focus on these bins so these are what one would one could call rare occurrences right rare events but if i keep increasing the standard deviation you will see that they also start coming in in fact if you look at it typically much of the gaussian is concentrated between minus three sigma and three sigma therefore if you now start increasing the value of sigma that the standard deviation you will start getting values falling into bins that are beyond let's say one or two sigma as well one or two rather in this case because we are increasing the standard deviation if you now increase this further and let's say you make it close to two the standard deviation is now two the variance is four and as you can see the gaussian essentially spreads to have a much larger set of values in the case of a communication system this would translate to a higher noise scenario and you know if you think about it there is a large possibility of your symbols getting corrupted or moved away from the correct decision region because of this noise so in this manner we can essentially visualize the gaussian and in using a histogram as well of course for higher standard deviations because of the effect that we discussed wherein the number of values which fall into the bins is the more of values which fall into the bin starts varying because your values are now spread across and the entries in the bins are no longer as stable one thing you can do is to accumulate and once you enable accumulation then you can see let's increase the standard deviation to two there will be a slight problem because we are accumulating standard deviation of one and then two so let us actually not do that see the problem is if you start accumulating when the standard deviation is one and then change it to two your histogram is no longer accurate we will just change the default to two to visualize correctly so now if you do this you can see that eventually it stabilizes and then you know that this has the shape of e power minus x square by two sigma square so to find sigma you can just use the fact that the peak value is proportional to e you know is essentially k times e power minus x square by two find k and then you can you know because that's basically the value k and then over here you can use the formula k e power minus x square by two sigma square is equal to this particular 60 000 and that will essentially give you a good estimate of your standard deviation so you should actually stop this and you can use the fact that this value is k so in this case our k is let's say let's say one i'll go even further okay i have two so let's say it's like one two nine five six zero and one two nine five six zero is my k and i have to zoom out a little one two nine five six zero is my k and let's say at 50 000 what is the value of x we have to find that out it's i think minus 2.7 and now if you substitute my you know e power minus 2.7 square by two sigma square times one two nine five six zero is equal to let's say 52 100 or so you can find sigma and that you can use to estimate the variance as well so in this manner we are able to use the histogram to good effect to visualize the properties of a random source and to essentially count the set or ranges of values which it can take and essentially get an estimate of the probability distribution in the further lectures we will be using the histogram to good effect to actually compute some statistics on the values that we are essentially receiving at the receiver of a communication system as well in this lecture we have essentially seen how histograms can be used in crew radio in particular we have seen how big the histogram sink has to be in terms of the number of values it takes how the choice of bins affects you and how you can use this to visualize random quantities such as you know noise samples or received symbols and your visual inspection of the histogram will tell you the performance of your system and we're going to use this to good effect in the coming lectures to find similar rates bitter rates and so on.