how to scale fft?
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
0 投票
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
採用された回答
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
2022 年 2 月 10 日
okay deal
thank you Matt.
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
2022 年 2 月 10 日
Yes.
Rabih Sokhen
2022 年 2 月 10 日
thank you for your help
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
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
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
2022 年 3 月 3 日
thank you Matt, sry for the late response .
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Install Products についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
