Uses gr.file_sink 32 bit or 64 bit


#1

Hi All again, :slight_smile:

i want to save some output from the usrp and watch it with octave.
Therefor i know is something written at,
http://gnuradio.org/trac/wiki/Octave
quotation:
“Data captured directly from the USRP is stored as 32-bit complex,
rather than
64-bit complex (gr.sizeof_gr_complex)”
So i think,
gr.file_sink(gr.sizeof_gr_complex1, “capture.dat”)
is to save 64 bit data and,
gr.file_sink(gr.sizeof_short
1, “capture.dat”)
is to save 32 bit data.
Is that correct ?
But therefor i have to set the output type of my USRP
to short(is not default) ?
If i set the output type to complex then i would get
64 bit ?
USRP source Ouput Type complex --> 64 bit
USRP source Ouput Type short --> 32 bit
Is this correct ?

Regards Markus


#2

I also want to save only as much data as needed to
create ONE FFT-Plot in octave.
My FFT-sink has got a fft-size of 1024.

How to cut the stream for a fft-size of 1024 ?

Regards Markus


#3

On Thu, Mar 26, 2009 at 4:12 AM, feldmaus removed_email_address@domain.invalid
wrote:

i want to save some output from the usrp and watch it with octave.

The usrp.source_c(…) block generates IQ data as pairs of 32-bit
floating point values.

Use gr.file_sink(gr.sizeof_gr_complex, “filename.dat”) to write these
samples to disk.

Inside Octave, use read_complex_binary(‘filename.dat’) to load the
saved samples into an array of complex numbers.

Johnathan


#4

On Thu, Mar 26, 2009 at 07:32:09AM -0700, Johnathan C. wrote:

On Thu, Mar 26, 2009 at 4:12 AM, feldmaus removed_email_address@domain.invalid wrote:

i want to save some output from the usrp and watch it with octave.

The usrp.source_c(…) block generates IQ data as pairs of 32-bit
floating point values.

Or to avoid any confustion about how many samples are getting
generated, I think it’s easier to think that it generates samples that
are of type std::complex.

Eric


#5

Eric B. schrieb:

Eric
Thanks for your posts,

so if i really want to plot this data
in octave i have to collect every 32bit samples ?

If i only plot the vector containnig the float samples:
c=read_complex_binary(‘usrp_output_64bit_complex_only_sin_signal.dat’);
t=1:1:100;
plot([real(c(t)), imag(c(t))])
i got for the beginning,
http://img90.imageshack.us/my.php?image=from1to100bits.jpg

And if i do,
t=100:1:164;
plot([real(c(t)), imag(c(t))])
http://img90.imageshack.us/my.php?image=from100to164bits.jpg

Regards Markus


#6

Eric B. <eb comsec.com> writes:

Or to avoid any confustion about how many samples are getting
generated, I think it’s easier to think that it generates samples that
are of type std::complex.
So you mean:

I(32 bit) --> real(16 bit) + imag(16 bit)
and
Q(32 bit) --> real(16 bit) + imag(16 bit)

So I+Q is 64 bit ???

Regards Markus


#7

Eric B. schrieb:

Eric
Yes its confusing me. :frowning:

Ok, here is a clipping from the data at the beginning:
0 + 0i
0 + 0i
-1 + 0i
0 - 1i
-13 + 2i
65 - 32i
-183 + 98i
412 - 233i
-831 + 478i
1572 - 918i
-3050 + 1745i
8314 - 4139i
-12548 - 5491i
3899 + 10329i
3523 - 2748i
-1791 + 1379i
951 - 738i
-484 + 378i
219 - 176i
-84 + 69i
19 - 20i
0 + 0i
0 - 1i
0 + 0i
0 - 1i
0 + 0i
0 - 1i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 + 0i
0 - 1i
0 + 0i
-1 - 1i
0 + 0i
-1 - 1i
0 + 0i
-1 - 1i
0 + 0i
-1 + 0i
0 - 1i
0 + 0i
-1 - 1i
0 + 0i
-1 + 0i
0 - 1i
-1 + 0i

How can i collect bits from the I or Q Signal ?
So the first 16 bits from the left side are the I Signal ?
And the first 16 bits from the right side are the Q Signal ?
Where is the beginning of the samples ?
Maybe the curious values at the beginning is the
start point ?

Regards Markus


#8

Johnathan C. <jcorgan corganenterprises.com> writes:

