Changes from mwork PC.
PDP 2025 MPI analysis new focus on database and SQL
This commit is contained in:
85
projects/Messung_Zürich/change_filenames.m
Normal file
85
projects/Messung_Zürich/change_filenames.m
Normal file
@@ -0,0 +1,85 @@
|
||||
%% 1) Read all files in the TR folder
|
||||
pathToTimingRecov = "C:\Users\Silas\Documents\MATLAB\Datensätze\IEF_Polariton_2025\36_IMDD_Kiel\Data\TR_ZIP";
|
||||
trFiles = dir(fullfile(pathToTimingRecov, 'TR_SILAS_*.mat'));
|
||||
|
||||
%% Directory for measurement files (used to extract metadata)
|
||||
pathToMeasurement = "C:\Users\Silas\Documents\MATLAB\Datensätze\IEF_Polariton_2025\36_IMDD_Kiel\Data\20250221";
|
||||
|
||||
%% Initialize lists for different PAM types
|
||||
listPAM2 = {};
|
||||
listPAM4 = {};
|
||||
listPAM6 = {};
|
||||
listPAM8 = {};
|
||||
|
||||
%% Loop over each TR file
|
||||
for k = 1:length(trFiles)
|
||||
% Get current TR file name
|
||||
trFileName = trFiles(k).name;
|
||||
|
||||
% 2) Extract file code from TR file name.
|
||||
% For a filename like "TR_SILAS_20250221T001800.mat" the code is "20250221T001800".
|
||||
filecode = extractBetween(trFileName, 'TR_SILAS_', '.mat');
|
||||
|
||||
% Find corresponding measurement file by code (custom function)
|
||||
measurementFilename = findFileByCode(pathToMeasurement, filecode{1});
|
||||
|
||||
% 3) Extract parameters from the measurement filename using regex.
|
||||
% Expected measurement filename format (example):
|
||||
% "Pmod_-10p000dBm_P_PD_-20p000dBm_..._32GBd_4PAM__1234T5678"
|
||||
tokens = regexp(measurementFilename, ...
|
||||
'Pmod_([-0-9p]+)dBm_P_PD_([-0-9p]+)dBm_.*?_(\d+)GBd_(\d+)PAM__\d+T\d+', ...
|
||||
'tokens');
|
||||
if isempty(tokens)
|
||||
error('Filename format not recognized for measurement file: %s', measurementFilename);
|
||||
end
|
||||
tokens = tokens{1};
|
||||
|
||||
% Convert token strings to numbers
|
||||
config.P_laser = str2double(strrep(tokens{1}, 'p', '.'));
|
||||
config.P_pd = str2double(strrep(tokens{2}, 'p', '.'));
|
||||
config.fsym = str2double(tokens{3}) * 1e9; % Convert from GBd to Hz
|
||||
config.M = str2double(tokens{4});
|
||||
|
||||
% Display loaded metadata
|
||||
fprintf('Loaded measurement file: %s\n', measurementFilename);
|
||||
fprintf('P_laser: %.3f dBm\n', config.P_laser);
|
||||
fprintf('P_pd: %.3f dBm\n', config.P_pd);
|
||||
fprintf('fsym: %.1f GBd\n', config.fsym * 1e-9);
|
||||
fprintf('M: %d\n', config.M);
|
||||
|
||||
% 4) Rename the TR file to include the metadata.
|
||||
% New filename format: TR_SILAS_<code>_Pmod_<P_laser>dBm_P_PD_<P_pd>dBm_<fsym in GBd>GBd_<M>PAM.mat
|
||||
newTRname = sprintf('TR_SILAS_%s_Pmod_%.3fdBm_P_PD_%.3fdBm_%dGBd_%dPAM', ...
|
||||
filecode{1}, config.P_laser, config.P_pd, config.fsym/1e9, config.M);
|
||||
|
||||
newTRname = strrep(newTRname,'.','p');
|
||||
newTRname = [newTRname, '.mat'];
|
||||
movefile(fullfile(pathToTimingRecov, trFileName), fullfile(pathToTimingRecov, newTRname));
|
||||
|
||||
% Append the file code to the corresponding PAM list based on config.M
|
||||
switch config.M
|
||||
case 2
|
||||
listPAM2{end+1} = filecode{1};
|
||||
case 4
|
||||
listPAM4{end+1} = filecode{1};
|
||||
case 6
|
||||
listPAM6{end+1} = filecode{1};
|
||||
case 8
|
||||
listPAM8{end+1} = filecode{1};
|
||||
otherwise
|
||||
warning('Unexpected PAM value %d in file %s', config.M, measurementFilename);
|
||||
end
|
||||
end
|
||||
|
||||
%% Display the lists of file codes for each PAM type
|
||||
disp('List of file codes for PAM2:');
|
||||
disp(listPAM2);
|
||||
|
||||
disp('List of file codes for PAM4:');
|
||||
disp(listPAM4);
|
||||
|
||||
disp('List of file codes for PAM6:');
|
||||
disp(listPAM6);
|
||||
|
||||
disp('List of file codes for PAM8:');
|
||||
disp(listPAM8);
|
||||
Reference in New Issue
Block a user