-1

I use the transmitter hackRF one. I need to send the same message once a minute. I need my transmitter turned off the rest of the time. And during the start of the transmission, the message was played from the very beginning. To do this, I used the code that gave Marcus Müller. Now I have the following graph:enter image description here

But when using my block, I get an output signal with some clicks, this is clearly noticeable when using a harmonic signal as a signal source.

Антон
  • 123
  • 4
  • Hey in the error it says that line 24 is "unindented", and if you look closely, you can see that it doesn't start with the same amount of indentation as line 18, for example. In python, the whitespace at the beginning of lines is meaningful! Make it so that line 24 to 28 start as deeply indented as line 18. – Marcus Müller Apr 25 '23 at 07:12
  • I'm sorry to bother you, but you can take a look at my corrected version – Антон Apr 25 '23 at 07:48
  • Ah I didn't write proper python there. As the error suggests, I forgot the colon : at the end of the line. Compare to line 20! – Marcus Müller Apr 25 '23 at 07:54
  • Also, when I look at line 22, there is an _ missing at the end of out_ (same further down) – Marcus Müller Apr 25 '23 at 07:54
  • Thanks! Now the code is error-free, but the code does not output anything. Now I'm figuring out what initial parameters I should set, – Антон Apr 25 '23 at 09:37
  • have fun experimenting! I think the parameter names are pretty self-explanatory: `period` is the duration after which the transmission/no transmission cycle repeats in seconds (see what the code does with it and sampling rate), `input_length` is the length of your audio input in samples, and `rate` is the sampling rate. – Marcus Müller Apr 25 '23 at 09:40
  • Also, please don't post a solution to your problem in your question. Rather, edit my answer to fix the code, and add back your original question! That makes more sense, because you now removed your original flowgraph, and it's much harder for the reader to understand what your question is about! – Marcus Müller Apr 25 '23 at 09:41

1 Answers1

0

Approach for shorter durations

In general, you could solve this with a "patterned interleaver" block out of the box, where you connect the file source to one input, and a null source to the other, and then forward one chunk of audio-file-length input from the first input, and then one hour minus that length from the other (null) input.

[ 0 0 0 … 0 0 1 1 … … … … … … 1 ]
  ^         ^ ^               ^
   \       /   \             /
    audio       remainder  of
    length       a full  hour

It's just that here, the time periods become too long and hence, the interleaver pattern vector becomes infeasible to manage (it needs to be 1 hr of samples in size, which, at 44.1kHz sampling rate, is more than 605 MB of integers, to select which input to forward from).

Another problem is that you'd need to know how many samples are in your audio file to create that interleaver pattern.

Solution: Write your own Finite State Machine

So, the solution here is to write your own block that has two states:

  1. pass through the audio file input
  2. produce zeros (and not pass any input samples)

where you switch from state 1 to state 2 when you see that the full audio file has been passed through, and from state 2 to state 1 when you see that a full hour has passed.

That's really easy if you write an embedded python block!

Pseudocode for the work function that would be

import numpy as np
from gnuradio import gr

class yourblock(gr.basic_block):
    def __init__(self, period=60, input_length=708000, rate=44100):
       gr.basic_block.__init__(self, 
       name = "My block",
       in_sig = [np.float32],
       out_sig = [np.float32]
       )
       self._samples_per_cycle = int(period * rate)
       self._zeros_left = self._samples_per_cycle - input_length
       self._input_length = input_length
       self._input_left = input_length
       self._state = 0

def general_work(self, input_items, output_items):
       in_ = input_items[0]
       out_ = output_items[0]
       if self._state == 0: # Passing through from input
         to_copy = min(self._input_left, len(in_), len(out_))
         out_[0:to_copy] = in_[0:to_copy]
         self._input_left -= to_copy
         if(self._input_left == 0):
           self._state = 1
           self._zeros_left = self._samples_per_cycle - self._input_length
         self.consume_each(to_copy) # copied this much from input
         return to_copy             # wrote this much to output
       if self._state == 1:
         to_zero = min(self._zeros_left, len(in_), len(out_))
         out_[0:to_zero] = 0.0
         self._zeros_left -= to_zero
         if(self._zeros_left == 0):
           self._state = 0
           self._input_left = self._input_length
         self.consume_each(to_zero) # copied this much from input
         return to_zero             # wrote this much to output


Антон
  • 123
  • 4
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94