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

3 views (last 30 days)
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 Comments
Mathieu NOE
Mathieu NOE on 24 Apr 2024
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 on 24 Apr 2024
Hii , I am trying to find the area under the fft curve mentioned above at 16GHz +/-50MHz..

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 24 Apr 2024
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!