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.
0 个评论
采纳的回答
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
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));
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!