I want to make this MATLAB code to plot a Gaussian pulse in THz, then use FFT on it. This is the MATLAB code I used to get the FFT of time domain Gaussian signal at 800nm wavelength:

lambda= 800e-9;%Wavelength
c=3*10.^8;%lLight speed
fc = c/lambda; % Actual Frequency of light [THz]
fsamp=fc*10; %sampling frequency
fs=1/fsamp; %Unit Time in [fs]
Ls=200; %Length of signal
sigma=8e-15;% Pulse duration
ts=(0:Ls-1)*fs; %time base
t0 = max(ts)/2; % Used to centering the pulse
gauss = (exp(-2*log(2)*(ts-t0).^2/(sigma)^2)).*cos(-2*pi*fc*(ts-t0));
title('Gaussian Pulse in Time Domain');
grid on;
NFFT = 2^nextpow2(Ls);
X = fft(gauss,NFFT)/Ls;
freq = 0.5*fsamp*linspace(0,1,NFFT/2+1); % (full range) Frequency Vector
title('FFT of the Gaussian Pulse');
xlabel('Frequency (Hz)')
ylabel('Magnitude |X(f)|');
grid on;

Which will give:

800e-9 m Wavelength

However, when I change the wavelength to 30um, it will give me a different shape:

30e-6 Wavelength

I know this is due the pulse duration (sigma), or maybe entirely wrong code. How do I make it retain its shape whenever I change the wavelength, without continuously changing the pulse duration?

  • $\begingroup$ If maintaining the waveform is your goal, try changing the sigma statement to sigma=lambda/1e+8 instead of a constant value $\endgroup$ – DSP Novice May 11 at 7:26
  • $\begingroup$ Thank you, it worked. $\endgroup$ – Warm Cup May 11 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.