# Need help in assigning frequency and normalising amplitude to the fft plot

2 ビュー (過去 30 日間)
Yogesh 2024 年 4 月 18 日
コメント済み: Paul 2024 年 4 月 18 日
clear all
close all
clc
L=10;
n=1.45;
c=2.9979e8;
dt = 6e-12;
T=10*2*L*n/c;
t = (-T/2/dt:1:T/2/dt)*dt;
Nt=round(T/dt);
fsine = 1e9;
vsine = 1;
phi = vsine*sin(2*pi*fsine*t);
FP=fft(phi);
fs=(-Nt/2:1:Nt/2-1);
Y=plot(fs,fftshift(abs(FP)));
Basically i have obtained this fft plot but I cannot figure out how to normalise the amplitude and then assign the frequency values.
Any help would be much appreciated.
Thank you.

サインインしてコメントする。

### 採用された回答

Star Strider 2024 年 4 月 18 日
There may be several approaches to your problem.
One of them is this —
clear all
close all
clc
L=10;
n=1.45;
c=2.9979e8;
dt = 6e-12;
T=10*2*L*n/c;
t = (-T/2/dt:1:T/2/dt)*dt;
Fs = 1/dt % Sampling Frequency
Fs = 1.6667e+11
Fn = Fs/2 % Nyquist Frequency
Fn = 8.3333e+10
Nt=round(T/dt);
fsine = 1e9;
vsine = 1;
phi = vsine*sin(2*pi*fsine*t);
FP=fft(phi)/numel(phi); % Normalise By Dividing By Signal Length
% fs=(-Nt/2:1:Nt/2-1)
fs = -Fn : Fs/numel(FP) : (Fn - Fs/numel(FP)); % Frequency Vector
figure
Y=plot(fs,fftshift(abs(FP)));
figure
Y=plot(fs,fftshift(abs(FP)));
grid
xlim([-1 1]*2.0E+9)
The signal energy is split between the +ve and -ve frequencies, so the frequency domain magnitude is only about ½ the original signal amplitude.
.
##### 3 件のコメント1 件の古いコメントを表示1 件の古いコメントを非表示
Star Strider 2024 年 4 月 18 日
My pleasure!
To quote from my Answer —
The signal energy is split between the +ve and -ve frequencies, so the frequency domain magnitude is only about ½ the original signal amplitude.
There is alkso ‘spectral leakage’, ao some of the energy also appears in the curved segments at the base of the peaks, as noited in the added third figure —
clear all
close all
clc
L=10;
n=1.45;
c=2.9979e8;
dt = 6e-12;
T=10*2*L*n/c;
t = (-T/2/dt:1:T/2/dt)*dt;
Fs = 1/dt % Sampling Frequency
Fs = 1.6667e+11
Fn = Fs/2 % Nyquist Frequency
Fn = 8.3333e+10
Nt=round(T/dt);
fsine = 1e9;
vsine = 1;
phi = vsine*sin(2*pi*fsine*t);
FP=fft(phi)/numel(phi); % Normalise By Dividing By Signal Length
% fs=(-Nt/2:1:Nt/2-1)
fs = -Fn : Fs/numel(FP) : Fn; % Frequency Vector
fs(ceil(numel(fs)/2)) = [];
Q = 1x2
161224 80612
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
figure
Y=plot(fs,fftshift(abs(FP)));
figure
Y=plot(fs,fftshift(abs(FP)));
grid
xlim([-1 1]*2.0E+9)
figure
Y=plot(fs,fftshift(abs(FP)));
grid
xlim([-1 1]*2.0E+9)
ylim([0 0.025])
text(0, 0.0015, '\leftarrow Spectral Leakage \rightarrow', 'Horiz','center')
Because of computational issues that are simply part of computer floating-point arithmetic, some of the signal energy also appears near the centres of the peaks. That is the reason the individual peak amplitudes do not equal exactly ½ of the original signal amplitude. The original signal energy being divided between the +ve and -ve frequency regions is the reason the peak magnitudes would only reach ½ the original signal amplitude if the computations were perfect (or if the signal was ‘windowed’ using for example an hann window, to correct for the fft being finite), while the analytic Fourier transform would be integrated from to and would therefore be exact.
.
Paul 2024 年 4 月 18 日
How does floating point accuracy affect this problem?
Are you suggesting that using a hann window would exactly recover the 1/2 amplitude? It doesn't seem to.
L=10;
n=1.45;
c=2.9979e8;
dt = 6e-12;
T=10*2*L*n/c;
t = (-T/2/dt:1:T/2/dt)*dt;
Fs = 1/dt; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Nt=round(T/dt);
fsine = 1e9;
vsine = 1;
phi = vsine*sin(2*pi*fsine*t);
FP=fft(phi(:).*hann(numel(phi)))/sum(hann(numel(phi))); % Normalise By Dividing By Signal Length
% fs=(-Nt/2:1:Nt/2-1)
Is the frequency vector correct?
fs = -Fn : Fs/numel(FP) : Fn; % Frequency Vector
fs(ceil(numel(fs)/2)) = [];
figure
Y=plot(fs,fftshift(abs(FP)));
xline(fsine,'r')
xlim([-1 1]*2.0E+9)
xlim([0.95 1.05]*1e9)

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

### Community Treasure Hunt

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

Start Hunting!

Translated by