hy guys.
i have a question concerning the scaling in fft .
i have seen alot of code on this forum, but some of the code scale the fft with length of the time domain while other's with increment.
code:
clear all; clc
dt=0.1;
t=-5:dt:5;
z=numel(t);
df = 1/dt;
f = linspace(-df/2, df/2, z);
h_t=rectpuls(t,1/f0);
h_f=fftshift(fft(h_t,n));
% how to scale h_f? should i divide h_f with z or dt and why?
% thank you in advance

 채택된 답변

Matt J
Matt J 2022년 2월 10일
편집: Matt J 2022년 2월 10일

0 개 추천

The DFT is a tool for computing several other theoretical transforms. It can be used to compute a Discrete Fourier Series, which is when you would scale by the length. It can also be used to approximate a continuous Fourier transform, which is when you scale by the time increment.
There is also some disagreement across different professions (esp., engineering versus physics) on scaling factors in the definitions of these transforms. Therefore, the safest way to determine the scaling that you need is to just compare the formula in Matlab's FFT defintiion to the formula for the thing you want to compute.

댓글 수: 8

Rabih Sokhen
Rabih Sokhen 2022년 2월 10일
okay deal
thank you Matt.
Rabih Sokhen
Rabih Sokhen 2022년 2월 10일
one more question plz. my aim is continuous Fourier transform.
if i already have h_t and i want to scale h_f , should i multiply h_f with dt --> h_t=fftshift(fft(h_f)))*dt ?
and if i want to find h_t from h_f, should i divide h_t with dt --> h_t=fftshift(fft(h_f)))/dt ?
thank you in advance
Matt J
Matt J 2022년 2월 10일
Yes.
Rabih Sokhen
Rabih Sokhen 2022년 2월 10일
thank you for your help
Paul
Paul 2022년 2월 10일
편집: Paul 2022년 2월 12일
To illustrate ...
If the desire is to use fft() to compute the DFT to approximate the Continuous Time Fourier Transform (CTFT) of a finite duration signal, then zero padding should be considered because the DFT inherenntly assumes the underlying signal is the periodic extension of the seuqence, which can lead to misleading results.
Consider an example with a rectangular pulse and its CTFT
syms t
f(t) = rectangularPulse(0,1,t);
syms w
ctft(w) = fourier(f(t),t,w); % CTFT of f(t)
Samples of f(t) at 20 Hz
dt = 0.05;
tvec = 0:dt:1;
fvals = ones(1,numel(tvec));
Compute the Discrete Time Fourier Transform (DTFT) of fvals.
[dtft,wdtft] = freqz(fvals,1,1024);
Plot the CTFT and the DTFT. We see that dt*DTFT is a reasonable approximation to the CTFT up to the Nyquist frequency (pi/dt)
figure
fplot(abs(ctft),[0 65]);
hold on
plot(wdtft/dt,dt*abs(dtft))
xlim([-1 pi/dt])
legend('CTFT','DTFT')
Now add to the plot the DFT of fvals
figure
fplot(abs(ctft),[0 65]);
hold on
plot(wdtft/dt,dt*abs(dtft))
dft = fft(fvals);
wdft = (0:numel(dft)-1)/numel(dft)*2*pi/dt;
stem(wdft(1:11),dt*abs(dft(1:11)),'MarkerFaceColor','auto')
xlim([-1 pi/dt])
legend('CTFT','DTFT','DFT no pad')
The DFT is nonzero only at w = 0 because the periodic extension of fvals is a constant sequence over all time. Note that the DFT are samples of the of the DTFT as they must be.
Now take the DFT with zero padding to pick up the ups and downs of the DTFT.
figure
fplot(abs(ctft),[0 65]);
hold on
plot(wdtft/dt,dt*abs(dtft))
dft = fft(fvals,64);
wdft = (0:numel(dft)-1)/numel(dft)*2*pi/dt;
stem(wdft(1:31),dt*abs(dft(1:31)),'MarkerFaceColor','auto')
xlim([-1 pi/dt])
legend('CTFT','DTFT','DFT w/pad')
In summary for a finite duration signal, the DFT of time domain samples of the signal are frequency domain samples of the DTFT, and dt*DTFT is an approximation to the CTFT up to the Nyquist frequency.
Edit: I just realized that making the samples of the rectangular pulse unity at the leading and trailing edges is is why the DTFT is larger at DC and has nulls offset in frequency compared to the CTFT. I guess one has to decide how what it means to sample at the discotinuities. I think reasonable options are to use a sample equal to 1 at the leading edge and zero at the trailing edge, i.e., the sampling starts at t = 0+, or make the samples = 1/2 at both edges. Here's the final plot using the second approach
figure
fplot(abs(ctft),[0 65]);
hold on
fvals = [0.5 ones(1,numel(tvec)-2) 0.5];
[dtft,wdtft] = freqz(fvals,1,1024);
plot(wdtft/dt,dt*abs(dtft));
dft = fft(fvals,64);
wdft = (0:numel(dft)-1)/numel(dft)*2*pi/dt;
stem(wdft(1:31),dt*abs(dft(1:31)),'MarkerFaceColor','auto')
xlim([-1 pi/dt])
legend('CTFT','DTFT','DFT w/pad')
Rabih Sokhen
Rabih Sokhen 2022년 2월 11일
Thank you Paul for your response, i understand more now.
in my case i want to do the fft of a vector so it will fit my continuous function.
just to be sure, the best way is to multiply my fft with dt instead of pading?
thank you in advance.
Matt J
Matt J 2022년 2월 11일
No, you must always multiply by dt. The issue of choosing how much zero-padding you need to do is separate.
Rabih Sokhen
Rabih Sokhen 2022년 3월 3일
thank you Matt, sry for the late response .

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Install Products에 대해 자세히 알아보기

태그

질문:

2022년 2월 10일

댓글:

2022년 3월 3일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by