Explorar o código

Тестовые изменения фильтров.

ChStepan hai 1 ano
pai
achega
cabee0b6c9

+ 1 - 1
src/src/FftDataFiltering/cicFilterTest.v

@@ -72,7 +72,7 @@ generate
 		.DataValid_o	(decimIntDataValid)
 	);
 	
-	for (j=0; j<N+1; j=j+1)	begin: CombFilterGen
+	for (j=0; j<N; j=j+1)	begin: CombFilterGen
 	
 		assign	combInData	[j]	=	(j==0)?decimIntData:combFilteredData[j-1];
 		assign	combDataVal	[j]	=	(j==0)?decimIntDataValid:combFilteredDataVal[j-1];

+ 15 - 8
src/src/FftDataFiltering/decimBlock.v

@@ -58,29 +58,36 @@ always	@(posedge	Clk_i)	begin
 		if	(DataNd_i)	begin
 			if	(decimCnt	==	decimFactor-1)	begin
 				decimCnt	<=	{decimCntWidth{1'b0}};
-				valReg		<=	1'b1;
+				// valReg		<=	DataNd_i;
+				// dataReg		<=	Data_i;
 			end	else	begin
 				decimCnt	<=	decimCnt+7'd1;
-				valReg		<=	1'b0;
+				// valReg		<=	1'b0;
 			end
+			// valReg		<=	DataNd_i;
 		end	else	begin
 			decimCnt	<=	{decimCntWidth{1'b0}};
-			valReg		<=	1'b0;
+			// valReg		<=	1'b0;
 		end
 	end	else	begin
 		decimCnt	<=	{decimCntWidth{1'b0}};
-		valReg		<=	1'b0;
+		// valReg		<=	1'b0;
+		// dataReg	<=	Data_i;
 	end
 end
 	
 always	@(posedge	Clk_i)	begin
 	if	(!Rst_i)	begin
-		if	(decimCnt	==	decimFactor-1)	begin
-			dataReg	<=	Data_i;
-		end	
-		
+		// if	(decimCnt	==	decimFactor-1)	begin
+		if	(decimCnt	==	0)	begin
+			dataReg		<=	Data_i;
+			valReg		<=	DataNd_i;
+		end	else begin
+			valReg		<=	1'b0;
+		end
 	end	else	begin
 		dataReg	<=	0;
+		valReg	<=	1'b0;
 	end
 end
 

+ 31 - 28
src/src/Sim/CicTestMatlab.m

@@ -1,6 +1,6 @@
-m = 2;  % Differential delays in the filter.
-n = 4;  % Filter sections
-r = 1;   % Decimation factor
+m = 1;  % Differential delays in the filter.
+n = 2;  % Filter sections
+r = 2;   % Decimation factor
 x = int16(zeros(160,1)); x(1) = 1;    % Create a 160-point
                                       % impulse signal.
 hm = mfilt.cicdecim(r,m,n); % Expects 16-bit input
@@ -14,30 +14,33 @@ yCorr = double(y);
 
 FilteredDataFft = abs(fft(yCorr));
 FilteredDataFftDb = 20*log10(FilteredDataFft);
-FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
+% FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
 
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-figure('name','In Data Time/Freq', 'Numbertitle', 'off')
-subplot(3,1,1)
-plot(x)
-grid on;
-grid minor;
-title('In Signal')
-xlabel('Time')
-ylabel('Amp')
-
-subplot(3,1,2)
-plot(yCorr)
-grid on;
-grid minor;
-title('Imp Resp')
-xlabel('Time')
-ylabel('Amp')
+hm = mfilt.cicdecim(r,m,n);
+fvtool(hm)
 
-subplot(3,1,3)
-plot(FilteredDataFftDb)
-grid on;
-grid minor;
-title('Filtered Data')
-xlabel('Time')
-ylabel('Amp')
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% figure('name','In Data Time/Freq', 'Numbertitle', 'off')
+% subplot(3,1,1)
+% plot(x)
+% grid on;
+% grid minor;
+% title('In Signal')
+% xlabel('Time')
+% ylabel('Amp')
+% 
+% subplot(3,1,2)
+% plot(yCorr)
+% grid on;
+% grid minor;
+% title('Imp Resp')
+% xlabel('Time')
+% ylabel('Amp')
+% 
+% subplot(3,1,3)
+% plot(FilteredDataFftDb)
+% grid on;
+% grid minor;
+% title('Filtered Data')
+% xlabel('Time')
+% ylabel('Amp')

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

@@ -18,7 +18,7 @@ real	signal;
 reg		[31:0]	tbCnt;
 
 wire 	[31:0] startValue = 32'd10;
-wire	[31:0] pNum = 8;
+wire	[31:0] pNum = 10;
 wire 	[31:0] stopValue = startValue+pNum-1;
 
 // wire	oscWind	=	(tbCnt>=10&tbCnt<=509)?	1'b1:1'b0;
@@ -35,7 +35,7 @@ wire	resultVal;
 wire	impRespVal;
 
 
-// wire	signed	[27:0]	adcDataMixed	=	oscWind?(ncoSin1*ncoSin2):28'd0;
+// wire	signed	[27:0]	adcDataMixed	=	oscWfind?(ncoSin1*ncoSin2):28'd0;
 wire	signed	[27:0]	adcDataMixed	=	(ncoSin1*ncoSin2);
 wire	signed	[13:0]	adcDataMixedCut	=	adcDataMixed[26-:14];
 
@@ -45,13 +45,13 @@ wire	signed	[13:0]	sinAdd	=	(ncoSin1>>>1)+(ncoSin2>>>1);
 
 
 wire	signed	[13:0]	singlePulse	=	(tbCnt==10)?	14'h1fff:14'h0;
-// wire	signed	[13:0]	singlePulse	=	(tbCnt>=4500&tbCnt<=4501)?	14'h1fff:14'h0;
+// wire	signed	[13:0]	singlePulse	=	(tbCnt>=10&tbCnt<=12)?	14'h1fff:14'h0;
 //==========================================================================================
 //clocks gen
 always	#10 Clk50	=	~Clk50;
 
 //==========================================================================================
-parameter	N	=	3;
+parameter	N	=	2;
 parameter	M	=	1;
 
 always	@(posedge	Clk50)	begin
@@ -227,7 +227,7 @@ reg	[31:0]	testCnt;
 wire	[10:0]	test = N*2+N*2+decimFactor;
 wire	[10:0]	test1 = N*2+N*2+decimFactor-1;
 // wire	writeEn	=	(oscWindDelay[N*2+N*2+decimFactor-2]);
-wire	writeEn	=	(tbCnt>= (startValue+(N*2*2)+decimFactor) & tbCnt <= (stopValue+(N*2*2)+decimFactor));
+wire	writeEn	=	(tbCnt>= (startValue+(N*2*2)+decimFactor-6) & tbCnt <= (stopValue+(N*2*2)+decimFactor-6));
 
 always	@(posedge	Clk50)begin
 	if	(!Rst)	begin

+ 3 - 2
src/src/Sim/FilteredData.txt

@@ -1,4 +1,5 @@
           0
           0
-      17336
-      19380
+          0
+          0
+          0

+ 0 - 96
src/src/Sim/ImpResp.asv

@@ -1,96 +0,0 @@
-FormatSpec = '%d';
-
-N = 1;
-R = 2;
-B = 16;
-M = 1;
-
-PointsNum = 500;
-
-Bmax = ceil(log2(((R*M)^N)/R)+B);
-MaxWidthR2 = ceil(log2(((2*M)^N)/2)+B);
-MaxWidthR4 = ceil(log2(((4*M)^N)/4)+B);
-
-K = N*20*log10(M);
-BitGrowth = ceil(2^(K/20));
-Bnew = B+BitGrowth;
-
-x = 1:1:PointsNum;
-xDecim = 1:1:PointsNum/R;
-
-Fc = 3;
-Fs = 50;
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-ReadImpulseRestId = fopen('C:\S5243_FFT_REPO\src\src\Sim\ImpResp.txt','r');
-ImpulseResp = fscanf(ReadImpulseRestId,FormatSpec);
-fclose(ReadImpulseRestId);
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-InDataFft = abs(fft(InDataSignal+randn(size(InDataSignal)))/PointsNum);
-InDataFftDb = 20*log10(InDataFft);
-
-FilteredDataFft = abs(fft(FilteredData+randn(size(FilteredData)))/PointsNum);
-FilteredDataFftDb = 20*log10(FilteredDataFft);
-FilteredDataFftDb = FilteredDataFftDb-max(FilteredDataFftDb);
-
-ImpuseRespFft = abs(fft(ImpulseResp));
-ImpuseRespFftDb = 20*log10(ImpuseRespFft);
-ImpuseRespFftDb = ImpuseRespFftDb-max(ImpuseRespFftDb);
-
-Fband = 0:1/PointsNum*R:1-1/PointsNum*R;
-FbandOrig = 0:1/PointsNum:1-1/PointsNum;
-
-%InDataFftDb = InDataFftDb(1:length(Fband));
-%FilteredDataFftDb = FilteredDataFftDb(1:length(Fband));
-%ImpuseRespFftDb = ImpuseRespFftDb(1:length(Fband));
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-
-subplot(2,1,1)
-plot(ImpulseResp)
-grid on;
-grid minor;
-title('Cic Frequency response')
-xlabel('f (Hz)')
-ylabel('Amp')
-
-subplot(2,1,2)
-plot(ImpuseRespFftDb)
-grid on;
-grid minor;
-title('Cic Frequency response')
-xlabel('f (Hz)')
-ylabel('Amp')
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-

+ 0 - 7
src/src/Sim/ImpResp.m

@@ -19,13 +19,6 @@ ImpuseRespFft = abs(fft(ImpulseResp));
 ImpuseRespFftDb = 20*log10(ImpuseRespFft);
 ImpuseRespFftDb = ImpuseRespFftDb-max(ImpuseRespFftDb);
 
-Fband = 0:1/PointsNum*R:1-1/PointsNum*R;
-FbandOrig = 0:1/PointsNum:1-1/PointsNum;
-
-%InDataFftDb = InDataFftDb(1:length(Fband));
-%FilteredDataFftDb = FilteredDataFftDb(1:length(Fband));
-%ImpuseRespFftDb = ImpuseRespFftDb(1:length(Fband));
-
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
 subplot(2,1,1)

+ 6 - 4
src/src/Sim/ImpResp.txt

@@ -1,7 +1,9 @@
-      24573
-      24573
-       8191
-       8191
+          0
+          0
+          0
+          0
+          0
+          0
           0
           0
           0

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

@@ -6,3 +6,5 @@
   4334
   1023
  -1025
+    -1
+  1023