OpenCores
URL https://opencores.org/ocsvn/astron_wb_fft/astron_wb_fft/trunk

Subversion Repositories astron_wb_fft

[/] [astron_wb_fft/] [trunk/] [fft_r2_pipe.vhd] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 danv
--------------------------------------------------------------------------------
2
-- Author: Harm Jan Pepping : HJP at astron.nl: April 2012
3
--------------------------------------------------------------------------------
4
--
5
-- Copyright (C) 2012
6
-- ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/>
7
-- P.O.Box 2, 7990 AA Dwingeloo, The Netherlands
8
--
9
-- This program is free software: you can redistribute it and/or modify
10
-- it under the terms of the GNU General Public License as published by
11
-- the Free Software Foundation, either version 3 of the License, or
12
-- (at your option) any later version.
13
--
14
-- This program is distributed in the hope that it will be useful,
15
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
16
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
-- GNU General Public License for more details.
18
--
19
-- You should have received a copy of the GNU General Public License
20
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
--
22
--------------------------------------------------------------------------------  --
23
-- Purpose:  Complex Pipelined Fast Fourier Transform
24
-- 
25
-- Description: The fft_r2_pipe unit performs a complex pipelined FFT on the incoming data stream.
26
--              The implementation is pipelined which means that at every stage only one 
27
--              multiplier is used to perform all N/2 twiddle multiplications. 
28
--              
29
--              There are two optional features: 
30
--              
31
--              * Reordering: When enabled the output bins of the FFT are re-ordered in 
32
--                            in such a way that the bins represent the frequencies in an 
33
--                            incrementing way. 
34
--              
35
--              * Separation: When enabled the fft_r2_pipe can be used to process two real streams.
36
--                            The first real stream (A) presented on the real input, the second 
37
--                            real stream (B) presented on the imaginary input. 
38
--                            The separation unit processes outputs the spectrum of A and B in 
39
--                            an alternating way: A(0), B(0), A(1), B(1).... etc
40
--
41
--
42
-- Remarks: When g_fft.nof_chan is used the spectrums at the output will be interleaved
43
--          per spectrum and NOT per sample. So in case g_fft.nof_chan = 1 there will be
44
--          two multiplexed channels at the input (c0t0 means channel 0, timestamp 0) :
45
--         
46
--          c0t0 c1t0s c0t1 c1t1 c0t2 c1t2 ... c0t15 c1t15 
47
--
48
--          At the output will find: 
49
--
50
--          c0f0 c0f1 c0f2 ... c0f15 c1f0 c1f1 c1f2 ... c1f15  (c0f0 means channel 0, frequency bin 0)
51
--
52
--           
53
 
54
library ieee, common_pkg_lib, common_components_lib,  common_requantize_lib, rTwoSDF_lib;
55
use IEEE.std_logic_1164.all;
56
use common_pkg_lib.common_pkg.all;
57
use rTwoSDF_lib.rTwoSDFPkg.all;
58
use work.fft_pkg.all;
59
 
60
entity fft_r2_pipe is
61
  generic (
62
    g_fft      : t_fft := c_fft;                   -- generics for the FFT
63
    g_pipeline : t_fft_pipeline := c_fft_pipeline; -- generics for pipelining in each stage, defined in rTwoSDF_lib.rTwoSDFPkg
64
    g_dont_flip_channels : boolean := false        -- generic to prevent re-ordering of the channels
65
  );
66
  port (
67
    clk      : in  std_logic;
68
    rst      : in  std_logic := '0';
69
    in_re    : in  std_logic_vector(g_fft.in_dat_w-1 downto 0);
70
    in_im    : in  std_logic_vector(g_fft.in_dat_w-1 downto 0);
71
    in_val   : in  std_logic := '1';
72
    out_re   : out std_logic_vector(g_fft.out_dat_w-1 downto 0);
73
    out_im   : out std_logic_vector(g_fft.out_dat_w-1 downto 0);
74
    out_val  : out std_logic
75
  );
76
end entity fft_r2_pipe;
77
 
78
architecture str of fft_r2_pipe is
79
 
80
  constant c_pipeline_remove_lsb : natural := 0;
81
 
82
  constant c_nof_stages         : natural := ceil_log2(g_fft.nof_points);
83
  constant c_stage_offset       : natural := true_log2(g_fft.wb_factor);                         -- Stage offset is required for twiddle generation in wideband fft
84
  constant c_in_scale_w         : natural := g_fft.stage_dat_w - g_fft.in_dat_w - sel_a_b(g_fft.guard_enable, g_fft.guard_w, 0);
85
  constant c_out_scale_w        : integer := g_fft.stage_dat_w - g_fft.out_dat_w - g_fft.out_gain_w;  -- Estimate number of LSBs to throw throw away when > 0 or insert when < 0
86
 
87
  -- number the stage instances from c_nof_stages:1
88
  -- . the data input for the first stage has index c_nof_stages
89
  -- . the data output of the last stage has index 0
90
  type t_data_arr is array(c_nof_stages downto 0) of std_logic_vector(g_fft.stage_dat_w-1 downto 0);
91
 
92
  signal data_re      : t_data_arr;
93
  signal data_im      : t_data_arr;
94
  signal data_val     : std_logic_vector(c_nof_stages downto 0):= (others=>'0');
95
 
96
  signal out_cplx     : std_logic_vector(c_nof_complex*g_fft.stage_dat_w-1 downto 0);
97
  signal in_cplx      : std_logic_vector(c_nof_complex*g_fft.stage_dat_w-1 downto 0);
