clc; clear; close all;


fileID = fopen("FDR_two_10M_Ref_10M_DUT.dat"); 
A1 = int32(fread(fileID,'int32','b'));
fclose(fileID);

B1 = swapbytes(reshape(A1,1,[]));
%B1 = (reshape(A1,1,[]));

CC = reshape(B1,4,[]);

LL = 1000;


LEN_OFF = 1;
LEN_OFF_MINUS = 0;

CH1 = CC(4,1:1024*LL);
CH2 = CC(3,1:1024*LL);
CH3 = CC(2,1+LEN_OFF_MINUS:1024*LL+LEN_OFF_MINUS);
CH4 = CC(1,1+LEN_OFF:1024*LL+LEN_OFF);

avg_LEN = 1;
avg = ones(1, avg_LEN)/avg_LEN;

CH1_avg = double(CH1);
CH2_avg = double(CH2);
CH3_avg = double(CH3);
CH4_avg = double(CH4);

CIC_R = 128;
FS = 133000000;
Fs_base = FS/CIC_R;

LEN = length(CH1_avg);
T = LEN/Fs_base;

time = linspace(0,T,length(CH1_avg));

avg_LEN = avg_LEN*2;
tt = time(avg_LEN:end);
C1 = CH1_avg(avg_LEN:end)/(2^32)*Fs_base;
C2 = CH2_avg(avg_LEN:end)/(2^32)*Fs_base;
C3 = CH3_avg(avg_LEN:end)/(2^32)*Fs_base;
C4 = CH4_avg(avg_LEN:end)/(2^32)*Fs_base;

LEN_STA = 20000;
LEN_END = 21000;
C1=C1(LEN_STA:LEN_END);
C2=C2(LEN_STA:LEN_END);
C3=C3(LEN_STA:LEN_END);
C4=C4(LEN_STA:LEN_END);
tt = tt(LEN_STA:LEN_END);

figure('Renderer', 'painters', 'Position', [10 450 900 500]);
subplot(411);
plot(tt,C1,'-m');
legend('CH1');
xlabel('time /S');
axis tight

subplot(412);
plot(tt, C2,'-b');
hold off;
grid on;
xlabel('time /S');
legend('CH2');
axis tight

subplot(413);
plot(tt, C3,'-m');
xlabel('time /S');
legend('CH3');
axis tight

subplot(414);
plot(tt, C4,'-k');
hold off;
grid on;
xlabel('time /S');
legend('CH4');
axis tight
