3 # Copyright 2006, 2007, 2008 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio 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)
12 # GNU Radio 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.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
25 from gnuradio import gr
26 from gnuradio.blks2impl.ofdm_sync_ml import ofdm_sync_ml
27 from gnuradio.blks2impl.ofdm_sync_pn import ofdm_sync_pn
28 from gnuradio.blks2impl.ofdm_sync_pnac import ofdm_sync_pnac
29 from gnuradio.blks2impl.ofdm_sync_fixed import ofdm_sync_fixed
31 class ofdm_receiver(gr.hier_block2):
33 Performs receiver synchronization on OFDM symbols.
35 The receiver performs channel filtering as well as symbol, frequency, and phase synchronization.
36 The synchronization routines are available in three flavors: preamble correlator (Schmidl and Cox),
37 modifid preamble correlator with autocorrelation (not yet working), and cyclic prefix correlator
41 def __init__(self, fft_length, cp_length, occupied_tones, snr, ks, logging=False):
43 Hierarchical block for receiving OFDM symbols.
45 The input is the complex modulated signal at baseband.
46 Synchronized packets are sent back to the demodulator.
48 @param fft_length: total number of subcarriers
50 @param cp_length: length of cyclic prefix as specified in subcarriers (<= fft_length)
52 @param occupied_tones: number of subcarriers used for data
53 @type occupied_tones: int
54 @param snr: estimated signal to noise ratio used to guide cyclic prefix synchronizer
56 @param ks: known symbols used as preambles to each packet
57 @type ks: list of lists
58 @param logging: turn file logging on or off
62 gr.hier_block2.__init__(self, "ofdm_receiver",
63 gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
64 gr.io_signature2(2, 2, gr.sizeof_gr_complex*occupied_tones, gr.sizeof_char)) # Output signature
66 bw = (float(occupied_tones) / float(fft_length)) / 2.0
68 chan_coeffs = gr.firdes.low_pass (1.0, # gain
70 bw+tb, # midpoint of trans. band
71 tb, # width of trans. band
72 gr.firdes.WIN_HAMMING) # filter type
73 self.chan_filt = gr.fft_filter_ccc(1, chan_coeffs)
75 win = [1 for i in range(fft_length)]
77 zeros_on_left = int(math.ceil((fft_length - occupied_tones)/2.0))
79 ks0[zeros_on_left : zeros_on_left + occupied_tones] = ks[0]
81 ks0 = fft.ifftshift(ks0)
82 ks0time = fft.ifft(ks0)
84 ks0time = ks0time.tolist()
88 nco_sensitivity = -1.0/fft_length # correct for fine frequency
89 self.ofdm_sync = ofdm_sync_ml(fft_length, cp_length, snr, ks0time, logging)
91 nco_sensitivity = -2.0/fft_length # correct for fine frequency
92 self.ofdm_sync = ofdm_sync_pn(fft_length, cp_length, logging)
94 nco_sensitivity = -2.0/fft_length # correct for fine frequency
95 self.ofdm_sync = ofdm_sync_pnac(fft_length, cp_length, ks0time, logging)
96 elif SYNC == "fixed": # for testing only; do not user over the air
97 self.chan_filt = gr.multiply_const_cc(1.0) # remove filter and filter delay for this
98 nsymbols = 18 # enter the number of symbols per packet
99 freq_offset = 0.0 # if you use a frequency offset, enter it here
100 nco_sensitivity = -2.0/fft_length # correct for fine frequency
101 self.ofdm_sync = ofdm_sync_fixed(fft_length, cp_length, nsymbols, freq_offset, logging)
105 self.nco = gr.frequency_modulator_fc(nco_sensitivity) # generate a signal proportional to frequency error of sync block
106 self.sigmix = gr.multiply_cc()
107 self.sampler = gr.ofdm_sampler(fft_length, fft_length+cp_length)
108 self.fft_demod = gr.fft_vcc(fft_length, True, win, True)
109 self.ofdm_frame_acq = gr.ofdm_frame_acquisition(occupied_tones, fft_length,
112 self.connect(self, self.chan_filt) # filter the input channel
113 self.connect(self.chan_filt, self.ofdm_sync) # into the synchronization alg.
114 self.connect((self.ofdm_sync,0), self.nco, (self.sigmix,1)) # use sync freq. offset output to derotate input signal
115 self.connect(self.chan_filt, (self.sigmix,0)) # signal to be derotated
116 self.connect(self.sigmix, (self.sampler,0)) # sample off timing signal detected in sync alg
117 self.connect((self.ofdm_sync,1), (self.sampler,1)) # timing signal to sample at
119 self.connect((self.sampler,0), self.fft_demod) # send derotated sampled signal to FFT
120 self.connect(self.fft_demod, (self.ofdm_frame_acq,0)) # find frame start and equalize signal
121 self.connect((self.sampler,1), (self.ofdm_frame_acq,1)) # send timing signal to signal frame start
122 self.connect((self.ofdm_frame_acq,0), (self,0)) # finished with fine/coarse freq correction,
123 self.connect((self.ofdm_frame_acq,1), (self,1)) # frame and symbol timing, and equalization
126 self.connect(self.chan_filt, gr.file_sink(gr.sizeof_gr_complex, "ofdm_receiver-chan_filt_c.dat"))
127 self.connect(self.fft_demod, gr.file_sink(gr.sizeof_gr_complex*fft_length, "ofdm_receiver-fft_out_c.dat"))
128 self.connect(self.ofdm_frame_acq,
129 gr.file_sink(gr.sizeof_gr_complex*occupied_tones, "ofdm_receiver-frame_acq_c.dat"))
130 self.connect((self.ofdm_frame_acq,1), gr.file_sink(1, "ofdm_receiver-found_corr_b.dat"))
131 self.connect(self.sampler, gr.file_sink(gr.sizeof_gr_complex*fft_length, "ofdm_receiver-sampler_c.dat"))
132 self.connect(self.sigmix, gr.file_sink(gr.sizeof_gr_complex, "ofdm_receiver-sigmix_c.dat"))
133 self.connect(self.nco, gr.file_sink(gr.sizeof_gr_complex, "ofdm_receiver-nco_c.dat"))