FormatSpec = '%d';

N = 4;
R = 4;
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;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ReadInDataId = fopen('C:/S5243_FFT_REPO/src/src/Sim/InputSignal.txt','r');
InDataSignal = fscanf(ReadInDataId,FormatSpec);
fclose(ReadInDataId);

ReadFilteredDataId = fopen('C:/S5243_FFT_REPO/src/src/Sim/FilteredData.txt','r');
FilteredData = fscanf(ReadFilteredDataId,FormatSpec);
fclose(ReadFilteredDataId);

ReadImpulseRestId = fopen('C:\S5243_FFT_REPO\src\src\Sim\ImpResp.txt','r');
ImpulseResp = fscanf(ReadImpulseRestId,FormatSpec);
fclose(ReadImpulseRestId);

ReadFilterCoefsId = fopen('C:\S5243_FFT_REPO\src\src\Sim\CorrFilterCoefs.txt','r');
FilterCoefs = fscanf(ReadFilterCoefsId,FormatSpec);
fclose(ReadFilterCoefsId);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

InDataFft = abs(fft(InDataSignal+randn(size(InDataSignal)))/PointsNum);
InDataFftDb = 20*log10(InDataFft);

FilteredDataFft = abs(fft(FilteredData+randn(size(FilteredData)))/PointsNum);
% FilteredDataFft = abs(fft(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')






























