Trying to find the integral under the curve at a certain bandwidth

3 次查看(过去 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))));
%xlim([-0.5e10 0.5e10]);
pow = fftshift(abs(fft(EL1t)));
freq_f = 16e9;
% nnz(Fs==freq_f) % returns 0
[val,ind] = min(abs(Fs-freq_f)); % Find freq closest to 16 GHz
disp(Fs(ind));
1.6001e+10
disp(pow(ind));
3.2278e+07
I wanted to find the area under the curve at 16GHz with 50MHz on the right and left side range.
I am trying to use trapz command but still a bit confused...
  2 个评论
Mathieu NOE
Mathieu NOE 2024-4-24
hello
not sure to understand what your goal is
if your signal is a sine wave at f = fsine = 1e9, there should be zero power around 16 GHz +/- 50 MHz
Yogesh
Yogesh 2024-4-24
Hii , I am trying to find the area under the fft curve mentioned above at 16GHz +/-50MHz..

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2024-4-24
Try this —
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);
figure
Z=plot(Fs,fftshift(abs(fft(EL1t))));
xline([-1 1]*50E+6 + 16E+9, '--r', 'Requested Frequency Range')
figure
Z=plot(Fs,fftshift(abs(fft(EL1t))));
xlim([-1 1]*50E+6 + 16E+9) % Set 'xlim' Values To Show The Desired Frequency Range
title('Signal In Requested Frequency Range')
freqlims = 16E+9 + [-1 1]*50E+6;
% idxrng = (Fs >= 16E+9-50E+6) & (Fs <= 16E+9-50E+6)
% q = nnz(idxrng)
magvals = interp1(Fs, fftshift(abs(fft(EL1t))), freqlims); % Interpolate To Get The Required Magnitude Values In The Desired Frequency Range
AUC = trapz(freqlims, magvals);
fprintf('\nThe area under the curve between %.5E Hz and %.5E Hz is %.5E units.\n', freqlims, AUC)
The area under the curve between 1.59500E+10 Hz and 1.60500E+10 Hz is 3.22793E+15 units.
%xlim([-0.5e10 0.5e10]);
pow = fftshift(abs(fft(EL1t)));
freq_f = 16e9;
% nnz(Fs==freq_f) % returns 0
[val,ind] = min(abs(Fs-freq_f)); % Find freq closest to 16 GHz
disp(Fs(ind));
1.6001e+10
disp(pow(ind));
3.2278e+07
There are no index values in the requested frequency range, so the only option is to interpolate the values that are, and use them as arguments to trapz. This approach would work for any frequency range within ‘Fs’.
.
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by