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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Yogesh
el 24 de Abr. de 2024
Comentada: Yogesh
el 24 de Abr. de 2024
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 comentarios
Respuesta aceptada
vidyesh
el 24 de Abr. de 2024
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 comentarios
vidyesh
el 24 de Abr. de 2024
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));
Más respuestas (0)
Ver también
Categorías
Más información sobre Fourier Analysis and Filtering en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!