Draw amplitude spectrum of filter

4 visualizzazioni (ultimi 30 giorni)
Hoa Luong
Hoa Luong il 8 Nov 2022
Risposto: Amith il 19 Ago 2024
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, ...)

Risposte (1)

Amith
Amith il 19 Ago 2024
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!

Community Treasure Hunt

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

Start Hunting!

Translated by