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

조회 수: 2 (최근 30일)
Yogesh
Yogesh 2024년 4월 24일
댓글: Star Strider 2024년 4월 29일
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
Yogesh
Yogesh 2024년 4월 29일
Thank you @Star Strider...
You were really helpful!!!...
Star Strider
Star Strider 2024년 4월 29일
@Yogesh — As always, my pleasure!
Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (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