blob: 9b787c2cead59d2e482ac4f4ff3d567d68520c4b [file] [log] [blame]
Piotr Krysikea34c012016-10-02 18:53:43 +02001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3# @file
Piotr Krysika6268a52017-08-23 16:02:19 +02004# @author (C) 2014 by Piotr Krysik <ptrkrysik@gmail.com>
Piotr Krysikea34c012016-10-02 18:53:43 +02005# @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 Krysika6268a52017-08-23 16:02:19 +020022
piotr6b78abc2014-07-08 23:29:13 +020023##################################################
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
34from gnuradio import blocks
35from gnuradio import gr
36from gnuradio.filter import firdes
ptrkrysik3be74a72014-12-13 10:11:00 +010037import grgsm
piotr6b78abc2014-07-08 23:29:13 +020038
Vasil Velichkov46c90be2019-09-02 04:06:41 +030039class fcch_detector(gr.hier_block2):
piotr6b78abc2014-07-08 23:29:13 +020040
41 def __init__(self, OSR=4):
Vasil Velichkov46c90be2019-09-02 04:06:41 +030042 gr.hier_block2.__init__(
piotr6b78abc2014-07-08 23:29:13 +020043 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 ##################################################
ptrkrysik3be74a72014-12-13 10:11:00 +010062 self.gsm_fcch_burst_tagger_0 = grgsm.fcch_burst_tagger(OSR)
piotr6b78abc2014-07-08 23:29:13 +020063 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