Advertisement
Guest User

Untitled

a guest
Jan 17th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. import numpy as np
  2. from gnuradio import gr
  3. import pmt
  4.  
  5.  
  6. class MTS_basic_py(gr.basic_block):
  7. """
  8. docstring for block MTS_basic_py
  9. """
  10.  
  11. def __init__(self, pos, vel, rcs, fs, fc, prf, len_tag_key, pulse_len):
  12. gr.basic_block.__init__(self,
  13. name="MTS_basic_py",
  14. in_sig=[np.complex64],
  15. out_sig=[np.complex64]),
  16. self.pos = pos
  17. self.vel = vel
  18. self.rcs = rcs
  19. self.fs = fs
  20. self.fc = fc
  21. self.PRF = prf
  22. self.PRI = 1 / self.PRF
  23. self.len_tag_key = len_tag_key
  24. self.curr_pulse = 0
  25. self.pulse_len = pulse_len
  26.  
  27. def forecast(self, noutput_items, ninput_items_required):
  28. # setup size of input_items[i] for work call
  29. for i in range(len(ninput_items_required)):
  30. ninput_items_required[i] = noutput_items
  31.  
  32. def general_work(self, input_items, output_items):
  33. in0 = input_items[0][:len(output_items[0])]
  34. out = output_items[0]
  35. # Start and end of current input
  36. start_n = self.nitems_read(0)
  37. end_n = start_n + len(in0)
  38.  
  39. # Start of burst tags
  40. tags = self.get_tags_in_range(0, start_n, end_n,
  41. pmt.string_to_symbol(self.len_tag_key))
  42. # No tags found in the input. Consume all, return nothing
  43. if len(tags) == 0:
  44. out[:] = 0
  45. out = np.trim_zeros(out)
  46. self.consume(0, len(input_items[0]))
  47. return len(out)
  48. # Since we're moving the first tag in the input to offset 0, get info
  49. # for the first tag
  50. tag = tags[0]
  51. # Offset not aligned. Consume samples before the tag and output nothing
  52. if tag.offset != start_n:
  53. out[:] = 0
  54. out = np.trim_zeros(out)
  55. self.consume(0, tag.offset - start_n)
  56. return len(out)
  57. # Tags should be aligned, get the pulse length from the tag value,
  58. # and (for now) copy the input pulse directly to the output and
  59. # return only the part of the output with the pulse
  60. else:
  61. self.curr_pulse += 1
  62. out[:self.pulse_len] = in0[:self.pulse_len]
  63. out[self.pulse_len:] = 0
  64. out = np.trim_zeros(out)
  65. self.consume(0, self.pulse_len)
  66. return len(out)
  67.  
  68. def simulate_target(self):
  69. return 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement