Strange problem when reading from gr.GR_SIN_WAVE

Hi all,

I am a newbie to GNU Radio. I just started off with my first program 

and
decided to read some floating point samples from the gr.GR_SIN_WAVE into
a
file. My problem is that every time I run the program, I get a different
file size. I even tried to change the file name after the first run, but
again ended up with the same problem. Here’s the script:

from gnuradio import gr
import time

def my_graph():
sampling_frequency = 10000
amplitude =0.1
graph1 = gr.flow_graph()
source = gr.sig_source_f(sampling_frequency,gr.GR_SIN_WAVE
,100,amplitude)
destination = gr.file_sink(gr.sizeof_float,
‘/home/anshul/Desktop/samples1.dat’)
graph1.connect(source,destination)
return graph1

if name == ‘main’:
graph1 = my_graph()
graph1.start()
time.sleep(2e-6)
graph1.stop()

kindly help out with this. Thanks in advance.

Essentially, the sampling rate parameter of the signal source does not
actually control the number of samples per “CPU clock”. That parameter
tells the signal source how to scale the sine wave in the time domain.
When you run this flow graph, the signal source is actually spitting
out samples as fast as possible. So in time.sleep(2e-6), any random
number of sample will be written.

You can control the rate of the samples with respect to you CPU clock
by using a gr.throttle(gr.sizeof_float, samps_per_second) block in
your flow graph. Also, you can use a gr.head(gr.sizeof_float,
num_samps) block to only allow the first “num_samps” into the file
sink.

-Josh

On Thu, Nov 29, 2007 at 05:59:44PM -0500, Kshitij Singh wrote:

import time
return graph1

if name == ‘main’:
graph1 = my_graph()
graph1.start()
time.sleep(2e-6)
graph1.stop()

kindly help out with this. Thanks in advance.

Insert a

head = gr.head(gr.sizeof_float, N)

between your source destination, where N is the number of samples you
want to collect.

Eric