function [y,swiftT]=swiftfunccycle100ms(swiftlength,startfreq,endfreq,nothstart,nothend,datalength,notch2start,nothch2end)
fstart=0;
swiftlength=100e-3;
startfreq=40e3; %Hz
endfreq=200e3; %Hz
%%
% secular_freq=133800;
% swiftlength_1=6e-3;
% factor=swiftlength/swiftlength_1;
% delta=200;
% delta_1=delta*factor;
% half_delta=delta_1/2;
% startfreq=secular_freq-half_delta;
% endfreq=secular_freq+half_delta;
%%
nothstart=133000; %Hz
nothend=134600; %Hz
datalength=1e5;
notch2start=nothstart; %Hz
nothch2end=nothend; %Hz
fend=10^6; %Hz
stimeStep=3e-8;
Stimelength=swiftlength;
dataN=datalength;
fstep=(fend-fstart)/dataN;
disp(fend);
datalength=round(swiftlength/stimeStep);
swiftfstart=startfreq;
swiftfend=endfreq;
Istart=round(swiftfstart/fstep);
Iend=round(swiftfend/fstep);
Itotal=Iend-Istart;
swiftmag(1:Istart)=0;
swiftmag(Istart:Iend)=1;
swiftmag(Iend:dataN)=0;
swiftphase(1:dataN)=0;
for I=Istart:Iend
swiftphase(I)=-(pi/2*(I-Istart)-pi/Itotal/2*(I-Istart)^2);
end
notch1start=nothstart;
notch1end=nothend;
N1start=round(notch1start/fstep);
N1end=round(notch1end/fstep);
swiftmag(N1start:N1end)=0;
notchstart=notch2start;
notchend=nothch2end;
Nstart=round(notchstart/fstep);
Nend=round(notchend/fstep);
swiftmag(Nstart:Nend)=0;
swiftFreal=swiftmag.cos(swiftphase);
swiftFimg=1iswiftmag.*sin(swiftphase);
swiftF=swiftFreal+swiftFimg;
swiftT1=ifft(swiftF);
swiftT(1:dataN/2)=swiftT1(dataN/2+1:dataN);
swiftT(dataN/2+1:dataN)=swiftT1(1:dataN/2);
% Stimelength=dataN/fend;
Stime=linspace(0,Stimelength,dataN);
freq=linspace(fstart,fend,dataN);
% Plotting
figure(1)
plot(Stime, real(swiftT));
xlabel(‘Time (s)’)
ylabel(‘Amplitude’)
% Set custom ticks for the time axis
% xticks([0.02, 0.04, 0.06, 0.08, 0.1]);
% xticklabels({‘0.02’, ‘0.04’, ‘0.06’, ‘0.08’, ‘0.1’});
% % Set custom ticks for the time axis
% xticks([0, 0.005, 0.015, 0.025, 0.035, 0.04]);
% xticklabels({‘0’, ‘0.005’, ‘0.015’, ‘0.025’, ‘0.035’, ‘0.04’});
% yticks([-2.5, -2, -1, 0, 1, 2, 2.5]);
% yticklabels({‘-2.5’, ‘-2’, ‘-1’, ‘0’, ‘1’, ‘2’, ‘2.5’});
figure(2)
plot(freq, abs(fft(swiftT)))
xlabel(‘Frequency (Hz)’)
ylabel(‘Magnitude’)
figure(3)
plot(freq, swiftphase)
xlabel(‘Frequency (Hz)’)
ylabel(‘Phase (rad)’)
savefile = ‘SWIFT.txt’;
x = Stime’;
y = real(swiftT)‘;
save(savefile, ‘x’, ‘y’, ‘-ASCII’)
% savefile = ‘C:C:\Users\Lenovo\Desktop\matAC\electric _field\SWIFT.txt\1'; % Specify the full path where you want to save the file
% x = Stime’;
% y = real(swiftT)’;
% save(savefile, ‘x’, ‘y’, ‘-ASCII’);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Define STFT parameters
win_size = 2048; % Window size
overlap = 0.5; % Overlap factor
fft_size = 20000; % FFT size
% Initialize STFT result matrix
stft_result = ;
% Loop over Swift time domain data in windows and apply FFT
for i = 1:win_size*(1-overlap):length(swiftT)-win_size
window = swiftT(i:i+win_size-1);
fft_result = fft(window, fft_size+1);
stft_result = [stft_result; abs(fft_result(1:fft_size))];
end
% Calculate frequency and time axes
freq_axis = linspace(startfreq, endfreq, fft_size);
time_axis = linspace(0, Stimelength, size(stft_result, 1));
% Plot the STFT spectrogram
figure;
% imagesc(time_axis1000,freq_axis / 1000, stft_result.');
imagesc(time_axis1000, linspace(startfreq, endfreq, fft_size)/1e3, stft_result.');
axis xy;
colorbar;
xlabel(‘Time (ms)’);
ylabel(‘Frequency (kHz)’);
title(‘STFT Spectrogram’);