Follow up to Previous Question

조회 수: 3 (최근 30일)
James Manns
James Manns 2024년 2월 6일
편집: Matt J 2024년 2월 6일
How do I display the calculations for each below?
clc
clear all
f=446000
f = 446000
Gf=10^-4*(sin(pi*(f-10^6)*10^-4)/(pi*(f-10^6)*10^-4))
Gf = -5.4645e-07
% calculate half-power beamwidth
function Bw = half_power_bw(f, Gf)
% Find the index of the maximum value in the magnitude spectrum
[~,imax] = max(abs(Gf));
% Find the indices of the half-power points
i_half_lower = find(abs(Gf) < abs(Gf(imax))/sqrt(2), 1, 'first');
i_half_upper = find(abs(Gf) < abs(Gf(imax))/sqrt(2), 1, 'last');
% Calculate the half-power bandwidth
Bw = f(i_half_upper) - f(i_half_lower);
end
% null-to-null beamwidth
function Bw = null_to_null_bw(f, Gf)
% Find the first and last nulls of the magnitude spectrum
nulls = find(abs(Gf) == 0);
i_null_lower = nulls(1);
i_null_upper = nulls(end);
% Calculate the null-to-null bandwidth
Bw = f(i_null_upper) - f(i_null_lower);
end
% 99% of power beamwidth
function Bw = power_bw(f, Gf, power_fraction)
% Calculate the total power
total_power = trapz(f, abs(Gf).^2);
% Find the index where the cumulative power reaches the desired fraction
power_integral = cumtrapz(f, abs(Gf).^2);
i_power = find(power_integral >= total_power*power_fraction, 1, 'first');
% Calculate the bandwidth at the desired power fraction
Bw = f(i_power);
end
% Bandwidth beyond which the attenuation is 35 dB.
function Bw = attenuation_bw(f, Gf, attenuation_dB)
% Convert attenuation from dB to linear scale
attenuation_linear = 10^(-attenuation_dB/20);
% Find the index where the magnitude spectrum falls below the attenuation level
i_attenuation = find(abs(Gf) < abs(max(Gf))*attenuation_linear, 1, 'first');
% Calculate the bandwidth beyond the attenuation level
Bw = f(i_attenuation);
end
  댓글 수: 1
Matt J
Matt J 2024년 2월 6일
편집: Matt J 2024년 2월 6일
Do we need to know what your previous question was? Some people weren't there.

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

채택된 답변

Matt J
Matt J 2024년 2월 6일
편집: Matt J 2024년 2월 6일
Just call the function, and omit a semicolon to see what its output is. However, your functions will not give nontrivial results unless f and Gf are vectors of the same size,
f=rand(1,10);
Gf=rand(1,10);
output = half_power_bw(f, Gf)
output = 0.0527
% calculate half-power beamwidth
function Bw = half_power_bw(f, Gf)
% Find the index of the maximum value in the magnitude spectrum
[~,imax] = max(abs(Gf));
% Find the indices of the half-power points
i_half_lower = find(abs(Gf) < abs(Gf(imax))/sqrt(2), 1, 'first');
i_half_upper = find(abs(Gf) < abs(Gf(imax))/sqrt(2), 1, 'last');
% Calculate the half-power bandwidth
Bw = f(i_half_upper) - f(i_half_lower);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by