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');
.