Parcourir la source

Пересчитан фильтр

ChStepan il y a 1 an
Parent
commit
e54e5078b0

+ 7 - 6
src/src/FftDataFiltering/DecimFilterWrapper.v

@@ -84,15 +84,16 @@ module	DecimFilterWrapper
 	
 	wire	[39:0]	firData;
 	wire	firDataVal;
+	wire	bypassData = (DecimFactor_i==3'd0 | DecimFactor_i==3'd1);
 //================================================================================
 //	ASSIGNMENTS
 //================================================================================
 
 	// assign	FilteredAdcDataI_o	=	outDataI;
-	assign	FilteredAdcDataI_o	=	firData[33-:16];
+	assign	FilteredAdcDataI_o	=	(bypassData)?{{2{AdcData_i[AdcDataWidth-1]}},AdcData_i}:firData[33-:16];
 
 	// assign	FilteredDataVal_o	=	decimDataValIR;
-	assign	FilteredDataVal_o	=	firDataVal;
+	assign	FilteredDataVal_o	=	(bypassData)?1'b1:firDataVal;
 
 
 // {{14{AdcData_i[AdcDataWidth-1]}},AdcData_i}
@@ -105,21 +106,21 @@ always	@(posedge	Clk_i)	begin
 	if	(!Rst_i)	begin
 		case(DecimFactor_i)
 			3'd0:	begin
-						outDataI	<=	AdcData_i;
+						outDataI	<=	{{2{AdcData_i[AdcDataWidth-1]}},AdcData_i};
 						outDataQ	<=	AdcData_i;
 						decimDataValIR	<=	OscWind_i;
 						decimDataValQR	<=	OscWind_i;
 					end
 			3'd1:	begin
-						outDataI	<=	decimDataI[maxWidthForR1-:16];
-						outDataQ	<=	decimDataQ[maxWidthForR1-:16];
+						outDataI	<=	{{2{AdcData_i[AdcDataWidth-1]}},AdcData_i};
+						// outDataI	<=	AdcData_i;
 						decimDataValIR	<=	OscWind_i;
 						decimDataValQR	<=	OscWind_i;
 					end
 			3'd2:	begin
 						outDataI	<=	decimDataI[maxWidthForR2-:16];
 						outDataQ	<=	decimDataQ[maxWidthForR2-:16];
-						decimDataValIR	<=	decimDataValI;
+						decimDataValIR	<=	1'b1;
 						decimDataValQR	<=	decimDataValQ;
 					end
 			3'd3:	begin

+ 3 - 3
src/src/Sim/DecimFilterWrapperTb.v

@@ -55,7 +55,7 @@ parameter	MaxWidth	=	38;
 initial begin
 	Clk50		=	1'b1;
 	Rst			=	1'b1;
-	decimFactor	=	3'd2;
+	decimFactor	=	3'd1;
 #100;
 	Rst		=	1'b0;
 end	
@@ -153,8 +153,8 @@ DecimFilter
 	.IfFtwL_i		(24'h51eb85),
 	.IfFtwH_i		(24'h23),
 	
-	.AdcData_i		(singlePulse),
-	// .AdcData_i		(sinAdd),
+	// .AdcData_i		(singlePulse),
+	.AdcData_i		(sinAdd),
 	// .AdcData_i		(adcDataMixedCut),
 	
 	.FilteredAdcDataI_o	(resultI),

+ 0 - 250
src/src/Sim/FilteredData.txt

@@ -1,250 +0,0 @@
-     0
-     0
-     0
-     0
-     2
-    -8
-     5
-    31
-  -107
-   135
-    16
-  -463
-  1120
-  1120
-  -463
-    16
-   135
-  -107
-    31
-     5
-    -8
-     2
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0

+ 0 - 500
src/src/Sim/InputSignal.txt

@@ -1,500 +0,0 @@
-     0
-     0
-     0
-     0
-     0
-  8191
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0
-     0

+ 62 - 57
src/src/Sim/KapitanovScriptForCicComp.m

@@ -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;
+

+ 14 - 15
src/src/Sim/fir_filter.coe

@@ -1,19 +1,18 @@
 Radix = 10;
 Coefficient_Width = 16;
 Coefdata =
--27,
-615,
-1015,
--1512,
--5803,
--2223,
-14818,
+-137,
+282,
+-770,
+1889,
+-4162,
+8631,
+-17375,
 32767,
-32767,
-14818,
--2223,
--5803,
--1512,
-1015,
-615,
--27;
+-17375,
+8631,
+-4162,
+1889,
+-770,
+282,
+-137;