|
|
@@ -60,9 +60,9 @@ M = 1; % Differential delay (only 1)
|
|
|
% ---- FIR filter parameters
|
|
|
% ------------------------------------------------------------------------
|
|
|
|
|
|
-NFIR = 16; % Filter order, must be odd when Fo = 0.5 !!!
|
|
|
+NFIR = 15; % Filter order, must be odd when Fo = 0.5 !!!
|
|
|
Bc = 16; % Coef. Bit-width
|
|
|
-Fo = 0.2; % Normalized Cutoff: 0.2 < Fo < 0.5;
|
|
|
+Fo = 0.5; % Normalized Cutoff: 0.2 < Fo < 0.5;
|
|
|
BETA = 8; % BETA parameter for Kaiser window (if IS_WIND = 'Y')
|
|
|
|
|
|
%% ------------------------------------------------------------------------
|
|
|
@@ -73,8 +73,8 @@ IS_COE = 'Y'; % create *.COE Xilinx file
|
|
|
IS_HDR = 'N'; % create *.H file (header)
|
|
|
IS_WIND = 'N'; % use Kaiser Window for FIR corrector
|
|
|
|
|
|
-IS_PLOT_IDL = 'N'; % plot ideal response
|
|
|
-IS_PLOT_FIR = 'N'; % plot FIR filter IR
|
|
|
+IS_PLOT_IDL = 'Y'; % plot ideal response
|
|
|
+IS_PLOT_FIR = 'Y'; % plot FIR filter IR
|
|
|
IS_PLOT_ERR = 'N'; % plot total error response in passband
|
|
|
|
|
|
%% ------------------------------------------------------------------------
|
|
|
@@ -99,25 +99,6 @@ HCICdb = 20 * log10(abs(HCIC));
|
|
|
Hcic = abs((sin(pi*M*R*ff) ./ sin(pi*ff))).^N;
|
|
|
Hcicdb = 20 * log10(abs(Hcic));
|
|
|
|
|
|
-
|
|
|
-##figure('name','Cic Response', 'Numbertitle', 'off')
|
|
|
-##plot(ff, Hcicdb - max(Hcicdb), '-.', 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
-##
|
|
|
-##title([{'Cic Response'};{sprintf('Fo = %i',Fo)}]);
|
|
|
-##xlabel ('Freq (\pi x rad / samples)');
|
|
|
-##ylabel ('Magnitude');
|
|
|
-##axis tight;
|
|
|
-##grid on;
|
|
|
-##
|
|
|
-##figure('name','Cic Response', 'Numbertitle', 'off')
|
|
|
-##plot(ff, HCICdb - max(HCICdb), '-.', 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
-##
|
|
|
-##title([{'Cic Response'};{sprintf('Fo = %i',Fo)}]);
|
|
|
-##xlabel ('Freq (\pi x rad / samples)');
|
|
|
-##ylabel ('Magnitude');
|
|
|
-##axis tight;
|
|
|
-##grid on;
|
|
|
-
|
|
|
fp = [0:STEP:Fo]; % Pass band frequency dots
|
|
|
fs = [(Fo+STEP):STEP:0.5]; % Stop band frequency dots
|
|
|
f = [fp fs]*2; % Normalized frequency dots
|
|
|
@@ -153,34 +134,45 @@ if (IS_WIND == 'Y')
|
|
|
hCOE = hNEW;
|
|
|
end
|
|
|
|
|
|
-if (IS_PLOT_FIR == 'Y')
|
|
|
- figure('name','FIR Response', 'Numbertitle', 'off')
|
|
|
- plot(hFIR, '-', 'LineWidth', 2, 'Color',[1 0 0]);
|
|
|
-
|
|
|
- title([{'FIR Response'};{sprintf('Order = %i',NFIR)}]);
|
|
|
- xlabel ('Samples');
|
|
|
- ylabel ('Magnitude');
|
|
|
- axis tight;
|
|
|
- legend([{sprintf('Order = %i',NFIR)}]);
|
|
|
- grid on;
|
|
|
-end
|
|
|
+##if (IS_PLOT_FIR == 'Y')
|
|
|
+## figure('name','FIR Response', 'Numbertitle', 'off')
|
|
|
+## plot(hFIR, '-', 'LineWidth', 2, 'Color',[1 0 0]);
|
|
|
+##
|
|
|
+## title([{'FIR Response'};{sprintf('Order = %i',NFIR)}]);
|
|
|
+## xlabel ('Samples');
|
|
|
+## ylabel ('Magnitude');
|
|
|
+## axis tight;
|
|
|
+## legend([{sprintf('Order = %i',NFIR)}]);
|
|
|
+## grid on;
|
|
|
+##end
|
|
|
|
|
|
hFFT = 20 * log10(abs(fft(hCOE, ceil(NFFT/R))));
|
|
|
hFFT = hFFT - max(hFFT);
|
|
|
|
|
|
-H_amp = repmat(hFFT, 1, R);
|
|
|
+H_amp = repmat(hFFT, 1, R*2);
|
|
|
H_amp = H_amp(1:length(ff));
|
|
|
-Test = max(H_amp);
|
|
|
+
|
|
|
H_amp = H_amp - max(H_amp);
|
|
|
|
|
|
H_comp = HCICdb + H_amp;
|
|
|
H_comp = H_comp - max(H_comp);
|
|
|
|
|
|
+if (IS_PLOT_FIR == 'Y')
|
|
|
+ figure('name','FIR Response', 'Numbertitle', 'off')
|
|
|
+ plot(ff,H_amp, '-', 'LineWidth', 2, 'Color',[1 0 0]);
|
|
|
+
|
|
|
+ title([{'FIR Response'};{sprintf('Order = %i',NFIR)}]);
|
|
|
+ xlabel ('Samples');
|
|
|
+ ylabel ('Magnitude');
|
|
|
+ axis([0 ff(NFFT)/2 -100 5]);
|
|
|
+ legend([{sprintf('Order = %i',NFIR)}]);
|
|
|
+ grid on;
|
|
|
+end
|
|
|
%% ------------------------------------------------------------------------
|
|
|
% ---- Plot results
|
|
|
% ------------------------------------------------------------------------
|
|
|
|
|
|
-% ---- Figure #1
|
|
|
+## ---- Figure #1
|
|
|
figure('name','CIC/FIR Frequency Response', 'Numbertitle', 'off')
|
|
|
plot(ff, HCICdb - max(HCICdb), '-.', 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
hold on;
|
|
|
@@ -195,29 +187,29 @@ figure('name','CIC/FIR Frequency Response', 'Numbertitle', 'off')
|
|
|
xlabel ('Freq (\pi x rad / samples)');
|
|
|
ylabel ('Magnitude (dB)');
|
|
|
axis([0 ff(NFFT)/2 -100 5]);
|
|
|
- line([Fr Fr], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [0 0 0]);
|
|
|
- line([Fc Fc], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [0 0 0]);
|
|
|
- line([2*Fc 2*Fc], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [0 0 0]);
|
|
|
+ line([Fr Fr], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [0 0 1]);
|
|
|
+ line([Fc Fc], [-400 200], 'LineWidth', 1, 'linestyle', '-.', 'Color', [0 0.4 0]);
|
|
|
+ line([2*Fc 2*Fc], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [1 0 0]);
|
|
|
legend('CIC filter','Comp. FIR','Sum Response','location','northeast');
|
|
|
grid on;
|
|
|
|
|
|
-% ---- Figure #2
|
|
|
-figure('name', 'CIC/FIR Frequency Response (Zoom)', 'Numbertitle', 'off')
|
|
|
- plot(ff, HCICdb - max(HCICdb), '-.', 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
- hold on;
|
|
|
-
|
|
|
- plot(ff, H_amp, '--', 'LineWidth', 2, 'Color',[0 0.4 0]);
|
|
|
- hold on;
|
|
|
-
|
|
|
- plot(ff, H_comp, '-', 'LineWidth', 2, 'Color',[1 0 0]);
|
|
|
- hold on;
|
|
|
-
|
|
|
- title([{'CIC, Comp. FIR and Result'};{sprintf('Filter Order = %i, Coef. width = %i',NFIR,Bc)}]);
|
|
|
- xlabel ('Freq (\pi x rad / samples)');
|
|
|
- ylabel ('Magnitude (dB)');
|
|
|
- axis([0 ff(NFFT)/(2*R) -7 1]);
|
|
|
- line([Fr Fr], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [0 0 0]);
|
|
|
- grid on;
|
|
|
+## ---- Figure #2
|
|
|
+##figure('name', 'CIC/FIR Frequency Response (Zoom)', 'Numbertitle', 'off')
|
|
|
+## plot(ff, HCICdb - max(HCICdb), '-.', 'LineWidth', 2, 'Color',[0 0 1]);
|
|
|
+## hold on;
|
|
|
+##
|
|
|
+## plot(ff, H_amp, '--', 'LineWidth', 2, 'Color',[0 0.4 0]);
|
|
|
+## hold on;
|
|
|
+##
|
|
|
+## plot(ff, H_comp, '-', 'LineWidth', 2, 'Color',[1 0 0]);
|
|
|
+## hold on;
|
|
|
+##
|
|
|
+## title([{'CIC, Comp. FIR and Result'};{sprintf('Filter Order = %i, Coef. width = %i',NFIR,Bc)}]);
|
|
|
+## xlabel ('Freq (\pi x rad / samples)');
|
|
|
+## ylabel ('Magnitude (dB)');
|
|
|
+## axis([0 ff(NFFT)/(2*R) -7 1]);
|
|
|
+## line([Fr Fr], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [0 0 0]);
|
|
|
+## grid on;
|
|
|
|
|
|
%% ------------------------------------------------------------------------
|
|
|
% ---- Passband irregularity
|
|
|
@@ -273,3 +265,16 @@ if (IS_HDR == 'Y')
|
|
|
fclose(fid);
|
|
|
end
|
|
|
|
|
|
+##figure('name','CIC/FIR Frequency Response', 'Numbertitle', 'off')
|
|
|
+##
|
|
|
+## plot(ff, H_amp, '--', 'LineWidth', 2, 'Color',[0 0.4 0]);
|
|
|
+## hold on;
|
|
|
+##
|
|
|
+## title([{'CIC, Comp. FIR and Result'};{sprintf('Filter Order = %i, Coef. width = %i',NFIR,Bc)}]);
|
|
|
+## xlabel ('Freq (\pi x rad / samples)');
|
|
|
+## ylabel ('Magnitude (dB)');
|
|
|
+## axis([0 ff(NFFT)/2 -100 5]);
|
|
|
+## line([Fr Fr], [-400 200], 'LineWidth', 1, 'linestyle', '--', 'Color', [0 0 0]);
|
|
|
+## legend('Comp. FIR','location','northeast');
|
|
|
+## grid on;
|
|
|
+
|