Error "It must be of type 'Type::MATLABOutput"

조회 수: 8 (최근 30일)
James Manns
James Manns 2024년 2월 1일
편집: Walter Roberson 2024년 2월 2일
I have a signal x(t)=exp(-100t), t>0. I'm trying to plot the ESD against frequency and then find and plot the 35dB bandwidt and the bandwidth that contains 99% of the energy.. The EDS plots fine but I get the following error for the 35dB plot:
"Error using / Invalid return value '[1/(2*abs(100 + w*1i)^2)]'. It must be of type'Type::MATLABOutput'.
Error in untitled3 (line 22) f_3dB = solve(ESD == max(ESD)/2, f);"
The code is below:
clc
clear all
syms t w;
x_t = exp(-100*t)*(heaviside(t));
X_w = fourier(x_t, w);
ESD = abs(X_w)^2;
% Plot ESD against linear frequency
f = linspace(-10, 10, 1000); % frequency range for plotting
ESD_plot = subs(ESD, w, 2*pi*f);
figure;
plot(f, ESD_plot);
title('Energy Spectral Density (ESD)');
xlabel('Frequency (Hz)');
ylabel('ESD');
grid on;
f_35dB = solve(ESD == max(ESD)/3162, f);
disp(['35 dB Bandwidth: ', num2str(2*f_35dB)]);
% Define frequency step size for numerical integration
df = 0.001;
freq_range = -10:df:10;
% Calculate energy in each frequency band
energy_in_band = double(subs(ESD, w, 2*pi*freq_range)) * df;
% Find the bandwidth containing 99% of the energy
cumulative_energy = cumsum(energy_in_band);
desired_energy = 0.99 * max(cumulative_energy);
bandwidth_99percent_energy = 2 * freq_range(find(cumulative_energy >= desired_energy, 1, 'first'));
disp(['Bandwidth containing 99% of the energy: ', num2str(bandwidth_99percent_energy)]);

채택된 답변

Walter Roberson
Walter Roberson 2024년 2월 2일
편집: Walter Roberson 2024년 2월 2일
f_35dB = solve(ESD == max(ESD)/3162, f);
max(ESD) returns a max() expression that is incompatible with the result of the calculation. It does not calculate the w for which ESD is the maximum and substitute that w to get the maximum ESD.
And you are asking to also solve f which is a vector of numeric frequencies.
  댓글 수: 1
Walter Roberson
Walter Roberson 2024년 2월 2일
편집: Walter Roberson 2024년 2월 2일
clc
clear all
syms t w;
x_t = exp(-100*t)*(heaviside(t));
X_w = fourier(x_t, w);
ESD = abs(X_w)^2;
% Plot ESD against linear frequency
f = linspace(-10, 10, 1000); % frequency range for plotting
ESD_plot = subs(ESD, w, 2*pi*f);
figure;
plot(f, ESD_plot);
title('Energy Spectral Density (ESD)');
xlabel('Frequency (Hz)');
ylabel('ESD');
grid on;
best_w = solve(diff(ESD, w),w)
best_w = 
0
max_ESD = subs(ESD, w, best_w)
max_ESD = 
f_35dB = double(solve(ESD == max_ESD/3162))
f_35dB = 0.0000e+00 - 5.5232e+03i
disp(['35 dB Bandwidth: ', num2str(2*f_35dB)]);
35 dB Bandwidth: 0-11046.3327i
% Define frequency step size for numerical integration
df = 0.001;
freq_range = -10:df:10;
% Calculate energy in each frequency band
energy_in_band = double(subs(ESD, w, 2*pi*freq_range)) * df;
% Find the bandwidth containing 99% of the energy
cumulative_energy = cumsum(energy_in_band);
desired_energy = 0.99 * max(cumulative_energy);
bandwidth_99percent_energy = 2 * freq_range(find(cumulative_energy >= desired_energy, 1, 'first'));
disp(['Bandwidth containing 99% of the energy: ', num2str(bandwidth_99percent_energy)]);
Bandwidth containing 99% of the energy: 19.506

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by