trying simply to create femtosecond pulse in MATLAB exactly like in the attached image,

enter image description here

the carrier frequency is around 374THz, and my sampling frequency is 10 times the carrier. The results of the fft yields nothing understandable... tried to change some of the variables, fs,t-around zero, fftshift... but could not conclude what's wrong with code.

my code follows matlab fft example :

clear all ; close all ; clc
fs=f*10; %sampling frequency
t=(0:L-1)*T; %time base

title(['Gaussian Pulse \sigma=', num2str(sigma),'s']);
ylim([-1 1]) 
xlim([10e-15 90e-15])

NFFT = 2^nextpow2(L);
X = fft(x,NFFT)/L;
Pxx=X.*conj(X)/(NFFT*NFFT); %computing power with proper scaling
f = fs/2*linspace(0,1,NFFT/2+1); %Frequency Vector

title('Magnitude of FFT');
xlabel('Frequency (Hz)')
ylabel('Magnitude |X(f)|');

the results are :

enter image description here

  • $\begingroup$ I would like to ask something related to the question asked on the post. I have a gaussian pulse as described below in the code: close all; f0=0.5; % central frequency, MHz t0=1.5; % pulse center time bndwdth=10; % pulse -6dB bandwidth duration=2*t0; % signal length % Gausspuls by default gives unity amplitude timebase=(0:round(duration/dt)-1)'dt; [signalI,signalQ]=gauspuls(timebase-t0,f0,bndwdth); signal=20*signalQ; How can i achieve a plot similar to the one above?? through the code: Fs=1.5e6; t = 0:1/Fs:1; L = length(t); n = 2^nextpow2(L); y=fft(signal,n); P = 2*abs(y/n); f = Fslinspace(0 $\endgroup$ Apr 4, 2019 at 8:52
  • $\begingroup$ @KunalKhosla Welcome to SE.SP! This is not a discussion forum. If you have a question, please ask it as a new question DO NOT post it as an answer on a related question. $\endgroup$
    – Peter K.
    Apr 4, 2019 at 14:32

1 Answer 1


You simply don't plot what you want to see. Note that your time domain signal is complex-valued and you modulate by a negative frequency. So the range of frequencies where things are happening are the negative frequencies (or - by periodicity - the frequencies in the range $[f_s/2,f_s]$), but those you don't plot. If you change the definition of your frequency vector and the corresponding plot command you'll see what you expect to see (i.e. a Gaussian in the frequency domain centered at $f_s-f=3.37e15$ Hz):

f = fs*linspace(0,1,NFFT); % (full range) Frequency Vector

enter image description here

OR, simply change the negative modulation frequency to a positive one


and leave everything else unchanged. Then the Gaussian in the frequency domain is centered at $f=374.7$ THz. This is probably what you expected to see in the first place.

enter image description here

  • $\begingroup$ thank's you made me realize that i made a mistake looking at the Fourier transform pair for frequency shift and taking the negative one as you wrote :/ . As for your first solution i want to look into it and learn more about using fft with matlab, you wrote: "(i.e. a Gaussian in the frequency domain centered at fs−f=3.37e15 Hz)" it's a bit tricky for me to understand it, if I intend to center my Gaussian at 'f=374e12Hz' why '337e12Hz' is what I looking for ? $\endgroup$
    – UdiW
    Aug 31, 2014 at 13:03
  • $\begingroup$ @UdiWeiss: If you modulate with a negative frequency of $-374e12$ Hz (as in your original code), you should expect the frequency domain Gaussian to be centered at that negative frequency. Due to the periodicity of the spectrum of a discrete time signal, you'll see the Gaussian also at frequencies $-f+kf_s$, and $f_s-f$ is the frequency for $k=1$. The values of the FFT correspond to frequencies in the fundamental interval $[0,f_s]$. $\endgroup$
    – Matt L.
    Aug 31, 2014 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.