Just to make this completely clear:
Very very thank you Johnathan.

Ok, so i think the gnuradio docu should be updated, because there is
written:
“Data captured directly from the USRP is stored as 32-bit complex,
rather than
64-bit complex (gr.sizeof_gr_complex).”

But I+Q is 64 bit complex as you said.

So i have to use the read_complex_binary() function which has
gr.sizeof_gr_complex(64 bit) . So the docu should write:
“Data captured directly from the USRP is stored as 64-bit complex,
rather than
32-bit complex.”

Further on my graphic does not look like my spectrum in the
FFT-sink.
Therfore should something added, like
how to show this correctly:
c=read_complex_binary(‘data’)
t=100:1:length©
f=20*log10(fft(t,c(t)))
plot([real(f), imag(f)])

But this sentences doesn’t work correcctly.
I am working on this.

How ever the above has another error???
The command mixes the real part from I and Q together as
the imag part from I and Q too.
Is this correct ???
Further on the data should go through a fft() and a 20*log()
function ???
My FFT has a size of 1024 is this relevant for the fft() function ?

Regards Markus


#9

Just to make this completely clear:

The complex baseband samples that come from the USRP1 source block
usrp.source_c(), and the from USRP2 source block usrp2.source_32fc(),
are complex numbers. The real portion of the sample (the “in-phase”,
or “I” portion), is a 32-bit floating point number. The imaginary
portion of the sample (“quadrature”, or “Q” portion) is also a 32-bit
floating point number.

The sample, then, is a vector quantity. While there is a “total” of
64 bits between the two numbers, when one uses bit depth to describe
these, one still refers to the bit depth of the individual dimensions,
not the aggregate. To describe the storage requirements of a sample,
in memory or on a block device, one typically uses bytes. Thus, it is
correct to say, “a 32-bit complex floating point sample takes 8 bytes
of storage, 4 for the I portion and 4 for the Q portion.”

Your earlier post showing the captured samples from the USRP as an
array in Octave was correct. (The magnitude spike in the first 20 or
so samples is an artifact of the the USRP when it is first enabled,
and can be ignored.)

Hope this helps.

Johnathan


#10

On Fri, Mar 27, 2009 at 8:36 PM, feldmaus removed_email_address@domain.invalid
wrote:

Wherefor is the first line ?
For the I part or the Q part ?
Does the lines of the I and Q part change from line to line ?
0 - 1i --> real(I) - imag(I)
-1 + 0i --> real(Q) + imag(Q)

You may want to refresh your knowledge of complex numbers:

http://en.wikipedia.org/wiki/Complex_number
http://www.dspguru.com/info/tutor/QuadSignals.pdf

Brian


#11

Brian P. <bpadalino gmail.com> writes:

Thanks Brian for your nice link,

but if you only post a link and do not wrote a simple
answer like yes or no to my question, then i will be
confused.
Or is there something totally wrong i wrote ?
Then please also wrote my mistake !

How ever do you have also a good link or answer, why this
http://img90.imageshack.us/my.php?image=from100to164bits.jpg

doesn’t looks like the FFT-Spectrum we get in gnuradio in
the FFT-sink.
The Howto http://gnuradio.org/trac/wiki/Octaveis incomplete !?

Thanks and Regards Markus


#12

On Sat, Mar 28, 2009 at 10:09 AM, feldmaus removed_email_address@domain.invalid
wrote:

Thanks Brian for your nice link,

but if you only post a link and do not wrote a simple
answer like yes or no to my question, then i will be
confused.
Or is there something totally wrong i wrote ?
Then please also wrote my mistake !

As the old proverb goes:

"Give a man a fish and you feed him for a day. Teach a man to fish

and you feed him for a lifetime."

You seem to have a grave misunderstanding of what complex numbers are
and how they are represented. I highly recommend you brush up on your
knowledge. Said links should be sufficient for you to correct your
own mistakes.

How ever do you have also a good link or answer, why this
http://img90.imageshack.us/my.php?image=from100to164bits.jpg

doesn’t looks like the FFT-Spectrum we get in gnuradio in
the FFT-sink.

Unfortunately, this plot does not indicate how to interpret the data I
am reading. Moreover, you did not supply the means of how you created
the graph with both the script or the source data. On top of that, I
have no idea how the data was captured or what the expected result
should be. There are a lot of holes here when it comes to the simple
question: “why this?”

Please take the time to read:

http://astro.uchicago.edu/cara/outreach/resources/other/howtograph.html

Please, don’t forget to perform “Step 6” before mailing the list for
help.

The Howto http://gnuradio.org/trac/wiki/Octaveis incomplete !?

Think of this as a learning opportunity as to both learn and teach
others. Feel free to complete the howto on the wiki once you have
gained adequate knowledge and if you still feel the wiki is still
incomplete.

There has been plenty of information given in this thread to
understand how numbers are represented using the file_sink. It’s now
up to you to learn from the posts and gain that knowledge for
yourself.

Good luck!

Brian


#13

Markus F. <feldmann_markus gmx.de> writes:

Ok, here is a clipping from the data at the beginning:
0 - 1i
-1 + 0i

As you said the Output is stored as 64 bit value, 32bit I and 32 bit Q,
but I and Q do have bot real and complex values ?!
As you can see, every line consists only one real and one complex value.

Wherefor is the first line ?
For the I part or the Q part ?
Does the lines of the I and Q part change from line to line ?
0 - 1i --> real(I) - imag(I)
-1 + 0i --> real(Q) + imag(Q)

Is this mapping correct ?

Regards Markus


#14

I also stored another files with data captured from my signal generator.
To store the data i used the Gnuradio companion with a USRP source
(complex output) and a file_sink(complex input). The usrp source gets
the data from my external signal-generator.
But this time i increased the amplitude of my sinus signal periodically.
So i can easily verify that i stored data from my signal generator and
nothing else.

