discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] create lookup tables


From: Marcus Müller
Subject: Re: [Discuss-gnuradio] create lookup tables
Date: Sat, 26 Dec 2015 17:45:12 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.1.0

Hi Andy,
So if i want to have a sine with frequency 1 hz and 256 samples per sine period i have to set samplerate to 256 ?

1hz = 256/256

yes, this is DSP, so all we care about is rates relative to the sampling rate. I got into the habit of thinking of the sampling rate as always being "1", and then your sine has a frequency of 1/256, ie. it takes 256 samples for a full period.
The head block has 2 parameters: number of items, vector length
The signal source spits out single samples, so your vector length is 1.

Now this is non specific gnuradio question, but how is it possible with python to create a sine with 1 hz from this lookup table.
For any frequency of sines you'd want to generate, you'd advance at a speed of len_of_table*relative_frequency. Think of it as this -- if a sine that is generated by taking every sample from your table one after the other has frequency f_sample/256, then the sine of twice that frequency has every second sample, and so on.
My first idea is: python has to sample the 256 samples (for one period)  from lookup table in exactly one second. So i think i need a timer which calls the next sample in the lookup table all 3,9 ms.
no!
GNU Radio is NOT a system where samples are processed sample-by-sample, with a fixed precise sampling rate. Each block is just asked to process/generate/sink as many samples as possible, and the result is passed on to the next block as fast as possible.

Best regards,
Marcus

On 12/26/2015 05:28 PM, Andreas Ladanyi wrote:
Hi Marcus,
 Well, first:
Signal Source can't produce 8bit signed integers by itself, so you'll have to convert whatever you configure the signal source for to char, eg. you could set it to "float" and use the "float to char" conversion. Make sure the result has amplitude 127. Properly configure your signal source for the desired sine period, e.g. sample_rate=X , frequency = X/256.
So if i want to have a sine with frequency 1 hz and 256 samples per sine period i have to set samplerate to 256 ?

1hz = 256/256

Then, use a "head" block with that period, and pipe the result to a file sink; use the char/byte type of everything. Done. Pretty straightforward, I guess :)
The head block has 2 parameters: number of items, vector length

The number of items is the amount of samples for a sine period = 256 in this case ?


As a side note: that's really a bit of a corner use case; a single line of python would probably be easier:

import numpy
(numpy.sine(numpy.linspace(0,2*numpy.pi,256)) * 127).astype(numpy.int8).tofile("/tmp/sinetable.dat")
This works perfect. Now i have a table with one sine period.

Now this is non specific gnuradio question, but how is it possible with python to create a sine with 1 hz from this lookup table.

My first idea is: python has to sample the 256 samples (for one period)  from lookup table in exactly one second. So i think i need a timer which calls the next sample in the lookup table all 3,9 ms.

in C, that program wouldn't be much longer.
and maybe faster ?!

Best regards,
Marcus

regards,
Andy :-)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]