Added lines to generate ramps from the FS without the unwanted resonances between 1.3 G and 2.7 G

This commit is contained in:
Karthik 2025-06-24 02:39:55 +02:00
parent 6cc4b47709
commit dce4a0f067

View File

@ -40,9 +40,9 @@ grid on;
set(gca, 'FontSize', 14); set(gca, 'FontSize', 14);
% Visualize full resonance curve and selected window % Visualize full resonance curve and selected window
[B_full, a_full] = extractBetweenResonances(FR_choice, ABKG_choice, ResonanceRange); [B_full, a_full] = extractBetweenResonances(FR_choice, ABKG_choice, ResonanceRange);
[B_curve, a_curve] = fullResonanceCurve(FR_choice, ABKG_choice, ResonanceRange); [B_curve, a_curve] = fullResonanceCurve(FR_choice, ABKG_choice, ResonanceRange);
[B_all, a_all] = getFullFeschbachSpectrum(FR_choice, ABKG_choice); [B_all, a_all] = getFullFeschbachSpectrum(FR_choice, ABKG_choice);
figure(2); figure(2);
clf clf
@ -66,6 +66,13 @@ set(gca, 'FontSize', 14)
grid on; grid on;
%% Isolate from spectrum manually %% Isolate from spectrum manually
FR_choice = 1;
ABKG_choice = 1;
a_start = 124; % initial scattering length (a_0)
a_end = 117; % final scattering length (a_0)
T = 0.010; % ramp duration (s)
Nt = 15000; % number of time points
ResonanceRange = [1.2, 2.6];
% Get the full spectrum % Get the full spectrum
[B, a_s] = getFullFeschbachSpectrum(1, 2); % Using new FR params and middle a_bkg [B, a_s] = getFullFeschbachSpectrum(1, 2); % Using new FR params and middle a_bkg
@ -90,11 +97,29 @@ for res = resonances_to_mask
end end
% Create masked version % Create masked version
B_masked = B_plot(keep_mask); B_masked = B_plot(keep_mask);
a_s_masked = a_s_plot(keep_mask); a_s_masked = a_s_plot(keep_mask);
% Interpolate over the masked regions % Interpolate over the masked regions
a_s_interp = interp1(B_masked, a_s_masked, B_plot, 'pchip'); a_s_interp = interp1(B_masked, a_s_masked, B_plot, 'pchip');
% --- Find the remaining resonances (peaks) in the interpolated data ---
% Use findpeaks to detect peaks (adjust MinPeakProminence as needed)
[peaks, locs] = findpeaks(abs(a_s_interp), 'MinPeakProminence', 20); % Tune this!
remaining_resonances = B_plot(locs); % Positions of remaining resonances
% --- Select the two resonances of interest (1.3G and 2.59G) ---
% If automatic detection fails, manually define them:
target_resonances = [1.3, 2.59]; % Manually specified (adjust as needed)
% OR use the closest detected resonances:
% target_resonances = remaining_resonances(abs(remaining_resonances - 1.3) < 0.2 & abs(remaining_resonances - 2.59) < 0.2);
% --- Extract the curve BETWEEN these two resonances ---
res1 = min(target_resonances); % Lower resonance (1.3G)
res2 = max(target_resonances); % Upper resonance (2.59G)
between_mask = (B_plot > res1) & (B_plot < res2); % No masking here, since resonances are already removed
B_between = B_plot(between_mask);
a_s_between = a_s_interp(between_mask);
% Plotting % Plotting
figure(3); figure(3);
@ -122,6 +147,45 @@ legend('Location', 'best');
grid on; grid on;
hold off; hold off;
% --- Plotting ---
figure(4);
hold on;
% Plot the interpolated spectrum (without 2.174G and 2.336G)
plot(B_plot, a_s_interp, 'k-', 'LineWidth', 1, 'DisplayName', 'Interpolated spectrum');
% Highlight the region between 1.3G and 2.59G
plot(B_between, a_s_between, 'm-', 'LineWidth', 2, 'DisplayName', 'Between 1.3G and 2.59G');
% Formatting
xlim(x_limits);
ylim([0, 150]);
xlabel('Magnetic Field (G)');
ylabel('Scattering Length (a_0)');
title('Interpolated Spectrum: Region Between 1.3G and 2.59G');
legend('Location', 'best');
grid on;
hold off;
% Generate the ramp
[t, B_ramp, a_check] = generateLinearBRamp(B_between, a_s_between, a_start, a_end, T, Nt);
% Plot results
figure;
subplot(2,1,1);
plot(t, B_ramp, 'b');
xlabel('Time (s)');
ylabel('B Field (G)');
title('Generated B-Field Ramp');
grid on;
subplot(2,1,2);
plot(t, a_check, 'r');
xlabel('Time (s)');
ylabel('a_s (a_0)');
title('Achieved Scattering Length');
grid on;
%% Helper functions %% Helper functions
function [t, B_ramp, a_check] = generateSmoothBRamp(FR_choice, ABKG_choice, a_start, a_end, selectedResRange, T, Nt, opts) function [t, B_ramp, a_check] = generateSmoothBRamp(FR_choice, ABKG_choice, a_start, a_end, selectedResRange, T, Nt, opts)
% Time array % Time array
@ -340,3 +404,36 @@ function [B, a_s] = getFullFeschbachSpectrum(FR_choice, ABKG_choice)
a_s = a_s .* (1 - resonancewB(j) ./ (B - resonanceB(j))); a_s = a_s .* (1 - resonancewB(j) ./ (B - resonanceB(j)));
end end
end end
function [t, B_ramp, a_check] = generateLinearBRamp(B_between, a_s_between, a_start, a_end, T, Nt)
% Generates a B-field ramp (B_ramp) to produce a linear a_s ramp from a_start to a_end.
% Uses precomputed LUT: B_between (magnetic field) and a_s_between (scattering length).
%
% Inputs:
% B_between - Magnetic field values (G) between resonances [vector]
% a_s_between - Corresponding scattering lengths (a_0) [vector]
% a_start, a_end - Target scattering length range (a_0)
% T - Total ramp time (s)
% Nt - Number of time steps
%
% Outputs:
% t - Time vector (s)
% B_ramp - Generated B-field ramp (G)
% a_check - Verified a_s(t) using interpolation (a_0)
% --- 1. Time vector ---
t = linspace(0, T, Nt);
% --- 2. Ensure LUT is sorted and unique ---
[a_s_sorted, sort_idx] = unique(a_s_between); % Remove duplicates and sort
B_sorted = B_between(sort_idx);
% --- 3. Generate target linear a_s ramp ---
a_target = linspace(a_start, a_end, Nt);
% --- 4. Interpolate B(t) from a_s -> B ---
B_ramp = interp1(a_s_sorted, B_sorted, a_target, 'pchip', 'extrap');
% --- 5. Verify a_s(t) by re-interpolating ---
a_check = interp1(B_sorted, a_s_sorted, B_ramp, 'pchip');
end