I executed the following octave commands:
c=read_complex_binary(‘usrp_output_64bit_complex_only_sin_signal.dat’);
plot(real(c(1:600)))
http://img17.imageshack.us/my.php?image=realfrom1to600samples.jpg
plot(real(c(601:length©))
http://img12.imageshack.us/my.php?image=realfrom601to2e06sample.jpg
plot(imag(c(1:600)))
http://img217.imageshack.us/my.php?image=imagfrom1to600samples.jpg
plot(imag(c(601:length©))
http://img21.imageshack.us/my.php?image=imagfrom601to2e06sample.jpg

As you can see the amplitude will be increased over time.

However this doesn’t looks like as in my FFT-Plot Software !
http://img135.imageshack.us/my.php?image=originalgraphicfromffts.jpg

Therfor i sink each wave is one sample and each sample has all the
information to build one displayed spectrum in my FFT-Plot ???

But how can i do this with octave ?
I doesn’t understand FFT completely. But i think i need the FFT function
to display the data as shown in my FFT-Plot ???

Now i post the Real+Imag Values from (600:700):
24 + 5i
1 + 24i
-23 + 10i
-19 - 18i
9 - 24i
24 + 1i
5 + 23i
-21 + 13i
-21 - 15i
6 - 25i
24 - 2i
8 + 23i
-19 + 16i
-23 - 13i
2 - 26i
24 - 5i
12 + 21i
-16 + 19i
-25 - 9i
0 - 26i
23 - 9i
16 + 18i
-13 + 21i
-25 - 5i
-4 - 25i
22 - 13i
18 + 15i
-10 + 23i
-26 - 2i
-8 - 25i
19 - 17i
20 + 12i
-6 + 24i
-26 + 1i
-12 - 23i
17 - 18i
22 + 9i
-2 + 24i
-25 + 5i
-15 - 21i
13 - 21i
23 + 6i
1 + 24i
-24 + 8i
-18 - 19i
11 - 23i
24 + 2i
3 + 24i
-23 + 12i
-20 - 16i
7 - 25i
24 - 1i
7 + 23i
-20 + 15i
-23 - 13i
3 - 25i
24 - 4i
11 + 22i
-18 + 18i
-24 - 10i
0 - 26i
23 - 8i
14 + 19i
-14 + 20i
-25 - 6i
-3 - 26i
22 - 11i
17 + 17i
-10 + 23i
-26 - 2i
-7 - 25i
20 - 14i
20 + 15i
-7 + 23i
-26 + 0i
-10 - 24i
18 - 18i
21 + 11i
-3 + 24i
-25 + 3i
-14 - 22i
15 - 20i
23 + 7i
0 + 24i
-24 + 8i
-17 - 20i
12 - 22i
24 + 3i
2 + 24i
-23 + 12i
-20 - 17i
8 - 24i
24 + 0i
6 + 23i
-21 + 14i
-21 - 14i
4 - 25i
24 - 2i
10 + 21i
-18 + 17i
-24 - 11i

Regards Markus


#15

Patrick S. schrieb:

feldmaus wrote am 2009-03-27 20:52:

Further on my graphic does not look like my spectrum in the
FFT-sink.

A FFT sink displays the frequency domain, it’s amplitude versus frequency.
Printing the samples shows the time domain, amplitude versus time.

The FFT sink feeds the samples through a FFT-block, resulting in its name.
A scope sink just plots the samples, as you try with Matlab/Octave.
You are right, thats also what i am thinking, but to these
samples through a fft, i have to know what is a sample !

Thats the topic of this post.
Thats what i not understand.

What is a sample ?
For example, is this ONE sample ?
24 + 5i

The left is a 32bit I part and the right is the Q part ?
But as i read I and Q are complex, so i sink I and Q will
be changed from line to line ?
If i need more than one line for one sample, how many lines
do i need for the fft ?

Regards Markus


#16

feldmaus wrote am 2009-03-27 20:52:

Further on my graphic does not look like my spectrum in the
FFT-sink.

A FFT sink displays the frequency domain, it’s amplitude versus
frequency.
Printing the samples shows the time domain, amplitude versus time.

The FFT sink feeds the samples through a FFT-block, resulting in its
name.
A scope sink just plots the samples, as you try with Matlab/Octave.

Patrick

Engineers motto: cheap, good, fast: choose any two
Patrick S.
Student of Telematik, Techn. University Graz, Austria


#17

Markus F. wrote am 2009-03-30 17:54:

You are right, thats also what i am thinking, but to these
samples through a fft, i have to know what is a sample !

Thats the topic of this post.
Thats what i not understand.

What is a sample ?
For example, is this ONE sample ?
24 + 5i

Yes.

The left is a 32bit I part and the right is the Q part ?

Yes! The I(nphase)-part is the real component of the complex number, the
Q(uadrature)-part is the imaginary component of the complex number

If i need more than one line for one sample, how many lines
do i need for the fft ?

One “line” in your output is one complex sample.

You really should read up about complex numbers and FFT, as Brian
mentioned. Please do your homework before asking questions. If you do
not understand how complex numbers work, you will not find too much
people here teaching you such things.

Patrick

Engineers motto: cheap, good, fast: choose any two
Patrick S.
Student of Telematik, Techn. University Graz, Austria


#18

Patrick S. <patrick.strasser tugraz.at> writes:

Q(uadrature)-part is the imaginary component of the complex number

If i need more than one line for one sample, how many lines
do i need for the fft ?

One “line” in your output is one complex sample.
Yes but one line doesn’t suffices for one FFT-Plot !
Or do you want to say that one line as for example,
0+1i
should result in one of my complete spectrum ???
I doesn’t think so. Ok the FFT-Plot uses a average algorithm so
it is not very fatal if there are some zero lines, because they
are not weighted because of the average algorithm, but i doens’t
believe this.

However i found a link where is more information.
The subject is .
The data Type changes. From Usrp to Host it is 8bit or 16bit short
and will be converted at the Host to 32bit float, so that or apllication
only compute with 32bit float values.

Regards Markus


#19

Eric B. <eb comsec.com> writes:

http://www.amazon.com/Understanding-Digital-Signal-Processing-2nd/dp/0131089897/ref=sr_1_1?ie=UTF8&s=books&qid=1238774302&sr=1-1

At this time i am doing my diploma and have not much money, so
i have to thing about where my money goes. But i will still buy
some nice books after this. :slight_smile:

I which “*.cc” file is the algorithm written for applying the fft ?

Regards Markus


#20

On Fri, Apr 03, 2009 at 12:25:41PM +0000, feldmaus wrote:

should result in one of my complete spectrum ???

Regards Markus

Marcus,

I know that some of us are starting to sound like broken records, but
you seem to be missing some of the basics. This is OK, we all started
out knowing nothing.

We’ve got many books and papers on the
http://gnuradio.org/trac/wiki/SuggestedReading page. I particularly
recommend “Understanding Digital Signal Processing” by Richard Lyons.
He works through the basics of DSP with complete examples, including
sampling, aliasing, DFT / FFT, filtering, digital data formats, complex
numbers, etc. It’s a great introductory book for autodidacts.

http://www.amazon.com/Understanding-Digital-Signal-Processing-2nd/dp/0131089897/ref=sr_1_1?ie=UTF8&s=books&qid=1238774302&sr=1-1

Eric