Piotr Krysik | ea34c01 | 2016-10-02 18:53:43 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python2 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # @file |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 4 | # @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com> |
Piotr Krysik | ea34c01 | 2016-10-02 18:53:43 +0200 | [diff] [blame] | 5 | # @section LICENSE |
| 6 | # |
| 7 | # Gr-gsm is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 3, or (at your option) |
| 10 | # any later version. |
| 11 | # |
| 12 | # Gr-gsm is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with gr-gsm; see the file COPYING. If not, write to |
| 19 | # the Free Software Foundation, Inc., 51 Franklin Street, |
| 20 | # Boston, MA 02110-1301, USA. |
| 21 | # |
Piotr Krysik | a6268a5 | 2017-08-23 16:02:19 +0200 | [diff] [blame] | 22 | |
piotr | 6b78abc | 2014-07-08 23:29:13 +0200 | [diff] [blame] | 23 | ################################################## |
| 24 | # Gnuradio Python Flow Graph |
| 25 | # Title: FCCH Bursts Detector |
| 26 | # Author: Piotr Krysik |
| 27 | # |
| 28 | # Description: Detects positions of FCCH bursts. At the end of each |
| 29 | # detected FCCH burst adds to the stream a tag with key "fcch" and value |
| 30 | # which is a frequency offset estimate. The input sampling frequency |
| 31 | # should be integer multiply of GSM GMKS symbol rate - 1625000/6 Hz. |
| 32 | ################################################## |
| 33 | |
| 34 | from gnuradio import blocks |
| 35 | from gnuradio import gr |
| 36 | from gnuradio.filter import firdes |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 37 | import grgsm |
piotr | 6b78abc | 2014-07-08 23:29:13 +0200 | [diff] [blame] | 38 | |
Piotr Krysik | 8715da0 | 2016-01-06 22:21:09 +0100 | [diff] [blame] | 39 | class fcch_detector(grgsm.hier_block): |
piotr | 6b78abc | 2014-07-08 23:29:13 +0200 | [diff] [blame] | 40 | |
| 41 | def __init__(self, OSR=4): |
Piotr Krysik | 8715da0 | 2016-01-06 22:21:09 +0100 | [diff] [blame] | 42 | grgsm.hier_block.__init__( |
piotr | 6b78abc | 2014-07-08 23:29:13 +0200 | [diff] [blame] | 43 | self, "FCCH bursts detector", |
| 44 | gr.io_signature(1, 1, gr.sizeof_gr_complex*1), |
| 45 | gr.io_signature(1, 1, gr.sizeof_gr_complex*1), |
| 46 | ) |
| 47 | |
| 48 | ################################################## |
| 49 | # Parameters |
| 50 | ################################################## |
| 51 | self.OSR = OSR |
| 52 | |
| 53 | ################################################## |
| 54 | # Variables |
| 55 | ################################################## |
| 56 | self.f_symb = f_symb = 1625000.0/6.0 |
| 57 | self.samp_rate = samp_rate = f_symb*OSR |
| 58 | |
| 59 | ################################################## |
| 60 | # Blocks |
| 61 | ################################################## |
ptrkrysik | 3be74a7 | 2014-12-13 10:11:00 +0100 | [diff] [blame] | 62 | self.gsm_fcch_burst_tagger_0 = grgsm.fcch_burst_tagger(OSR) |
piotr | 6b78abc | 2014-07-08 23:29:13 +0200 | [diff] [blame] | 63 | self.blocks_threshold_ff_0_0 = blocks.threshold_ff(0, 0, 0) |
| 64 | self.blocks_threshold_ff_0 = blocks.threshold_ff(int((138)*samp_rate/f_symb), int((138)*samp_rate/f_symb), 0) |
| 65 | self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1) |
| 66 | self.blocks_moving_average_xx_0 = blocks.moving_average_ff(int((142)*samp_rate/f_symb), 1, int(1e6)) |
| 67 | self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, int(OSR)) |
| 68 | self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1) |
| 69 | |
| 70 | ################################################## |
| 71 | # Connections |
| 72 | ################################################## |
| 73 | self.connect((self, 0), (self.blocks_multiply_conjugate_cc_0, 0)) |
| 74 | self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 1)) |
| 75 | self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_threshold_ff_0_0, 0)) |
| 76 | self.connect((self, 0), (self.blocks_delay_0, 0)) |
| 77 | self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0)) |
| 78 | self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_threshold_ff_0, 0)) |
| 79 | self.connect((self.blocks_threshold_ff_0_0, 0), (self.blocks_moving_average_xx_0, 0)) |
| 80 | self.connect((self.gsm_fcch_burst_tagger_0, 0), (self, 0)) |
| 81 | self.connect((self, 0), (self.gsm_fcch_burst_tagger_0, 0)) |
| 82 | self.connect((self.blocks_threshold_ff_0, 0), (self.gsm_fcch_burst_tagger_0, 1)) |
| 83 | |
| 84 | def get_OSR(self): |
| 85 | return self.OSR |
| 86 | |
| 87 | def set_OSR(self, OSR): |
| 88 | self.OSR = OSR |
| 89 | self.set_samp_rate(self.f_symb*self.OSR) |
| 90 | self.blocks_delay_0.set_dly(int(self.OSR)) |
| 91 | |
| 92 | |