blob: 06a1257a7cf9d8d5c60f3647cf3468ce9aa768f2 [file] [log] [blame]
Piotr Krysikea34c012016-10-02 18:53:43 +02001#!/usr/bin/env python2
2# -*- coding: utf-8 -*-
3# @file
4# @author Piotr Krysik <ptrkrysik@gmail.com>
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#
piotr6b78abc2014-07-08 23:29:13 +020022##################################################
23# Gnuradio Python Flow Graph
24# Title: FCCH Bursts Detector
25# Author: Piotr Krysik
26#
27# Description: Detects positions of FCCH bursts. At the end of each
28# detected FCCH burst adds to the stream a tag with key "fcch" and value
29# which is a frequency offset estimate. The input sampling frequency
30# should be integer multiply of GSM GMKS symbol rate - 1625000/6 Hz.
31##################################################
32
33from gnuradio import blocks
34from gnuradio import gr
35from gnuradio.filter import firdes
ptrkrysik3be74a72014-12-13 10:11:00 +010036import grgsm
piotr6b78abc2014-07-08 23:29:13 +020037
Piotr Krysik8715da02016-01-06 22:21:09 +010038class fcch_detector(grgsm.hier_block):
piotr6b78abc2014-07-08 23:29:13 +020039
40 def __init__(self, OSR=4):
Piotr Krysik8715da02016-01-06 22:21:09 +010041 grgsm.hier_block.__init__(
piotr6b78abc2014-07-08 23:29:13 +020042 self, "FCCH bursts detector",
43 gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
44 gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
45 )
46
47 ##################################################
48 # Parameters
49 ##################################################
50 self.OSR = OSR
51
52 ##################################################
53 # Variables
54 ##################################################
55 self.f_symb = f_symb = 1625000.0/6.0
56 self.samp_rate = samp_rate = f_symb*OSR
57
58 ##################################################
59 # Blocks
60 ##################################################
ptrkrysik3be74a72014-12-13 10:11:00 +010061 self.gsm_fcch_burst_tagger_0 = grgsm.fcch_burst_tagger(OSR)
piotr6b78abc2014-07-08 23:29:13 +020062 self.blocks_threshold_ff_0_0 = blocks.threshold_ff(0, 0, 0)
63 self.blocks_threshold_ff_0 = blocks.threshold_ff(int((138)*samp_rate/f_symb), int((138)*samp_rate/f_symb), 0)
64 self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
65 self.blocks_moving_average_xx_0 = blocks.moving_average_ff(int((142)*samp_rate/f_symb), 1, int(1e6))
66 self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, int(OSR))
67 self.blocks_complex_to_arg_0 = blocks.complex_to_arg(1)
68
69 ##################################################
70 # Connections
71 ##################################################
72 self.connect((self, 0), (self.blocks_multiply_conjugate_cc_0, 0))
73 self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_conjugate_cc_0, 1))
74 self.connect((self.blocks_complex_to_arg_0, 0), (self.blocks_threshold_ff_0_0, 0))
75 self.connect((self, 0), (self.blocks_delay_0, 0))
76 self.connect((self.blocks_multiply_conjugate_cc_0, 0), (self.blocks_complex_to_arg_0, 0))
77 self.connect((self.blocks_moving_average_xx_0, 0), (self.blocks_threshold_ff_0, 0))
78 self.connect((self.blocks_threshold_ff_0_0, 0), (self.blocks_moving_average_xx_0, 0))
79 self.connect((self.gsm_fcch_burst_tagger_0, 0), (self, 0))
80 self.connect((self, 0), (self.gsm_fcch_burst_tagger_0, 0))
81 self.connect((self.blocks_threshold_ff_0, 0), (self.gsm_fcch_burst_tagger_0, 1))
82
83 def get_OSR(self):
84 return self.OSR
85
86 def set_OSR(self, OSR):
87 self.OSR = OSR
88 self.set_samp_rate(self.f_symb*self.OSR)
89 self.blocks_delay_0.set_dly(int(self.OSR))
90
91