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.

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.

 Risposta accettata

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 Commenti

But the above command is for max value which is at 0GHz , but I want to know the value at 16GHz
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));
Thank you Vidyesh , you were really helpful...

Accedi per commentare.

Più risposte (0)

Tag

Richiesto:

il 24 Apr 2024

Commentato:

il 24 Apr 2024

Community Treasure Hunt

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

Start Hunting!

Translated by