| classdef us_dataset < handle |
| |
| |
| |
| |
| |
|
|
| |
|
|
| |
| |
| properties (SetAccess = public) |
| name |
| creation_date |
| probe_geometry |
| data |
| c0 |
| initial_time |
| sampling_frequency |
| modulation_frequency |
| PRF |
| angles |
| end |
| |
| |
| properties (SetAccess = protected) |
| samples |
| channels |
| firings |
| frames |
| version |
| end |
| |
| |
| methods (Access = public) |
| |
| function h = us_dataset(input_name) |
| |
| |
| |
| |
| |
| |
| if exist('input_name') h.name = input_name; end |
| h.creation_date = sprintf('%d/%02d/%d %02d:%02d:%02.2f',clock); |
| h.version = 'v1.96'; |
| h.PRF = 100; |
| |
| end |
| |
| end |
|
|
| |
| methods |
| |
| |
| function set.name(h,input_name) |
| assert(isstr(input_name), 'Wrong format of the us_dataset name. It should be a string.'); |
| h.name = input_name; |
| end |
| |
| |
| function set.creation_date(h,input_date) |
| assert(isstr(input_date), 'Wrong format of the us_dataset creation date. It should be a string.'); |
| h.creation_date = input_date; |
| end |
| |
| function set.probe_geometry(h,input_geometry) |
| assert(ndims(input_geometry)==2&&size(input_geometry,2)==3&&isnumeric(input_geometry), 'Wrong format of the probe geometry. It should be a numeric three column matrix [x, y, z] in (m)'); |
| h.probe_geometry = input_geometry; |
| end |
| |
| function set.c0(h,input_c0) |
| assert(numel(input_c0)==1&&isnumeric(input_c0), 'Wrong format of the reference speed of sound c0. It should be a numeric scalar in (m/s)'); |
| h.c0 = input_c0; |
| end |
| |
| function set.angles(h,input_angles) |
| assert(size(input_angles,1)==numel(input_angles)&&isnumeric(input_angles), 'Wrong format of the angle vector. It should be a numeric column vector in (rad)'); |
| h.angles = input_angles; |
| end |
| |
| function set.initial_time(h,input_t0) |
| assert(numel(input_t0)==1&&isnumeric(input_t0), 'Wrong format of the initial time. It should be a numeric scalar in (s)'); |
| h.initial_time = input_t0; |
| end |
| |
| function set.sampling_frequency(h,input_Fs) |
| assert(numel(input_Fs)==1&&isnumeric(input_Fs), 'Wrong format of the sampling frequency. It should be a numeric scalar in (Hz)'); |
| h.sampling_frequency=input_Fs; |
| end |
| |
| function set.PRF(h,input_PRF) |
| assert(numel(input_PRF)==1&&isnumeric(input_PRF), 'Wrong format of the pulse repetition frequency. It should be a numeric scalar in (Hz)'); |
| h.PRF = input_PRF; |
| end |
| |
| function set.modulation_frequency(h,input_Fd) |
| assert(numel(input_Fd)==1&&isnumeric(input_Fd), 'Wrong format of the modulation frequency. It should be a numeric scalar in (Hz)'); |
| h.modulation_frequency = input_Fd; |
| end |
| |
| function set.data(h,input_data) |
| assert(isnumeric(input_data)&&ndims(input_data)<5, 'Wrong format of the data. It should be a numeric array of dimensions [samples, channels, firings, frames].'); |
| |
| h.samples = size(input_data,1); |
| h.channels = size(input_data,2); |
| h.firings = size(input_data,3); |
| h.frames = size(input_data,4); |
| |
| h.data = input_data; |
| |
| if(isreal(h.data)&(h.modulation_frequency~=0)) |
| warning('The inserted data is real (RF format), but the modulation frequency is not zero.'); |
| end |
| if(~isreal(h.data)&(h.modulation_frequency==0)) |
| warning('The inserted data is complex (IQ format), but the modulation frequency is zero.'); |
| end |
| if(h.channels~=size(h.probe_geometry,1)) |
| warning(sprintf('The number of channels in the inserted data (%d) does not match the size of the probe geometry matrix (%d).',h.channels, size(h.probe_geometry,1))); |
| end |
| if(h.firings~=size(h.angles,1)) |
| warning(sprintf('The number of firings in the inserted data (%d) does not match the size of the angle vector (%d).',h.firings, size(h.angles,1))); |
| end |
| end |
| |
| end |
| |
| |
| methods (Access = public) |
| |
| function write_file_hdf5(h,filename) |
| |
| |
| |
| |
| |
| |
| |
| |
| attr_details.Name = 'version'; |
| attr_details.AttachedTo = '/'; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename, attr_details, 'v.0.0.40'); |
| |
| |
| try |
| h5info(filename,'/US') |
| catch |
| fid = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| gid = H5G.create(fid,'US','H5P_DEFAULT','H5P_DEFAULT','H5P_DEFAULT'); |
| H5G.close(gid); |
| H5F.close(fid); |
| end |
| |
| |
| group_name = 'US_DATASET0000'; |
| fid = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| gid = H5G.open(fid,'/US'); |
| s_gid = H5G.create(gid,group_name,'H5P_DEFAULT','H5P_DEFAULT','H5P_DEFAULT'); |
| H5G.close(s_gid); |
| H5G.close(gid); |
| H5F.close(fid); |
| location = ['/US/' group_name]; |
| |
| |
| |
| file = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| filetype = H5T.enum_create('H5T_NATIVE_INT'); |
| H5T.enum_insert(filetype,'US', 0); |
| H5T.enum_insert(filetype,'SR', 1); |
| gid = H5G.open(file,location); |
| space = H5S.create_simple(1,1,[]); |
| attr = H5A.create (gid,'type',filetype,space,'H5P_DEFAULT'); |
| H5A.write(attr, filetype, uint32(0)); |
| H5A.close(attr); |
| H5G.close(gid); |
| H5S.close(space); |
| H5T.close(filetype); |
| H5F.close(file); |
| |
| |
| file = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| filetype = H5T.enum_create('H5T_NATIVE_INT'); |
| H5T.enum_insert (filetype,'STA',0); |
| H5T.enum_insert (filetype,'CPW',1); |
| H5T.enum_insert (filetype,'VS',2); |
| H5T.enum_insert (filetype,'BS',3); |
| gid = H5G.open(file,location); |
| space = H5S.create_simple (1,1,[]); |
| attr = H5A.create (gid,'subtype',filetype,space,'H5P_DEFAULT'); |
| H5A.write(attr,filetype,uint32(1)); |
| |
| |
| file = H5F.open(filename,'H5F_ACC_RDWR','H5P_DEFAULT'); |
| filetype = H5T.enum_create('H5T_NATIVE_INT'); |
| H5T.enum_insert(filetype,'RF',0); |
| H5T.enum_insert(filetype,'IQ',1); |
| gid = H5G.open(file,location); |
| space = H5S.create_simple(1,1,[]); |
|
|
| attr = H5A.create(gid,'signal_format',filetype,space,'H5P_DEFAULT'); |
| if(h.modulation_frequency>0) |
| H5A.write(attr,filetype,uint32(1)); |
| else |
| H5A.write(attr,filetype,uint32(0)); |
| end |
| H5A.close(attr); |
| H5G.close(gid); |
| H5S.close(space); |
| H5T.close(filetype); |
| H5F.close(file); |
|
|
| |
| attr_details.Name = 'name'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename,attr_details,h.name,'WriteMode','append'); |
|
|
| |
| attr_details.Name = 'version'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename,attr_details,h.version,'WriteMode','append'); |
| |
| |
| attr_details.Name = 'creation_date'; |
| attr_details.AttachedTo = location; |
| attr_details.AttachType = 'group'; |
| hdf5write(filename,attr_details,h.creation_date,'WriteMode','append'); |
|
|
| |
| |
| |
| dset_details.Location = location; |
| dset_details.Name = 'sound_speed'; |
| hdf5write(filename, dset_details, single(h.c0), 'WriteMode', 'append'); |
| |
| |
| dset_details.Location = location; |
| dset_details.Name = 'initial_time'; |
| hdf5write(filename, dset_details, single(h.initial_time), 'WriteMode', 'append'); |
|
|
| |
| dset_details.Location = location; |
| dset_details.Name = 'sampling_frequency'; |
| hdf5write(filename, dset_details, single(h.sampling_frequency), 'WriteMode', 'append'); |
|
|
| |
| dset_details.Location = location; |
| dset_details.Name = 'PRF'; |
| hdf5write(filename, dset_details, single(h.PRF), 'WriteMode', 'append'); |
| |
| |
| dset_details.Location = location; |
| dset_details.Name = 'modulation_frequency'; |
| if(h.modulation_frequency>0) |
| hdf5write(filename, dset_details, single(h.modulation_frequency), 'WriteMode', 'append'); |
| else |
| hdf5write(filename, dset_details, single(0), 'WriteMode', 'append'); |
| end |
|
|
| |
| dset_details.Location = location; |
| dset_details.Name = 'probe_geometry'; |
| hdf5write(filename, dset_details, single(h.probe_geometry), 'WriteMode', 'append'); |
| |
| |
| dset_details.Location = location; |
| dset_details.Name = 'angles'; |
| hdf5write(filename, dset_details, single(h.angles), 'WriteMode', 'append'); |
| |
| |
| dset_details.Location = [location '/data']; |
| dset_details.Name = 'real'; |
| hdf5write(filename, dset_details, single(real(h.data)), 'WriteMode', 'append'); |
| dset_details.Name = 'imag'; |
| hdf5write(filename, dset_details, single(imag(h.data)), 'WriteMode', 'append'); |
| |
| end |
| |
|
|
| function read_file(h,filename) |
| |
| |
| |
| |
| |
| |
| [pathstr, name, ext] = fileparts(filename); |
| switch ext |
| case '.mat' |
| h.read_file_mat(filename); |
| case '.hdf5' |
| h.read_file_hdf5(filename); |
| otherwise |
| error('Unknown signal format!'); |
| end |
| |
| end |
| |
| |
| function write_file(h,filename) |
| |
| |
| |
| |
| |
| |
| [pathstr, name, ext] = fileparts(filename); |
| switch ext |
| case '.mat' |
| h.write_file_mat(filename); |
| case '.hdf5' |
| h.write_file_hdf5(filename); |
| otherwise |
| error('Unknown signal format!'); |
| end |
| |
| end |
| |
| |
| function read_file_hdf5(h,filename) |
|
|
| |
| |
| |
| |
| |
| |
| info = h5info(filename,'/US'); |
|
|
| |
| for n=1:length(info.Groups) |
| location=info.Groups(n).Name; |
| dstype=h5readatt(filename,location,'type'); |
| if strcmp(dstype,'US') |
| subtype=h5readatt(filename,location,'subtype'); |
| if strcmp(subtype{1},'CPW') |
|
|
| |
| dataset_subtype=h5readatt(filename,location,'subtype'); |
| assert(strcmp(dataset_subtype,'CPW'),'Only CPWC us_dataset are supported!'); |
| |
| |
| signal_format=h5readatt(filename,location,'signal_format'); |
| |
| |
| h.modulation_frequency=h5read(filename,[location '/modulation_frequency']); |
|
|
| |
| switch(signal_format{1}) |
| case 'RF' |
| assert(h.modulation_frequency==0,'RF dataset cannot have a modulation frequency'); |
| case 'IQ' |
| assert(h.modulation_frequency>0,'IQ dataset cannot have a null modulation frequency'); |
| otherwise |
| error('Unknown signal format!'); |
| end |
|
|
| |
| |
| a = h5readatt(filename,location,'name'); h.name=a{1}(1:end-1); |
|
|
| |
| a = h5readatt(filename,location,'creation_date'); h.creation_date=a{1}(1:end-1); |
| |
| |
| a = h5readatt(filename,location,'version'); h.version=a{1}(1:end-1); |
|
|
| |
| |
| h.c0 = h5read(filename,[location '/sound_speed']); |
|
|
| |
| h.initial_time = h5read(filename,[location '/initial_time']); |
|
|
| |
| h.sampling_frequency = h5read(filename,[location '/sampling_frequency']); |
|
|
| |
| h.PRF = h5read(filename,[location '/PRF']); |
|
|
| |
| h.probe_geometry = h5read(filename,[location '/probe_geometry']); |
|
|
| |
| h.angles = h5read(filename,[location '/angles']); |
| |
| |
| real_part = h5read(filename,[location '/data/real']); |
| imag_part = h5read(filename,[location '/data/imag']); |
| h.data = real_part+1i*imag_part; |
| end |
| end |
| end |
| end |
| |
| function read_file_mat(h,filename) |
|
|
| |
| |
| |
| |
|
|
| |
| load(filename); |
| |
| |
| signal_format = PARAM.signal_format; |
|
|
| |
| h.modulation_frequency = PARAM.modulation_frequency; |
|
|
| |
| switch(signal_format) |
| case 'RF' |
| assert(h.modulation_frequency==0,'RF dataset cannot have a modulation frequency'); |
| case 'IQ' |
| assert(h.modulation_frequency>0,'IQ dataset cannot have a null modulation frequency'); |
| otherwise |
| error('Unknown signal format!'); |
| end |
|
|
| |
| |
| h.name = PARAM.name; |
|
|
| |
| h.creation_date = PARAM.creation_date; |
|
|
| |
| h.version = PARAM.version; |
|
|
| |
| |
| h.c0 = PARAM.c0; |
|
|
| |
| h.initial_time = PARAM.initial_time; |
|
|
| |
| h.sampling_frequency = PARAM.sampling_frequency; |
|
|
| |
| h.PRF = PARAM.PRF; |
|
|
| |
| h.probe_geometry = PARAM.probe_geometry; |
|
|
| |
| h.angles = PARAM.angles; |
|
|
| |
| real_part = PARAM.real; |
| imag_part = PARAM.imag; |
| h.data = real_part+1i*imag_part; |
| |
| end |
| |
| |
| function write_file_mat(h,filename) |
|
|
| |
| |
| |
| |
| |
|
|
| |
| if(h.modulation_frequency>0) |
| PARAM.signal_format = 'IQ'; |
| else |
| PARAM.signal_format = 'RF'; |
| end |
|
|
| |
| PARAM.name = h.name; |
|
|
| |
| PARAM.version = h.version; |
|
|
| |
| PARAM.creation_date = h.creation_date; |
|
|
|
|
| |
| |
| |
| PARAM.c0 = single(h.c0); |
| |
| |
| PARAM.initial_time = single(h.initial_time); |
| |
| |
| PARAM.sampling_frequency = single(h.sampling_frequency); |
| |
| |
| PARAM.PRF = single(h.PRF); |
|
|
| |
| if(h.modulation_frequency>0) |
| PARAM.modulation_frequency = single(h.modulation_frequency); |
| else |
| PARAM.modulation_frequency = single(0); |
| end |
|
|
| |
| PARAM.probe_geometry = single(h.probe_geometry); |
|
|
| |
| PARAM.angles = single(h.angles); |
|
|
| |
| PARAM.real = single(real(h.data)); |
| PARAM.imag = single(imag(h.data)); |
|
|
| save(filename,'PARAM'); |
| |
| end |
| |
| end |
| |
| end |
|
|