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!