98
  signal raw_out_re   : std_logic_vector(g_fft.stage_dat_w-1 downto 0);
99
  signal raw_out_im   : std_logic_vector(g_fft.stage_dat_w-1 downto 0);
100
  signal raw_out_val  : std_logic;
101
 
102
begin
103
 
104
  -- Inputs
105
  data_re( c_nof_stages) <= scale_and_resize_svec(in_re, c_in_scale_w, g_fft.stage_dat_w);
106
  data_im( c_nof_stages) <= scale_and_resize_svec(in_im, c_in_scale_w, g_fft.stage_dat_w);
107
  data_val(c_nof_stages) <= in_val;
108
 
109
  ------------------------------------------------------------------------------
110
  -- pipelined FFT stages
111
  ------------------------------------------------------------------------------
112
  gen_fft: for stage in c_nof_stages downto 1 generate
113
    u_stage : entity rTwoSDF_lib.rTwoSDFStage
114
    generic map (
115
      g_nof_chan       => g_fft.nof_chan,
116
      g_stage          => stage,
117
      g_stage_offset   => c_stage_offset,
118
      g_twiddle_offset => g_fft.twiddle_offset,
119
      g_scale_enable   => sel_a_b(stage <= g_fft.guard_w, FALSE, TRUE),
120
      g_pipeline       => g_pipeline
121
    )
122
    port map (
123
      clk       => clk,
124
      rst       => rst,
125
      in_re     => data_re(stage),
126
      in_im     => data_im(stage),
127
      in_val    => data_val(stage),
128
      out_re    => data_re(stage-1),
129
      out_im    => data_im(stage-1),
130
      out_val   => data_val(stage-1)
131
    );
132
  end generate;
133
 
134
  ------------------------------------------------------------------------------
135
  -- Optional output reorder and separation
136
  ------------------------------------------------------------------------------
137
  gen_reorder_and_separate : if(g_fft.use_separate or g_fft.use_reorder) generate
138
    in_cplx <= data_im(0) & data_re(0);
139
 
140
    u_reorder_sep : entity work.fft_reorder_sepa_pipe
141
    generic map (
142
      g_bit_flip    => g_fft.use_reorder,
143
      g_fft_shift   => g_fft.use_fft_shift,
144
      g_separate    => g_fft.use_separate,
145
      g_dont_flip_channels => g_dont_flip_channels,
146
      g_nof_points  => g_fft.nof_points,
147
      g_nof_chan    => g_fft.nof_chan
148
    )
149
    port map (
150
      clk     => clk,
151
      rst     => rst,
152
      in_dat  => in_cplx,
153
      in_val  => data_val(0),
154
      out_dat => out_cplx,
155
      out_val => raw_out_val
156
    );
157
 
158
    raw_out_re <= out_cplx(  g_fft.stage_dat_w-1 downto 0);
159
    raw_out_im <= out_cplx(2*g_fft.stage_dat_w-1 downto g_fft.stage_dat_w);
160
 
161
  end generate;
162
 
163
  no_reorder_no_generate : if(g_fft.use_separate=false and g_fft.use_reorder=false) generate
164
    raw_out_re  <= data_re(0);
165
    raw_out_im  <= data_im(0);
166
    raw_out_val <= data_val(0);
167
  end generate;
168
 
169
  ------------------------------------------------------------------------------
170
  -- pipelined FFT output requantization
171
  ------------------------------------------------------------------------------
172
  u_requantize_re : entity common_requantize_lib.common_requantize
173
  generic map (
174
    g_representation      => "SIGNED",
175
    g_lsb_w               => c_out_scale_w,
176
    g_lsb_round           => TRUE,
177
    g_lsb_round_clip      => FALSE,
178
    g_msb_clip            => FALSE,
179
    g_msb_clip_symmetric  => FALSE,
180
    g_pipeline_remove_lsb => c_pipeline_remove_lsb,
181
    g_pipeline_remove_msb => 0,
182
    g_in_dat_w            => g_fft.stage_dat_w,
183
    g_out_dat_w           => g_fft.out_dat_w
184
  )
185
  port map (
186
    clk        => clk,
187
    in_dat     => raw_out_re,
188
    out_dat    => out_re,
189
    out_ovr    => open
190
  );
191
 
192
  u_requantize_im : entity common_requantize_lib.common_requantize
193
  generic map (
194
    g_representation      => "SIGNED",
195
    g_lsb_w               => c_out_scale_w,
196
    g_lsb_round           => TRUE,
197
    g_lsb_round_clip      => FALSE,
198
    g_msb_clip            => FALSE,
199
    g_msb_clip_symmetric  => FALSE,
200
    g_pipeline_remove_lsb => c_pipeline_remove_lsb,
201
    g_pipeline_remove_msb => 0,
202
    g_in_dat_w            => g_fft.stage_dat_w,
203
    g_out_dat_w           => g_fft.out_dat_w
204
  )
205
  port map (
206
    clk        => clk,
207
    in_dat     => raw_out_im,
208
    out_dat    => out_im,
209
    out_ovr    => open
210
  );
211
 
212
  -- Valid Output
213
  u_out_val : entity common_components_lib.common_pipeline_sl
214
  generic map (
215
    g_pipeline => c_pipeline_remove_lsb
216
  )
217
  port map (
218
    rst     => rst,
219
    clk     => clk,
220
    in_dat  => raw_out_val,
221
    out_dat => out_val
222
  );
223
 
224
end str;
225
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.