Vous êtes sur la page 1sur 10

fft

FastFouriertransform

Syntax

Y=fft(X) example

Y=fft(X,n) example

Y=fft(X,n,dim) example

Description
Y=fft(X)computesthediscreteFouriertransform(DFT)ofXusingafastFouriertransform(FFT)algorithm. example

IfXisavector,thenfft(X)returnstheFouriertransformofthevector.
IfXisamatrix,thenfft(X)treatsthecolumnsofXasvectorsandreturnstheFouriertransformofeachcolumn.
IfXisamultidimensionalarray,thenfft(X)treatsthevaluesalongthefirstarraydimensionwhosesizedoesnot
equal1asvectorsandreturnstheFouriertransformofeachvector.
example
Y=fft(X,n)returnsthenpointDFT.Ifnovalueisspecified,YisthesamesizeasX.
IfXisavectorandthelengthofXislessthann,thenXispaddedwithtrailingzerostolengthn.
IfXisavectorandthelengthofXisgreaterthann,thenXistruncatedtolengthn.
IfXisamatrix,theneachcolumnistreatedasinthevectorcase.
IfXisamultidimensionalarray,thenthefirstarraydimensionwhosesizedoesnotequal1istreatedasinthevector
case.
example
Y=fft(X,n,dim)returnstheFouriertransformalongthedimensiondim.Forexample,ifXisamatrix,then
fft(X,n,2)returnsthenpointFouriertransformofeachrow.

Examples collapseall

NoisySignal

UseFouriertransformstofindthefrequencycomponentsofasignalburiedinnoise.
OpenScript
Specifytheparametersofasignalwithasamplingfrequencyof1kHzandasignal
durationof1second.

Fs=1000;%Samplingfrequency
T=1/Fs;%Samplingperiod
L=1000;%Lengthofsignal
t=(0:L1)*T;%Timevector

Formasignalcontaininga50Hzsinusoidofamplitude0.7anda120Hzsinusoidofamplitude1.

S=0.7*sin(2*pi*50*t)+sin(2*pi*120*t);

Corruptthesignalwithzeromeanwhitenoisewithavarianceof4.

X=S+2*randn(size(t));

Plotthenoisysignalinthetimedomain.ItisdifficulttoidentifythefrequencycomponentsbylookingatthesignalX(t).
plot(1000*t(1:50),X(1:50))
title('SignalCorruptedwithZeroMeanRandomNoise')
xlabel('t(milliseconds)')
ylabel('X(t)')

ComputetheFouriertransformofthesignal.

Y=fft(X);

ComputethetwosidedspectrumP2.ThencomputethesinglesidedspectrumP1basedonP2andtheevenvaluedsignallength
L.

P2=abs(Y/L);
P1=P2(1:L/2+1);
P1(2:end1)=2*P1(2:end1);

DefinethefrequencydomainfandplotthesinglesidedamplitudespectrumP1.Theamplitudesarenotexactlyat0.7and1,as
expected,becauseoftheaddednoise.Onaverage,longersignalsproducebetterfrequencyapproximations.

f=Fs*(0:(L/2))/L;
plot(f,P1)
title('SingleSidedAmplitudeSpectrumofX(t)')
xlabel('f(Hz)')
ylabel('|P1(f)|')
Now,taketheFouriertransformoftheoriginal,uncorruptedsignalandretrievetheexactamplitudes,0.7and1.0.

Y=fft(S);
P2=abs(Y/L);
P1=P2(1:L/2+1);
P1(2:end1)=2*P1(2:end1);

plot(f,P1)
title('SingleSidedAmplitudeSpectrumofS(t)')
xlabel('f(Hz)')
ylabel('|P1(f)|')
GaussianPulse

ConvertaGaussianpulsefromthetimedomaintothefrequencydomain.
OpenScript
DefinesignalparametersandaGaussianpulse,X.

Fs=100;%Samplingfrequency
t=0.5:1/Fs:0.5;%Timevector
L=length(t);%Signallength

X=1/(4*sqrt(2*pi*0.01))*(exp(t.^2/(2*0.01)));

Plotthepulseinthetimedomain.

plot(t,X)
title('GaussianPulseinTimeDomain')
xlabel('Time(t)')
ylabel('X(t)')
Tousethefftfunctiontoconvertthesignaltothefrequencydomain,firstidentifyanewinputlengththatisthenextpowerof2
fromtheoriginalsignallength.ThiswillpadthesignalXwithtrailingzerosinordertoimprovetheperformanceoffft.

n=2^nextpow2(L);

ConverttheGaussianpulsetothefrequencydomain.

Y=fft(X,n);

Definethefrequencydomainandplottheuniquefrequencies.

f=Fs*(0:(n/2))/n;
P=abs(Y/n);

plot(f,P(1:n/2+1))
title('GaussianPulseinFrequencyDomain')
xlabel('Frequency(f)')
ylabel('|P(f)|')
CosineWaves

Comparecosinewavesinthetimedomainandthefrequencydomain.
OpenScript
Specifytheparametersofasignalwithasamplingfrequencyof1kHzandasignal
durationof1second.

Fs=1000;%Samplingfrequency
T=1/Fs;%Samplingperiod
L=1000;%Lengthofsignal
t=(0:L1)*T;%Timevector

Createamatrixwhereeachrowrepresentsacosinewavewithscaledfrequency.Theresult,X,isa3by1000matrix.Thefirst
rowhasawavefrequencyof50,thesecondrowhasawavefrequencyof150,andthethirdrowhasawavefrequencyof300.

x1=cos(2*pi*50*t);%Firstrowwave
x2=cos(2*pi*150*t);%Secondrowwave
x3=cos(2*pi*300*t);%Thirdrowwave

