Trying to find the integral under the curve at a certain bandwidth
2 views (last 30 days)
Show older comments
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));
disp(pow(ind));
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
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
Accepted Answer
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)
%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));
disp(pow(ind));
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
More Answers (0)
See Also
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!