|
1 | 1 | function [NMRdata] = getNMRdata(Folder1r1iprocs)
|
2 | 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
3 |
| -% Copyright to Dr. Panteleimon G. Takis, 2022 % |
| 3 | +% Copyright to Dr. Panteleimon G. Takis, 2019 % |
4 | 4 | % %
|
5 | 5 | % National Phenome Centre and Imperial Clinical Phenotyping Centre, %
|
6 | 6 | % Department of Metabolism, Digestion and Reproduction, IRDB Building, %
|
7 | 7 | % Imperial College London, Hammersmith Campus, %
|
8 | 8 | % London, W12 0NN, United Kingdom %
|
9 |
| -% % |
10 |
| -% This program is distributed in the hope that it will be useful, % |
11 |
| -% but WITHOUT ANY WARRANTY; without even the implied warranty of % |
12 |
| -% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % |
13 |
| -% GNU General Public License for more details. % |
14 |
| -% % |
15 |
| -% You should have received a copy of the GNU General Public License % |
16 |
| -% along with this program. If not, see <https://www.gnu.org/licenses/>.% |
17 |
| -% % |
18 |
| -% Email: p.takis@imperial.ac.uk % |
19 | 9 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
20 | 10 | %
|
21 | 11 | % Reading the real and inaginary part of processed 1D NMR spectra:
|
|
24 | 14 | % Folder1r1iprocs: The NMR folder containing the '1r', '1i', 'procs' files
|
25 | 15 | % for each spectrum.
|
26 | 16 | %
|
27 |
| -% Outputs |
28 |
| -% NMRdata: Structure containing PPM vector (NMRdata.XAxis), |
29 |
| -% Intensity Real (NMRdata.Data) and |
30 |
| -% Intensity Imaginary data vectors (NMRdata.IData) |
31 |
| - |
32 |
| -% |
33 |
| -% Last Updated: 12/01/2022 |
| 17 | +% Last Updated: 21/02/2023 |
34 | 18 | %
|
35 | 19 | % Algorithm contains also adapted parts from rbnmr.m function:
|
36 | 20 | %
|
|
39 | 23 | %
|
40 | 24 |
|
41 | 25 | [NMRdata,Procs,ACQUS,filepath2] = readNMR_real_imag(Folder1r1iprocs);
|
42 |
| -try |
| 26 | +SM_temp = gradient(NMRdata.IData',NMRdata.XAxis'); |
| 27 | +[~,ii] = find(NMRdata.XAxis' > 2 & NMRdata.XAxis' < 4); |
| 28 | + |
| 29 | +SM_temp_test = SM_temp(1,ii); |
| 30 | +SM_temp_test_MAX = max(SM_temp_test); |
| 31 | +SM_temp_test_MIN_abs = abs(min(SM_temp_test)); |
| 32 | +if SM_temp_test_MIN_abs > SM_temp_test_MAX |
| 33 | + NMRdata.IData = -1*NMRdata.IData; |
| 34 | + Check_phase = 1; |
| 35 | +else |
| 36 | + Check_phase = 0; |
| 37 | +end |
| 38 | + |
| 39 | +try |
| 40 | +% try |
43 | 41 | fa = fopen(fullfile(filepath2,'fid'),'r');
|
44 |
| - [fid] = fread(fa,'int32','l'); |
| 42 | + switch ACQUS.BYTORDA |
| 43 | + case 0 |
| 44 | + read_bytes='l'; |
| 45 | + case 1 |
| 46 | + read_bytes='b'; |
| 47 | + end |
| 48 | + switch ACQUS.DTYPA |
| 49 | + case 0 |
| 50 | + precision='int32'; |
| 51 | + case 1 %double |
| 52 | + precision='double'; |
| 53 | + case 2 |
| 54 | + precision='double'; |
| 55 | + end |
| 56 | + |
| 57 | + [fid] = fread(fa,precision,read_bytes); |
45 | 58 | fclose(fa);
|
46 | 59 | fidreal = fid(1:2:length(fid)).*(2^(Procs.NC_proc));
|
47 | 60 | fidimag = fid(2:2:length(fid)).*(2^(Procs.NC_proc));
|
|
60 | 73 | ImagD = -1*(flipud(imag(ImagS)));
|
61 | 74 | ImagD = (ImagD/(2^-Procs.NC_proc));%(1^Procs.NC_proc);
|
62 | 75 | REAL = (flipud(real(ImagS)))/(2^-Procs.NC_proc);
|
63 |
| - IMAG = ImagD; |
64 |
| - |
| 76 | + if Check_phase == 1 |
| 77 | + IMAG = -ImagD; |
| 78 | + else |
| 79 | + IMAG = ImagD; |
| 80 | + end |
65 | 81 | [i,~] = find(NMRdata.XAxis > 1 & NMRdata.XAxis < 5);
|
66 | 82 | TEMP_RE = REAL(i,:);
|
67 | 83 | TEMP_NMRdata = NMRdata.Data(i,:);
|
68 | 84 | TEMP_IMAG = IMAG(i,:);
|
69 | 85 | TEMP_NMRidata = NMRdata.IData(i,:);
|
70 |
| - |
71 | 86 | [j,~] = find(TEMP_RE == 0);
|
72 | 87 | [q,~] = find(TEMP_NMRdata == 0);
|
73 | 88 | [u,~] = find(TEMP_NMRidata == 0);
|
|
86 | 101 | MM_IM = mean(AAAA_IM);
|
87 | 102 | %MM_IM
|
88 | 103 | if MM_R == MM_IM
|
89 |
| - FAC = 1; |
90 | 104 | else
|
91 |
| - FAC = MM_R/MM_IM; |
92 |
| - NMRdata.IData = NMRdata.IData/FAC; |
| 105 | + NMRdata.IData = NMRdata.IData/(MM_R/MM_IM); |
93 | 106 | end
|
94 | 107 | Procs.NC_proc = 0;
|
95 |
| - NMRdata.FAC = FAC; |
96 | 108 | catch
|
97 | 109 | clearvars NMRdata
|
98 | 110 | [NMRdata,~,~,~] = readNMR_real_imag(Folder1r1iprocs);
|
99 |
| - NMRdata.FAC = 1; |
100 | 111 | end
|
101 | 112 |
|
102 | 113 | end
|
|
0 commit comments