Need Help running functions Resubmit
Show older comments
I am resubmitting this question again.
I need help coding and running some functions for the signal in the attached. I need to find the value of the signal bandwidth using the following bandwidth definitions:
(a) Half-power bandwidth.
(b) Null-to-null bandwidth.
(c) 99% of power bandwidth. (Hint: Use numerical methods.)
(d) Bandwidth beyond which the attenuation is 35 dB.
Below is what I have so far for the code but I get several errors when I try to run. Could you please help
clc
clear all
f=446000
Gx(f)=10^-4*(sin(pi*(f-10^6)*10^-4)/(pi*(f-10^6)*10^-4))
% 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
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!