Подробно реши первый номер, ответ на английском, к...
Créé le : 1 décembre 2025
Répondu en utilisant GPT-5.1 Thinking par Chat01
Créé le : 1 décembre 2025
Répondu en utilisant GPT-5.1 Thinking par Chat01
Here is a detailed solution for Problem 1 (in English) with MATLAB code at the end. (HW3_2025.pdf)
We want a digital Chebyshev type I lowpass filter obtained via impulse invariance from an analog prototype.
Given:
Tasks:
We first convert the passband and stopband edges from Hz to rad/s:
In MATLAB:
matlabFp = 18e6; % passband edge in Hz Fstop = 20e6; % stopband edge in Hz Fs = 50e6; % sampling frequency in Hz Wp = 2*pi*Fp; % rad/s Ws = 2*pi*Fstop; % rad/s Rp = 0.3; % passband ripple (dB) Rs = 60; % stopband attenuation (dB)
For a type I Chebyshev analog lowpass, the minimum order that meets the specs is
Numerically (already pre-computed):
This gives approximately:
The filter order must be an integer, so we choose:
In MATLAB we let cheb1ord do that for us and also return the necessary edge frequency:
matlab[N, Wc] = cheb1ord(Wp, Ws, Rp, Rs, 's'); % 's' → analog design % N will come out as 20 % Wc is the resulting passband edge (cutoff) in rad/s
We now design the analog Chebyshev type I lowpass filter:
In MATLAB:
matlab[Ba, Aa] = cheby1(N, Rp, Wc, 's'); % analog Chebyshev I lowpass
Ba and Aa are the numerator and denominator polynomials in .
Let be the impulse response of the analog filter .
Impulse invariance constructs a discrete-time filter whose impulse response is
So the discrete-time impulse is simply the sampled analog impulse, scaled by . The mapping in pole–residue form:
If
then after impulse invariance,
and the discrete-time transfer function becomes
In MATLAB we don’t have to do this by hand; we use impinvar:
matlabT = 1/Fs; [Bd, Ad] = impinvar(Ba, Aa, Fs); % digital filter coefficients
So the digital filter is
with Bd containing and Ad containing .
Using partial fraction expansion:
(For our proper filter, there is no polynomial term.)
Then
We can compute this with residue and evaluate at a chosen time grid .
In MATLAB:
matlab% Time axis for viewing the analog impulse response tmax = 4e-6; % 4 microseconds (adjust as needed) Nt = 2000; t = linspace(0, tmax, Nt); % Partial fraction expansion for analog filter [r, p, k] = residue(Ba, Aa); % Ba/Aa in s-domain % Analog impulse response h_a(t) = sum r_k e^{p_k t}, k is empty for proper LPF ha = zeros(size(t)); for i = 1:length(r) ha = ha + r(i)*exp(p(i)*t); end
We use impz:
matlabL = 200; % number of samples to show [hd, n] = impz(Bd, Ad, L); % digital impulse response t_samples = n / Fs; % map discrete-time index to seconds
If you want to directly check impulse invariance:
matlab% Sample the analog impulse at the same instants n*T t_n = n / Fs; ha_samples = zeros(size(t_n)); for i = 1:length(r) ha_samples = ha_samples + r(i)*exp(p(i)*t_n); end hd_theoretical = T * ha_samples; % should match hd up to numerical error
We use freqs to evaluate over a frequency range 0 to .
matlabNfreq = 2048; w_max = 2*pi*(Fs/2); % up to Nyquist frequency in rad/s w = linspace(0, w_max, Nfreq); % analog rad/s [Ha, ~] = freqs(Ba, Aa, w); fa = w/(2*pi); % Hz Ha_dB = 20*log10(abs(Ha));
We use freqz with sampling frequency Fs (this makes the frequency vector in Hz):
matlab[Hd, fd] = freqz(Bd, Ad, Nfreq, Fs); % fd in Hz Hd_dB = 20*log10(abs(Hd));
Now we can plot both analog and digital magnitude responses on the same frequency axis (in MHz).
matlab%% Problem 1: Chebyshev I LPF via Impulse Invariance clear; clc; close all; %% Given specifications Fp = 18e6; % passband edge in Hz Fstop = 20e6; % stopband edge in Hz Fs = 50e6; % sampling frequency in Hz Rp = 0.3; % passband ripple in dB Rs = 60; % stopband attenuation in dB T = 1/Fs; % sampling period %% 1) Analog Chebyshev I lowpass design % Convert to rad/s Wp = 2*pi*Fp; Ws = 2*pi*Fstop; % Find minimum order and cutoff [N, Wc] = cheb1ord(Wp, Ws, Rp, Rs, 's'); fprintf('Analog Chebyshev-I order N = %d\n', N); % Design analog filter [Ba, Aa] = cheby1(N, Rp, Wc, 's'); % analog lowpass H_a(s) = Ba(s)/Aa(s) %% 2) Impulse invariance to get digital filter [Bd, Ad] = impinvar(Ba, Aa, Fs); % digital H_d(z) via impulse invariance %% 3) Impulse responses % --- Analog impulse response h_a(t) using partial fractions --- tmax = 4e-6; % end time (seconds) to view analog impulse Nt = 2000; t = linspace(0, tmax, Nt); % Partial fraction expansion in s-domain [r, p, k] = residue(Ba, Aa); %#ok<ASGLU> k should be empty for proper LPF % h_a(t) = sum r_k * exp(p_k * t) ha = zeros(size(t)); for i = 1:length(r) ha = ha + r(i).*exp(p(i).*t); end % --- Digital impulse response h_d[n] --- L = 200; % number of samples to plot [hd, n] = impz(Bd, Ad, L); % discrete-time impulse response t_samples = n/Fs; % map discrete index to seconds % Optional: check impulse invariance (T * h_a(nT) vs hd) ha_nT = zeros(size(n)); for i = 1:length(r) ha_nT = ha_nT + r(i).*exp(p(i).*t_samples); end hd_theoretical = T * ha_nT; %% 4) Plot impulse responses (analog and digital) figure; subplot(2,1,1); plot(t*1e6, ha, 'LineWidth', 1.2); grid on; xlabel('Time \mu s'); ylabel('h_a(t)'); title('Analog impulse response'); subplot(2,1,2); stem(t_samples*1e6, hd, 'filled'); grid on; xlabel('Time \mu s'); ylabel('h_d[n]'); title('Digital impulse response (impulse invariance)'); % (Optional overlay to visually compare T*h_a(nT) and h_d[n]) figure; stem(t_samples*1e6, hd, 'filled'); hold on; plot(t_samples*1e6, hd_theoretical, 'r--', 'LineWidth', 1.2); grid on; xlabel('Time \mu s'); ylabel('Amplitude'); legend('h_d[n]', 'T \cdot h_a(nT)', 'Location', 'best'); title('Check of impulse invariance: discrete vs sampled analog'); %% 5) Magnitude responses for analog and digital filters Nfreq = 2048; w_max = 2*pi*(Fs/2); % 0 to Nyquist (rad/s) w = linspace(0, w_max, Nfreq); % analog rad/s frequencies [Ha, ~] = freqs(Ba, Aa, w); % analog frequency response fa = w/(2*pi); % Hz Ha_dB = 20*log10(abs(Ha)); [Hd, fd] = freqz(Bd, Ad, Nfreq, Fs); % digital frequency response, fd in Hz Hd_dB = 20*log10(abs(Hd)); % Plot magnitude responses (in dB) vs frequency in MHz figure; plot(fa/1e6, Ha_dB, 'LineWidth', 1.2); hold on; plot(fd/1e6, Hd_dB, '--', 'LineWidth', 1.2); grid on; xlabel('Frequency (MHz)'); ylabel('Magnitude (dB)'); title('Magnitude responses: analog vs digital'); legend('Analog H_a(j\Omega)', 'Digital H_d(e^{j\omega})', 'Location', 'best'); % Optionally highlight passband/stopband edges xline(Fp/1e6, 'g--', '18 MHz'); xline(Fstop/1e6, 'r--', '20 MHz');
If you want, next we can also derive the difference equation for the digital filter from Bd and Ad, but for Problem 1 the main requirements are the filter design and the impulse/frequency plots.
напиши код на матлабе для графиков второго задания.
Вот готовый MATLAB-код, который строит импульсные и частотные характеристики для Задачи 2 (аналоговый фильтр и его цифровой прототип по билинейному преобразованию, Гц). (HW3_2025.pdf)
matlab%% Problem 2: Plots for analog & digital filters (bilinear transform) clear; clc; close all; %% Given data Fs = 20; % sampling frequency in Hz T = 1/Fs; % sampling period % Analog transfer function: % H(s) = (s + 2) / (s^2 + s + 1) Ba = [1 2]; % numerator in s Aa = [1 1 1]; % denominator in s %% Digital filter via bilinear transform % H(z) is the digital prototype of H(s) [Bd, Ad] = bilinear(Ba, Aa, Fs); % requires Signal Processing Toolbox %% ================== IMPULSE RESPONSES ================== % ---- Analog impulse response h_a(t) via partial fractions ---- t_max = 3; % seconds, adjust as needed Nt = 2000; % number of time points t = linspace(0, t_max, Nt); [r, p, k] = residue(Ba, Aa); % partial fraction expansion in s ha = zeros(size(t)); for i = 1:length(r) ha = ha + r(i) .* exp(p(i).*t); end if ~isempty(k) % if there were a direct term (here there shouldn't be, but just in case) ha = ha + k(1)*ones(size(t)); end % ---- Digital impulse response h_d[n] ---- L = 80; % number of samples to show [hd, n] = impz(Bd, Ad, L); % discrete-time impulse response t_d = n*T; % map sample index n to time nT (seconds) % ---- Plot impulse responses ---- figure; subplot(2,1,1); plot(t, ha, 'LineWidth', 1.2); grid on; xlabel('t (s)'); ylabel('h_a(t)'); title('Analog impulse response'); subplot(2,1,2); stem(t_d, hd, 'filled'); grid on; xlabel('t = nT (s)'); ylabel('h_d[n]'); title('Digital impulse response (bilinear transform)'); %% ================== FREQUENCY RESPONSES ================== Nf = 1024; % number of frequency points % ---- Analog magnitude response ---- % For comparison with the digital filter we usually look up to pi/T rad/s w_max = pi/T; % max analog rad/s w = linspace(0, w_max, Nf); % rad/s [Ha, ~] = freqs(Ba, Aa, w); % analog freq response H(jΩ) fa = w/(2*pi); % convert rad/s to Hz % ---- Digital magnitude response ---- [Hd, fd] = freqz(Bd, Ad, Nf, Fs); % digital freq response, fd in Hz % ---- Plot magnitude responses (linear scale) ---- figure; plot(fa, abs(Ha), 'LineWidth', 1.2); hold on; plot(fd, abs(Hd), '--', 'LineWidth', 1.2); grid on; xlabel('Frequency (Hz)'); ylabel('|H(j\Omega)|, |H(e^{j\omega})|'); title('Magnitude responses: analog vs digital'); legend('Analog', 'Digital', 'Location', 'best'); % ---- Plot magnitude responses (dB) ---- figure; plot(fa, 20*log10(abs(Ha)+eps), 'LineWidth', 1.2); hold on; plot(fd, 20*log10(abs(Hd)+eps), '--', 'LineWidth', 1.2); grid on; xlabel('Frequency (Hz)'); ylabel('Magnitude (dB)'); title('Magnitude responses (dB): analog vs digital'); legend('Analog', 'Digital', 'Location', 'best');
Если нужно, могу отдельно выписать разностное уравнение для цифрового фильтра из коэффициентов Bd и Ad.