From 94ee1b36022caea5fec1b3db37dfa6c9f3ba17b5 Mon Sep 17 00:00:00 2001 From: David Protzman Date: Tue, 26 Apr 2022 21:28:59 -0400 Subject: [PATCH] Updated get_sample_count_of_file to use new function for num of bytes/sample --- .../updated_scripts/get_sample_count_of_file.m | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/matlab/updated_scripts/get_sample_count_of_file.m b/matlab/updated_scripts/get_sample_count_of_file.m index 72690bf..5e74c76 100644 --- a/matlab/updated_scripts/get_sample_count_of_file.m +++ b/matlab/updated_scripts/get_sample_count_of_file.m @@ -1,16 +1,25 @@ -% Get the number of complex 32-bit floating point values in the specified file +% Get the number of complex values in the specified file using the provided sample type % % @param file_path Path to the file that contains complex 32-bit floating point samples +% @param sample_type MATLAB numeric class type for each I and Q value in the file. Ex: 'single', 'int16', 'int8', etc % @return sample_count Number of complex 32-bit floating point samples in the provided input file -function [sample_count] = get_sample_count_of_file(file_path) +function [sample_count] = get_sample_count_of_file(file_path, sample_type) handle = fopen(file_path, "r"); if (handle == 0) error("Could not open input file '%s'"', file_path); end - + + % Get how many bytes are required to make a single I or Q value + bytes_per_sample = get_bytes_per_sample(sample_type); + + % Move to the end of the file fseek(handle, 0, 'eof'); + + % Ask how many bytes into the file the pointer is currently byte_count = ftell(handle); fclose(handle); - sample_count = floor(byte_count / 4 / 2); + % Get the number of complex samples in the file. Flooring to ensure that if there are bytes missing those are not + % counted towards the total number of samples + sample_count = floor(byte_count / bytes_per_sample / 2); end \ No newline at end of file