Trying to find the integral under the curve at a certain bandwidth
조회 수: 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))));
%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
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
채택된 답변
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)
%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
추가 답변 (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!