How do I assign frequency values to the obtained fft values without plotting . I need to know the value of the peak at 16Hz for further calculations.

2 ビュー (過去 30 日間)
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);
EL1t=1.274e7*exp(1i*phi);
FP=fft(phi);
fs=1/dt/Nt;
Fs=(-1/dt/2:fs:1/dt/2-1);
Z=plot(Fs,fftshift(abs(fft(EL1t))));
I need to know the value at 16GHz in the plot.

採用された回答

vidyesh
vidyesh 2024 年 4 月 24 日
Hi Yogesh,
You can use the max function to find the value of the peak and its index in the array.
Then use the index to get the corresponding frequency.
Add the below lines to your code.
pow = fftshift(abs(fft(EL1t)));
[val,ind] = max(pow)
f_max = Fs(ind);
Hope this helps
  3 件のコメント
vidyesh
vidyesh 2024 年 4 月 24 日
I thought you wanted the value at peak (max value).
You can use the below code to find the value at a specific frequency:
freq_f = 16e9;
% nnz(Fs==freq_f) % returns 0
In this case it seems like array 'Fs' doesnt contain the exact value of 16 GHz, so we find the closest value.
[val,ind] = min(abs(Fs-freq_f)); % Find freq closest to 16 GHz
disp(Fs(ind));
disp(pow(ind));
Yogesh
Yogesh 2024 年 4 月 24 日
Thank you Vidyesh , you were really helpful...

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by