Follow up to Previous Question

2 ビュー (過去 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 Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by