Подробно реши пятое задание из прикрепленного файл...
Creato il: 1 dicembre 2025
Risposto usando GPT-5.1 Thinking da Chat01
Creato il: 1 dicembre 2025
Risposto usando GPT-5.1 Thinking da Chat01
Подробно реши пятое задание из прикрепленного файла. Ответ на английском, подробное описание. код в матлабе
We solve Problem 5 (CORDIC) from your PDF: compute
a) arctan(1.1)
b) abs(1.2 + 2.1j)
using a 10-step CORDIC algorithm, justify the method, and compare with the exact values. (HW3_2025.pdf)
CORDIC computes trig functions and vector operations using only:
α_i = atan(2⁻ᶦ)There are two modes:
For this problem we use vectoring mode, because:
atan(1.1) we start with a vector whose slope is 1.1 and drive y → 0.|1.2 + 2.1j| we start with vector (x, y) = (1.2, 2.1) and again drive y → 0. The final x (after scaling correction) is the magnitude.Precompute the list of angles:
where here N = 10.
CORDIC vectoring mode updates:
Initialize
For each iteration :
Choose direction
Update
After enough iterations:
so
Equivalently, define
and then
We will use this form in code.
We want .
Choose initial vector with slope 1.1:
Run the 10-step vectoring algorithm.
(Values rounded to 6 decimal digits.)
Let .
| i | yi sign | xi+1 | yi+1 | zi+1 (rad) |
|---|---|---|---|---|
| 0 | y₀ > 0 | 2.100000 | 0.100000 | 0.785398 |
| 1 | y₁ > 0 | 2.150000 | −0.950000 | 1.249046 |
| 2 | y₂ < 0 | 2.387500 | −0.412500 | 1.004067 |
| 3 | y₃ < 0 | 2.439063 | −0.114062 | 0.879712 |
| 4 | y₄ < 0 | 2.446191 | 0.038379 | 0.817293 |
| … | … | … | … | … |
| 9 | y₉ < 0 | 2.448079 | −0.004605 | 0.834862 |
After 10 iterations:
This is our CORDIC approximation:
Exact value (as computed by high-precision math / MATLAB atan):
Error:
In degrees:
So 10 iterations already give ~3 decimal digits of accuracy for the angle.
We treat the complex number as a 2D vector:
Run the same vectoring algorithm. After 10 iterations we obtain some with . Because of the accumulated scaling,
with
Numerically (10 iterations):
Exact magnitude:
Error:
So the CORDIC magnitude after 10 steps is accurate to at least 6 decimal digits.
(As a bonus, the same run also gives the phase
, close to the exact .)
Angle decomposition:
Any angle can be represented (approximately) as a sum of signed micro-angles:
with .
With vectoring mode, the algorithm automatically chooses the signs so that the vector converges to the x-axis, and becomes that sum.
Shift-add hardware efficiency:
Because each micro-rotation uses factors , we need only shifts and adds (no multipliers!). CORDIC is historically important in hardware (FPGA, ASIC, DSP).
Convergence:
Each step reduces the magnitude of roughly by a factor of ~2. Hence, after N steps, the angle error is on the order of . With N = 10, error is roughly , consistent with our numerical results.
Fixed gain:
The overall gain depends only on N, not on the input. We can precompute the correction factor once and reuse it for all inputs to recover the proper magnitude.
Below is self-contained MATLAB code that:
arctan(1.1) with 10 CORDIC iterationsabs(1.2 + 2.1j) using CORDICatan and absmatlab%% HW3 – Problem 5: CORDIC implementation (10 steps) % Computes: % (a) arctan(1.1) % (b) abs(1.2 + 2.1j) % using 10-step CORDIC in vectoring mode. clear; clc; N = 10; % number of CORDIC iterations %% (a) CORDIC approximation of arctan(1.1) y_over_x = 1.1; [theta_cordic, xN_atan, yN_atan] = cordic_arctan_ratio(y_over_x, N); theta_true = atan(y_over_x); fprintf('--- Part (a): arctan(1.1) ---\n'); fprintf('CORDIC (10 steps): theta = %.12f rad\n', theta_cordic); fprintf('True value : theta = %.12f rad\n', theta_true); fprintf('Absolute error : %.12e rad\n', theta_cordic - theta_true); fprintf('Degrees (CORDIC) : %.6f deg\n', theta_cordic * 180/pi); fprintf('Degrees (true) : %.6f deg\n\n', theta_true * 180/pi); %% (b) CORDIC approximation of abs(1.2 + 2.1j) x0 = 1.2; % real part y0 = 2.1; % imaginary part [r_cordic, theta_vec, xN_vec, yN_vec] = cordic_polar(x0, y0, N); r_true = abs(1.2 + 2.1j); theta_true_vec = atan2(y0, x0); fprintf('--- Part (b): abs(1.2 + 2.1j) ---\n'); fprintf('CORDIC (10 steps): r = %.12f\n', r_cordic); fprintf('True value : r = %.12f\n', r_true); fprintf('Absolute error : %.12e\n', r_cordic - r_true); fprintf('Relative error : %.12e\n\n', (r_cordic - r_true)/r_true); fprintf('CORDIC angle : theta = %.12f rad (%.6f deg)\n', ... theta_vec, theta_vec * 180/pi); fprintf('True angle : theta = %.12f rad (%.6f deg)\n', ... theta_true_vec, theta_true_vec * 180/pi); %% --- Local functions --- function [theta, xN, yN] = cordic_arctan_ratio(y_over_x, N) % CORDIC in vectoring mode to compute atan(y_over_x) % We choose x0 = 1, y0 = y_over_x, so theta = atan(y0/x0) = atan(y_over_x). % Precompute elementary angles alpha_i = atan(2^-i) alpha = atan(2.^-(0:N-1)); x = 1; % x0 y = y_over_x; % y0 z = 0; % z0 for i = 0:N-1 if y >= 0 d = 1; else d = -1; end % Pseudo-rotation in vectoring mode x_new = x + d * y * 2^(-i); y_new = y - d * x * 2^(-i); z_new = z + d * alpha(i+1); x = x_new; y = y_new; z = z_new; end theta = z; % approximate atan(y_over_x) xN = x; yN = y; end function [r, theta, xN, yN] = cordic_polar(x0, y0, N) % CORDIC in vectoring mode to convert (x0, y0) to (r, theta) % Output: % r ~ sqrt(x0^2 + y0^2) % theta ~ atan2(y0, x0) alpha = atan(2.^-(0:N-1)); x = x0; y = y0; z = 0; for i = 0:N-1 if y >= 0 d = 1; else d = -1; end x_new = x + d * y * 2^(-i); y_new = y - d * x * 2^(-i); z_new = z + d * alpha(i+1); x = x_new; y = y_new; z = z_new; end % CORDIC gain correction: K_N = prod(1/sqrt(1 + 2^(-2i))) K = prod(1 ./ sqrt(1 + 2.^(-2*(0:N-1)))); r = K * x; % correct the scale to recover magnitude theta = z; % accumulated angle xN = x; yN = y; end
You can paste this into a file like hw3_problem5_cordic.m, run it in MATLAB, and it will print the CORDIC results and their errors compared to MATLAB’s exact functions.
Подробно реши третье задание из прикрепленного файла. Ответ на английском, подробное описание.
We’re solving Problem 3 from your PDF: (HW3_2025.pdf)
A filter has the transfer function
.
Determine the impulse response of the filter with the modified frequency response
.
The transfer function of an LTI discrete-time system is
Given
we can directly read off the impulse response :
The frequency response of this system is the DTFT of :
We’re told the new system has frequency response
So the new system is just the old system, but with its frequency response shifted in frequency by .
To find the impulse response of this new filter, we use a standard DTFT property.
Recall the DTFT pair:
The frequency-shift (modulation) property says:
In words:
Multiplying a time-domain signal by shifts its spectrum to the right by .
Apply this to our case:
By the property above, we simply take
Then
exactly as required.
We already know
So
Compute term by term:
Numerically,
so
We know , , so
Note that , so
Hence
Numerically,
so
(if you compute with higher precision you might get slightly different last digits; another equivalent approximate value is depending on rounding).
(You don’t really need the decimal values in an exam — the exponential form is usually enough.)
The impulse response of the filter with modified frequency response
is
where is the original impulse response:
Explicitly,
This sequence is the impulse response of the new, frequency-shifted filter.
напиши код на матлабе для построения требуемых графиков, отдельно для номера 2, отдельно для номера 4. Ответ на английском
Here’s MATLAB code for Problem 2 and Problem 4 as two separate pieces, each building only the plots that the assignment asks for (impulse and frequency responses). (HW3_2025.pdf)
Assuming the analog transfer function is
and the digital version is obtained by the bilinear transform with sampling frequency Fs = 20 Hz.
matlab%% Problem 2 – Impulse and Frequency Responses (Analog vs Digital) clear; clc; close all; %% Analog filter H(s) = (s + 2) / (s^2 + s + 1) numA = [1 2]; % numerator in s denA = [1 1 1]; % denominator in s Fs = 20; % sampling frequency [Hz] T = 1/Fs; %% (a) Impulse response (analog vs digital) % --- Analog impulse response (continuous time) --- t_end = 3; % seconds (choose as you like) t = linspace(0, t_end, 2000); % time vector for analog response [hA, tA] = impulse(numA, denA, t); % analog impulse response % --- Digital filter via bilinear transform --- % Bilinear transform: s = 2*Fs * (1 - z^-1) / (1 + z^-1) [bz, az] = bilinear(numA, denA, Fs); % digital filter coefficients N = 60; % number of digital samples to show [hd, n] = impz(bz, az, N); % digital impulse response % Plot impulse responses figure; subplot(2,1,1); plot(tA, hA, 'LineWidth', 1.5); grid on; xlabel('Time t [s]'); ylabel('h_A(t)'); title('Analog Impulse Response'); subplot(2,1,2); stem(n*T, hd, 'filled'); % plot vs time in seconds for comparison grid on; xlabel('Time t = nT [s]'); ylabel('h_D[n]'); title('Digital Impulse Response (Bilinear, Fs = 20 Hz)'); %% (b) Frequency response (analog vs digital) % --- Analog frequency response using freqs (continuous-time) --- % Angular frequency vector (rad/s) wA = linspace(0, 2*pi*Fs, 2048); % up to some convenient max freq HA = freqs(numA, denA, wA); % analog frequency response fA = wA / (2*pi); % convert rad/s to Hz % --- Digital frequency response using freqz --- % H_D(e^{j\omega}) over [0, Fs/2] Hz [HD, fD] = freqz(bz, az, 2048, Fs); % fD is in Hz % Plot magnitude responses (in dB) figure; subplot(2,1,1); plot(fA, 20*log10(abs(HA) + eps), 'LineWidth', 1.5); grid on; xlabel('Frequency [Hz]'); ylabel('|H_A(j\omega)| [dB]'); title('Analog Magnitude Response'); subplot(2,1,2); plot(fD, 20*log10(abs(HD) + eps), 'LineWidth', 1.5); grid on; xlabel('Frequency [Hz]'); ylabel('|H_D(e^{j\omega})| [dB]'); title('Digital Magnitude Response (Bilinear, Fs = 20 Hz)');
You can put this as a single script (e.g., problem2_plots.m). It:
numA, denAWe rewrite in terms of powers of :
So the discrete-time filter coefficients (for use with impz, freqz, filter) are:
Here is the MATLAB code to plot the impulse and frequency responses.
matlab%% Problem 4 – Impulse and Frequency Responses of H(z) = (z + 1)/(z^3 + 2z^2 + 3z + 4) clear; clc; close all; % Given transfer function: % H(z) = (z + 1) / (z^3 + 2 z^2 + 3 z + 4) % Rewrite in powers of z^-1: % H(z) = (z^-2 + z^-3) / (1 + 2 z^-1 + 3 z^-2 + 4 z^-3) b = [0 0 1 1]; % numerator coefficients in z^-1 a = [1 2 3 4]; % denominator coefficients in z^-1 %% (a) Impulse response N = 50; % number of samples of impulse response [h, n] = impz(b, a, N); % discrete-time impulse response figure; stem(n, h, 'filled'); grid on; xlabel('n'); ylabel('h[n]'); title('Impulse Response of H(z)'); %% (b) Frequency response Nfft = 1024; % FFT points for freqz [H, w] = freqz(b, a, Nfft); % w in rad/sample figure; subplot(2,1,1); plot(w/pi, abs(H), 'LineWidth', 1.5); grid on; xlabel('Normalized Frequency (\omega/\pi)'); ylabel('|H(e^{j\omega})|'); title('Magnitude Response of H(z)'); subplot(2,1,2); plot(w/pi, angle(H), 'LineWidth', 1.5); grid on; xlabel('Normalized Frequency (\omega/\pi)'); ylabel('Phase [rad]'); title('Phase Response of H(z)');
You can save this as something like problem4_plots.m.
If you also need the difference equation or block diagrams (Direct-Form I / II) later, I can write those out too, but this code already produces all the plots the assignment asks for in Problem 4.
Подробно реши первое задание из прикрепленного файла. Ответ на английском, подробное описание. код в матлабе.
We need to design a Chebyshev lowpass digital filter using the impulse invariance method, with specs: (HW3_2025.pdf)
Then:
We first design a continuous-time (analog) Chebyshev Type I lowpass filter that meets the given specs.
These are used in the analog filter design.
Passband ripple and stopband attenuation :
The minimum filter order for a Chebyshev Type I lowpass is
For the given numbers, this gives approximately
(in practice, MATLAB’s cheb1ord will compute the exact minimum integer order.)
In MATLAB, we don’t have to compute these by hand; we can use:
matlab[Na, Wp_analog] = cheb1ord(Wp, Ws, Rp, Rs, 's');
This returns the required analog filter order Na (which should be about 20) and an adjusted analog passband edge Wp_analog.
We then design the analog Chebyshev lowpass transfer function:
with MATLAB:
matlab[ba, aa] = cheby1(Na, Rp, Wp_analog, 'low', 's');
ba and aa are vectors of numerator and denominator coefficients of .The impulse invariance method defines the digital impulse response as:
where:
If the analog transfer function has partial fraction expansion
then:
Taking the Z-transform:
So every analog pole maps to a digital pole at , preserving the shape of the impulse response between 0 and Nyquist (but causing aliasing of higher-frequency components).
In MATLAB, this mapping is implemented by:
matlab[bd, ad] = impinvar(ba, aa, Fs);
This directly produces the digital filter:
Analog impulse response is obtained by:
matlab[ha, t] = impulse(ba, aa, t_vec);
Digital impulse response is obtained by:
matlab[hd, n] = impz(bd, ad, N_imp);
If designed correctly, you should see that
for the plotted time window (this is the core idea of impulse invariance).
For the analog filter, the frequency response is
We compute it over a set of angular frequencies (rad/s):
matlabwA = linspace(0, 2*pi*25e6, 2000); % up to Nyquist (25 MHz) HA = freqs(ba, aa, wA); % analog frequency response fA = wA / (2*pi); % convert to Hz
We can then plot in linear scale or dB.
The digital filter’s DTFT is . Using freqz with sampling frequency Fs:
matlab[HD, fD] = freqz(bd, ad, 2048, Fs); % fD in Hz, range 0..Fs/2
This computes the digital magnitude response on , directly comparable with the analog response.
This script:
matlab%% Problem 1 – Chebyshev LPF via Impulse Invariance % Specs: % Passband edge: fp = 18 MHz % Stopband edge: fs = 20 MHz % Passband ripple: Rp = 0.3 dB % Stopband attenuation: Rs = 60 dB % Sampling freq: Fs = 50 MHz % % Tasks: % (a) Plot analog and digital impulse responses % (b) Plot analog and digital magnitude responses clear; clc; close all; %% Given specifications Fp = 50e6; % sampling frequency [Hz] T = 1/Fp; % sampling period [s] fp = 18e6; % analog passband edge [Hz] fs = 20e6; % analog stopband edge [Hz] Rp = 0.3; % passband ripple [dB] Rs = 60; % stopband attenuation [dB] % Convert to rad/s for analog design Wp = 2*pi*fp; % passband edge [rad/s] Ws = 2*pi*fs; % stopband edge [rad/s] %% Step 1: Analog Chebyshev Type I lowpass design % Find minimum order and passband edge for analog Chebyshev filter [Na, Wp_analog] = cheb1ord(Wp, Ws, Rp, Rs, 's'); fprintf('Analog Chebyshev Type I order Na = %d\n', Na); % Design analog lowpass filter H_a(s) [ba, aa] = cheby1(Na, Rp, Wp_analog, 'low', 's'); %% Step 2: Impulse invariance to obtain digital filter % Digital filter via impulse invariance [bd, ad] = impinvar(ba, aa, Fp); %% (a) Impulse responses: analog vs digital % Choose a time window for impulse response comparison N_imp = 200; % number of samples (discrete-time) t_imp = (0:N_imp-1)*T; % corresponding continuous times % Analog impulse response h_a(t) [ha, t_cont] = impulse(ba, aa, t_imp); % use same time grid as digital % Digital impulse response h_d[n] [hd, n] = impz(bd, ad, N_imp); % n = 0,1,...,N_imp-1 % Plot impulse responses figure; subplot(2,1,1); plot(t_cont*1e6, ha, 'LineWidth', 1.5); grid on; xlabel('Time t [\mus]'); ylabel('h_a(t)'); title('Analog Impulse Response (Chebyshev LPF)'); subplot(2,1,2); stem(n*T*1e6, hd, 'filled'); grid on; xlabel('Time t = nT [\mus]'); ylabel('h_d[n]'); title('Digital Impulse Response (Impulse Invariance)'); %% (b) Magnitude responses: analog vs digital % --- Analog magnitude response --- fA_max = 25e6; % plot up to Nyquist of digital system wA = linspace(0, 2*pi*fA_max, 2048); % angular frequency [rad/s] HA = freqs(ba, aa, wA); fA = wA/(2*pi); % Hz % --- Digital magnitude response --- [HD, fD] = freqz(bd, ad, 2048, Fp); % fD in Hz, 0..Fs/2 % Convert to MHz for nicer axis labels fA_MHz = fA / 1e6; fD_MHz = fD / 1e6; figure; subplot(2,1,1); plot(fA_MHz, 20*log10(abs(HA) + eps), 'LineWidth', 1.5); grid on; xlabel('Frequency [MHz]'); ylabel('|H_a(j\Omega)| [dB]'); title('Analog Chebyshev LPF Magnitude Response'); xline(fp/1e6, '--', 'f_p', 'LabelVerticalAlignment','bottom'); xline(fs/1e6, '--', 'f_s', 'LabelVerticalAlignment','bottom'); subplot(2,1,2); plot(fD_MHz, 20*log10(abs(HD) + eps), 'LineWidth', 1.5); grid on; xlabel('Frequency [MHz]'); ylabel('|H_d(e^{j\omega})| [dB]'); title('Digital LPF Magnitude Response (Impulse Invariance)'); xline(fp/1e6, '--', 'f_p', 'LabelVerticalAlignment','bottom'); xline(fs/1e6, '--', 'f_s', 'LabelVerticalAlignment','bottom'); %% Optional: check the impulse-invariance relation h_d[n] ≈ T * h_a(nT) % err = hd - T*ha(:); % fprintf('Max abs error between hd and T*ha(nT): %e\n', max(abs(err)));
cheb1ord + cheby1 with the given passband/stopband specs.impinvar (impulse invariance).You can put this into problem1_impulse_invariance.m or similar and run it in MATLAB.
Переделывай код, тупица!!! Analog Chebyshev Type I order Na = 20
Warning: The output is not correct/robust. Coeffs of B(s)/A(s) are real, but B(z)/A(z) has complex
coeffs. Probable cause is rooting of high-order repeated poles in A(s).
B(z) and A(z) have been forced to be real using real(A(z)) and real(B(z)).
In impinvar (line 130)
In problem1 (line 42)
Error using plot
Vectors must be the same length.
Error in problem1 (line 59)
plot(t_cont*1e6, ha, 'LineWidth', 1.5);