Apply apodization to NMR spectra
19 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I want to apply an apodization to a spectra I have. To do so, I want to use an exponential function of 1Hz. I do not have many information about the spectra, only the vector of ppm values and another vector for the intensities.
I have been trying to obtain results, but I cannot make it work correctly. I attach the spectra I have in a csv file. This is my current code:
[filename, filepath] = uigetfile('*.csv', 'Select .csv file');
fullFilePath = fullfile(filepath, filename);
if filename ~= 0
% Read the data from the selected file
T = readtable(fullFilePath);
%Separate into the common component(X) and the actual spectrograms (Y)
X = table2array(T(:,1));
Y = table2array(T(:,2));
[~, max_index] = max(Y);
shift = 172 - X(max_index);
X = X + shift;
plot(X, Y)
xlim([160, 190])
set(gca, 'XDir', 'reverse');
end
SpectralSize = length(Y);
AcquiredSize = SpectralSize/2;
LowestFq = min(Y);
%% Baseline Correction:
order = 3;
baselineCoefficients = polyfit(X, Y, order);
baseline = polyval(baselineCoefficients, X);
correctedY = Y - baseline;
plot(X, correctedY)
xlim([160, 190])
set(gca, 'XDir', 'reverse');
%% Apodization:
frequencies = flipud(X);
apodizationFunction = exp(-pi * frequencies * 1);
apodized_spectrum = ifft(fftshift(fft(correctedY)) .* apodizationFunction);
Could someone help me with this? I am not very familiar ith this type of data. Thank you!
0 comentarios
Respuestas (1)
Star Strider
el 18 de Jun. de 2023
I am not certain what you want to do. (I had to look up ‘Apodization’ and discovered that in the context of Fourier transforms, it means windowing.) With that information (and being somewhat familiar with windowed Fourier transforms), I changed the ‘apodized_spectrum’ calculation to:
apodized_spectrum = ifft(fftshift(fft(correctedY .* apodizationFunction)));
changing the order of operations so that the window function is applied to the argument vector before performing the Fourier transform. I also plotted the ‘apodizationFunction’, however it does not appear to be correct to me, in that is should probably be symmetrical. I believe that the calculation is now correct, however it may be necessary to revise the apodization (windowing) function so it matches what you want to do with the fft calculation (that is not obvious to me).
The revised code with additional plots —
% [filename, filepath] = uigetfile('*.csv', 'Select .csv file');
% fullFilePath = fullfile(filepath, filename);
fullFilePath = 'FileTrialsSingleSpectra.csv';
% if filename ~= 0
% Read the data from the selected file
T = readtable(fullFilePath);
%Separate into the common component(X) and the actual spectrograms (Y)
X = table2array(T(:,1));
Y = table2array(T(:,2));
[~, max_index] = max(Y);
shift = 172 - X(max_index);
X = X + shift;
plot(X, Y)
xlim([160, 190])
set(gca, 'XDir', 'reverse');
% end
SpectralSize = length(Y);
AcquiredSize = SpectralSize/2;
LowestFq = min(Y);
%% Baseline Correction:
order = 3;
baselineCoefficients = polyfit(X, Y, order);
baseline = polyval(baselineCoefficients, X);
correctedY = Y - baseline;
plot(X, correctedY)
xlim([160, 190])
set(gca, 'XDir', 'reverse');
%% Apodization:
frequencies = flipud(X);
apodizationFunction = exp(-pi * frequencies * 1);
% apodized_spectrum = ifft(fftshift(fft(correctedY)) .* apodizationFunction);
apodized_spectrum = ifft(fftshift(fft(correctedY .* apodizationFunction)));
Sz_a_s = size(apodized_spectrum)
Sz_a_f = size(apodizationFunction)
figure
plot(frequencies, apodizationFunction)
grid
xlabel('Frequency')
ylabel('Function Value')
title('Apodization Function')
figure
plot(X, abs(apodized_spectrum))
xlim([160, 190])
set(gca, 'XDir', 'reverse');
.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!