peaceman
peaceman

Reputation: 1529

discrete Fourier transform in matlab for data?

I have some data in time domain, the time separation between each element is dt and my data are from 0 to N*dt sec,I want to see spectral of my data from .6e15 Hz to 1e15 Hz what must I do?

Upvotes: 1

Views: 1948

Answers (2)

peaceman
peaceman

Reputation: 1529

Here is the code that I need:

NT=10000;%size of data that I have
ddx=2e-9;
dt=ddx/(3e8);%time separation between each element
i=sqrt(-1);
NFREQS=1000;%size of frequency array
lambdai=150e-9;
lambdaf=500e-9;
freqi=3e8/lambdai;%lower limit of frequency
freqf=3e8/lambdaf;%upper limit of frequency
freq=zeros(1,NFREQS);
for j=1:NFREQS
freq(j)=freqi-j*(freqi-freqf)/NFREQS;%frequency array
end
arg=2*pi*freq*dt;
lambda=linspace(lambdai,lambdaf,NFREQS);
    for n=1:NFREQS
    for j=1:NT
     Exf(n)=Exf(n)+Ex(j)*exp(-i*arg(n)*j);%Ex the data that I have and Exf is fft of it
    end
    end

plot(lambda,real(Epsilon));

This code calculates Fourier transform of Ex in range of 150e-9m t0 500e-9m

Upvotes: 0

0x90
0x90

Reputation: 40982

let say you have the x in time already.

x%is given
fmin = 1e15;
fmax = 6*fmin;
numOfSamples = length(x);
f = linspace(fmin,fmax,numOfSamples);
t = 1 : numOfSamples;
y=fft(x);
plot(fftshift(y));

Upvotes: 1

Related Questions