Draw amplitude spectrum of filter

4 次查看(过去 30 天)
Hoa Luong
Hoa Luong 2022-11-8
回答: Amith 2024-8-19
i want to draw a amplitude spectrum of filter that has an amplitude of 5 in the range [0, 1] ; -20 (dB/octave) attenuation in
(1,6] and -60 (dB/octave) in the range (6, ...)

回答(1 个)

Amith
Amith 2024-8-19
Hi Hoa Luong,
Find the MATLAB code below according to the specification requested where there is an amplitude of 5 in the range [0, 1], -20 dB/octave attenuation in the range (1, 6], and -60 dB/octave attenuation in the range (6, …):
% Define the frequency range
f = logspace(-1, 2, 1000); % Frequency range from 0.1 to 100 Hz
% Initialize the amplitude spectrum
A = zeros(size(f));
% Define the amplitude spectrum
A(f <= 1) = 5; % Amplitude of 5 in the range [0, 1]
A(f > 1 & f <= 6) = 5 * (f(f > 1 & f <= 6) / 1).^(-20/20); % -20 dB/octave attenuation in (1, 6]
A(f > 6) = 5 * (6 / 1).^(-20/20) * (f(f > 6) / 6).^(-60/20); % -60 dB/octave attenuation in (6, ...)
% Plot the amplitude spectrum
figure;
semilogx(f, A, 'LineWidth', 2);
xlabel('Frequency (Hz)');
ylabel('Amplitude');
title('Amplitude Spectrum of the Filter');
grid on;
The graph yielded from the above MATLAB code is:
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Octave 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by