X=[x1;x2;x3];

Plotthefirst100entriesfromeachrowofXinasinglefigureinorderandcomparetheirfrequencies.

fori=1:3
subplot(3,1,i)
plot(t(1:100),X(i,1:100))
title(['Row',num2str(i),'intheTimeDomain'])
end
Foralgorithmperformancepurposes,fftallowsyoutopadtheinputwithtrailingzeros.Inthiscase,padeachrowofXwithzeros
sothatthelengthofeachrowisthenexthigherpowerof2fromthecurrentlength.Definethenewlengthusingthenextpow2
function.

n=2^nextpow2(L);

SpecifythedimargumenttousefftalongtherowsofX,thatis,foreachsignal.

dim=2;

ComputetheFouriertransformofthesignals.

Y=fft(X,n,dim);

Calculatethedoublesidedspectrumandsinglesidedspectrumofeachsignal.

P2=abs(Y/n);
P1=P2(:,1:n/2+1);
P1(:,2:end1)=2*P1(:,2:end1);

Inthefrequencydomain,plotthesinglesidedamplitudespectrumforeachrowinasinglefigure.

fori=1:3
subplot(3,1,i)
plot(0:(Fs/n):(Fs/2Fs/n),P1(i,1:n/2))
title(['Row',num2str(i),'intheFrequencyDomain'])
end
InputArguments collapseall

XInputarray
vector|matrix|multidimensionalarray

Inputarray,specifiedasavector,matrix,ormultidimensionalarray.

Inputarraysof8bitor16bitunsignedintegersarecasttodoublepriortocomputingtheFouriertransform.

IfXisanempty0by0matrix,thenfft(X)returnsanempty0by0matrix.

DataTypes:double|single|uint8|uint16
ComplexNumberSupport:Yes

nTransformlength
[](default)|nonnegativeintegerscalar

Transformlength,specifiedas[]oranonnegativeintegerscalar.Specifyingapositiveintegerscalarforthetransformlengthcan
increasetheperformanceoffft.Thelengthistypicallyspecifiedasapowerof2oravaluethatcanbefactoredintoaproductof
smallprimenumbers.Ifnislessthanthelengthofthesignal,thenfftignorestheremainingsignalvaluespastthenthentryand
returnsthetruncatedresult.Ifnis0,thenfftreturnsanemptymatrix.

Example:n=2^nextpow2(size(X,1))

DataTypes:double|single|uint8|uint16

dimDimensiontooperatealong
positiveintegerscalar

Dimensiontooperatealong,specifiedasapositiveintegerscalar.Ifnovalueisspecified,thenthedefaultisthefirstarray
dimensionwhosesizedoesnotequal1.
fft(X,[],1)operatesalongthecolumnsofXandreturnstheFouriertransformofeachcolumn.

fft(X,[],2)operatesalongtherowsofXandreturnstheFouriertransformofeachrow.

Ifdimisgreaterthanndims(X),thenfft(X,[],dim)returnsX.Whennisspecified,fft(X,n,dim)padsortruncatesXtolength
nalongdimensiondim.

DataTypes:double|single|uint8|uint16

OutputArguments collapseall

YFrequencydomainrepresentation
vector|matrix|multidimensionalarray

Frequencydomainrepresentationreturnedasavector,matrix,ormultidimensionalarray.

IfXisoftypesingle,thenfftnativelycomputesinsingleprecision,andYisalsooftypesingle.Otherwise,Yisreturnedasa
typedouble.

ThesizeofYisasfollows:

ForY=fft(X)orY=fft(X,[],dim),thesizeofYisequaltothesizeofX.
ForY=fft(X,n,dim),thevalueofsize(Y,dim)isequalton,whilethesizeofallotherdimensionsremainsasinX.

IfXisreal,thenYisconjugatesymmetric,andthenumberofuniquepointsinYisceil((n+1)/2).

MoreAbout collapseall

DiscreteFourierTransformofVector
Y=fft(X)andX=ifft(Y)implementtheFouriertransformandinverseFouriertransform,respectively.ForXandYoflength
n,thesetransformsaredefinedasfollows:


n
(j1)(k 1)
Y (k ) = X ( j)W n
j=1

n

X ( j) = 1 Y (k )Wn(j1)(k 1),
n k=1

where

Wn = e(2i)/n
isoneofnrootsofunity.
Tips
Theexecutiontimeforfftdependsonthelengthofthetransform.Thetimeisfastestforpowersoftwoandalmostasfast
forlengthsthathaveonlysmallprimefactors.Thetimeistypicallyseveraltimesslowerforlengthsthatareprime,orwhich
havelargeprimefactors.
Formostvaluesofn,realinputDFTsrequireroughlyhalfthecomputationtimeofcomplexinputDFTs.However,whennhas
largeprimefactors,thereislittleornospeeddifference.
Youcanpotentiallyincreasethespeedoffftusingtheutilityfunction,fftw.Thisfunctioncontrolstheoptimizationofthe
algorithmusedtocomputeanFFTofaparticularsizeanddimension.

Algorithms
TheFFTfunctions(fft,fft2,fftn,ifft,ifft2,ifftn)arebasedonalibrarycalledFFTW[1][2].

FourierTransforms

References
[1]FFTW(http://www.fftw.org)

[2]Frigo,M.,andS.G.Johnson."FFTW:AnAdaptiveSoftwareArchitecturefortheFFT."ProceedingsoftheInternationalConference
onAcoustics,Speech,andSignalProcessing.Vol.3,1998,pp.13811384.

SeeAlso
fft2|fftn|fftshift|fftw|ifft

IntroducedbeforeR2006a

Vous aimerez peut-être aussi