2
$\begingroup$

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
f=374.7e12;%Thz
fs=f*10; %sampling frequency
T=1/fs;
L=1000;
sigma=5e-15;
t=(0:L-1)*T; %time base



x=(exp(-(t-50e-15).^2/(2*sigma)^2)).*exp(-1i*2*pi*f*t);
subplot(2,1,1)
plot(t,real(x),'b');
title(['Gaussian Pulse \sigma=', num2str(sigma),'s']);
xlabel('Time(s)');
ylabel('Amplitude');
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

subplot(2,1,2)
plot(f,2*abs(X(1:NFFT/2+1)))
title('Magnitude of FFT');
xlabel('Frequency (Hz)')
ylabel('Magnitude |X(f)|');

the results are :

enter image description here

$\endgroup$
  • $\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$ – Kunal Khosla Apr 4 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 at 14:32
0
$\begingroup$

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
...
plot(f,2*abs(X)) 

enter image description here

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

x=(exp(-(t-50e-15).^2/(2*sigma)^2)).*exp(1i*2*pi*f*t);

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

$\endgroup$
  • $\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 '14 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 '14 at 15:02

Your Answer

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

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