
file_name = 'Reference_5MHz_Sine_Ch1.bin';
newCSVfilename = 'generated_csv_file.csv';
num_channels = 32;
adc_resolution = 12;

%% Open file
fileID = fopen(file_name);
data = fread(fileID,'uint16');
fclose(fileID);

%% manipulate data
shifted_data = data-2^(adc_resolution-1); % convert to 2s complement by subtracting the midcode (adc_resolution-1):
num_samples = length(shifted_data)/num_channels;
samples = reshape(shifted_data,[num_channels,num_samples]); % Change single column of samples into matrix where each column is a new channel
samples = samples'; % Transpose to match CSV format

%% Save matrix as csv
writematrix(samples,newCSVfilename)

%% Plotting first 100 pts of channel 1
figure;
plot(samples(:,1))
xlim([1  100]);
title('Time-domain Signal');
xlabel('Sample #');
ylabel('Codes');