% Gaussian Fourier self-deconvolution function by ChatGPT4o Prompt: Write a
% Matlab function that peforms Fourier self-deconvolution as a means for
% sharpening (narrowing) the width of signal peaks in x,y, by computing the
% Fourier transform of the original signal, dividing that by the Fourier
% transform of a zero-centered Gaussian function of width
% deconvolution_width, performing an inverse Fourier transform on the
% result, and applies a smoothing function of width smoothing_width to the
% deconvoluted result.

function y_deconvoluted = FSDChatGPT(x, y, deconvolution_width, smoothing_width)
    % Ensure y is a column vector
    y = y(:);

    % Compute the Fourier transform of the signal
    Y = fftshift(fft(y));
    
    % Generate the narrower Gaussian kernel for deconvolution
    dx = x(2) - x(1); % Sampling interval
    n = length(x);
    f = (-n/2:n/2-1)' / (n * dx); % Frequency axis
    sigma_kernel = deconvolution_width / (2 * sqrt(2 * log(2))); % Kernel standard deviation
    K = exp(-(2 * pi * sigma_kernel * f).^2); % Fourier transform of the Gaussian kernel

    % Perform deconvolution in the frequency domain
    Y_deconvoluted = Y ./ (K + 1e-6); % Add small value to avoid division by zero
    y_deconvoluted = real(ifft(ifftshift(Y_deconvoluted))); % Inverse Fourier transform

    % Apply smoothing to reduce noise
    y_deconvoluted = smooth(y_deconvoluted, smoothing_width);
    
    % Ensure the output is the same size as x
    y_deconvoluted = y_deconvoluted(:).'; % Convert to row vector for compatibility
end