2 # Copyright 2008 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
22 # See Altera Application Note AN455
24 # R = decimation factor, 8-256
25 # Fc = passband (one-sided) cutoff frequency
28 function taps = cic_comp_taps(R, Fc, L)
29 M = 1; %% Differential delay
30 N = 4; %% Number of stages
31 B = 18; %% Coeffi. Bit-width
32 Fs = 64e6; %% (High) Sampling freq in Hz before decimation
33 Fo = R*Fc/Fs; %% Normalized Cutoff freq; 0<Fo<=0.5/M;
34 p = 2e3; %% Granularity
35 s = 0.25/p; %% Step size
36 fp = [0:s:Fo]; %% Pass band frequency samples
37 fs = (Fo+s):s:0.5; %% Stop band frequency samples
38 f = [fp fs]*2; %% Normalized frequency samples; 0<=f<=1
39 Mp = ones(1,length(fp)); %% Pass band response; Mp(1)=1
40 Mp(2:end) = abs( M*R*sin(pi*fp(2:end)/R)./sin(pi*M*fp(2:end))).^N;
41 Mf = [Mp zeros(1,length(fs))];
43 h = fir2(L,f,Mf); %% Filter length L+1
44 taps = h/sum(h); %% Floating point coefficients