⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ciccomp.m

📁 Designing Digital Down Conversion Systems with Altera CIC MegaCore and FIR Compensation Filter v6.1
💻 M
字号:
% (c) 2006 Altera Corporation. All rights reserved.  Altera products are protected under numerous U.S. and foreign patents, maskwork rights, 
% copyrights and other intellectual property laws. This design file, and your use thereof, is subject to and governed by the terms and 
% conditions of the applicable Altera Reference Design License Agreement (found at www.altera.com).
% By using this reference design file, you indicate your acceptance of such terms and conditions between you and Altera Corporation. 
% In the event that you do not agree with such terms and conditions, you may not use the reference design file and please promptly destroy 
% any copies you have made.  This reference design file being provided on
% an "as-is" basis and as an accommodation and therefore all warranties, representations or  
% guarantees of any kind (whether express, implied or statutory) including, without limitation, warranties of merchantability, 
% non-infringement, or fitness for a particular purpose, are specifically disclaimed. 
% By making this reference design file available, Altera expressly does not recommend, suggest or require that this reference design file
% be used in combination with any other product not provided by Altera.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CIC compensating filter design using frequency sampling method

clear all
close all

%%%%%% CIC filter parameters %%%%%%
R = 4;                                      %% Decimation factor
M = 1;                                      %% Differential Delay
N = 8;                                      %% Number of Stages
B = 18;                                     %% Number of bits to represent fixed point filter coefficients
Fs = 91.392e6;                              %% (High) Sampling frequency in Hz (before decimation)
Fc = 4.85e6;                                %% Passband edge in Hz
%%%%%%% fir2.m parameters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
L = 110;                                    %% Order of filter taps; must be an even number
Fo = R*Fc/Fs;                               %% Normalized Cutoff freq; 0<Fo<=0.5/M; 
                                            %% Fo should be less than 1/(4M) for good performance                              
% Fo = 0.5/M;                                 %% use Fo=0.5 if we don't care responses outside passband

%%%%%%% CIC Compensator Design using fir2.m %%%%%%
p = 2e3;                                    %% Granulatiry
s = 0.25/p;                                 %% Stepsize
fp = [0:s:Fo];                              %% Passband frequency samples                                        
fs = (Fo+s):s:0.5;                          %% Stopband frequency samples
f = [fp fs]*2;                              %% Noramlized frequency samples; 0<=f<=1; 
Mp = ones(1,length(fp));                    %% Passband response; Mp(1)=1
Mp(2:end) = abs( M*R*sin(pi*fp(2:end)/R)./sin(pi*M*fp(2:end))).^N; %% Inverse sinc
Mf = [Mp zeros(1,length(fs))];
f(end) = 1;
h = fir2(L,f,Mf);                           %% Filter length L+1
h = h/max(h);                              %% Floating point coefficients
hz = round(h*power(2,B-1)-1);                   %% Quantization of filter coefficients

%%%%%%% Full resolution CIC filter response %%%%%%%%
hrec = ones(1,R*M);
tmph = hrec;

for k=1:N-1
    tmph = conv(hrec, tmph);
end;
hcic = tmph;
hcic=hcic/norm(hcic);

%%%%%%% Total Response %%%%%%%%%%%%%%%
hzp = upsample(hz,R);
hp = upsample(h, R);
ht = conv(hcic, hp);                        %% Concatenation of CIC and fir2 FIR at high freqency
hzt = conv(hcic, hzp);                      %% CIC + Fixed point fir2 at high frequency

[Hcic, wt] = freqz(hcic, 1, 4096, Fs);      %% CIC Freq. Response
[Hciccomp, wt] = freqz(hp, 1, 4096, Fs);    %% CIC Comp. response using fir2
[Ht, wt] = freqz(ht, 1, 4096, Fs);          %% Total response for CIC + floating point fir2
[Hzt, wt] = freqz(hzt, 1, 4096, Fs);        %% Total response for CIC + fixed point fir2

Mcic = 20*log10(abs(Hcic)/max(abs(Hcic)));  %% CIC Freq. Response
Mciccomp = 20*log10(abs(Hciccomp)/max(abs(Hciccomp)));  %% CIC Comp. response using fir2
Mt = 20*log10(abs(Ht)/max(abs(Ht)));        %% Total response for CIC + floating point fir2
Mzt = 20*log10(abs(Hzt)/max(abs(Hzt)));     %% Total response for CIC + fixed point fir2

figure;
plot(wt, Mcic, wt, Mciccomp, wt, Mt,wt, Mzt);
legend('CIC','CIC Comp','Total Response (Floating Point)','Total Response (Fixed Point)')
ylim([-100 5]);
title('Frequency Sampling Method');
grid
xlabel('Frequency Hz');
ylabel('Filter Magnitude Response dB');

%%%%%%%%% Save filter coefficients for Altera FIR Compiler %%%%%%%%%
filename = ['fdcoeffR',num2str(R),'N',num2str(N),'M',num2str(M),'L',num2str(L),'.txt'];
fid = fopen(filename, 'wt');
fprintf(fid, '%18.0f \n', hz); %% fixed point coeff
% fprintf(fid, '%0.6d\n',h); %% floating point
fclose(fid)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -