Commit b676791c authored by 袁通's avatar 袁通
Browse files

update

parent 255a6c99
Loading
Loading
Loading
Loading
+0 −13
Original line number Diff line number Diff line
@@ -46,17 +46,10 @@ x2=(-b2+d2^0.5)/(2*a2);
% N: 501
% Peak 1: 13160
% Peak 2: 6938
<<<<<<< Updated upstream
% alpha: 0.7

N = 501;
yo2 = filter(1, [1 zeros(1, N-1) x2], y2);
=======
% alpha: 0.1 Too small, the peak is fake !!!!!
N = 500;
alpha = 0.1;
yo2 = filter(1, [1 zeros(1, N-1) alpha], y2);
>>>>>>> Stashed changes
sound(yo2, 8192);

% For y3 ----------------------------------------
@@ -79,14 +72,8 @@ saveas(gcf, "plots/P2_10_f_out1_3.png");

N = 751;
N1 = 2252;
<<<<<<< Updated upstream
alpha1 = 0.75;
alpha2 = 0.6;
b = [1 zeros(1, 750) alpha1 zeros(1, 1500) alpha2] ;
=======
alpha = 0.5;
alpha1 = 0.28;
b = [1 zeros(1, N-1) alpha zeros(1, N1-1)] + [1 zeros(1, N1-1) alpha1 zeros(1, N-1)];
>>>>>>> Stashed changes
yo3 = filter(1, b, y3);
sound(yo3, 8192);
 No newline at end of file

LAB4/P4_2_all.asv

deleted100644 → 0
+0 −69
Original line number Diff line number Diff line
% 4.2(a)

% 4.2(b)
tau = 0.01
T = 10
N = T/tau

t = [0:tau:T-tau]
y = exp(-2 * abs(t-5))

%4.2(c)
Y = fftshift(tau*fft(y))

%4.2(d)
w = -(pi/tau)+(0:N-1)*(2*pi/(N*tau))

%4.2(e)
X = exp(j*5*w).*Y

%4.2(f)
magnitudeX_app = abs(X)
phaseX_app = angle(X)

x = exp(-2 * abs(t))
X2 = fftshift(tau * fft(x))
magnitudeX = abs(X2)
phaseX = angle(X2)

% plot(t, x, 'g');
% hold on;
% plot(t, y, 'b');

figure;
subplot(2, 1, 1)
hold on
plot(w, magnitudeX_app , 'g')
plot(w, magnitudeX, 'b')
legend('|X| by approximation', '|X|', 'Location', 'northeast');
title('magnitude of X and approximation of X');
subplot(2, 1, 2)
hold on
plot(w, phaseX_app, 'g')
plot(w, phaseX, 'b')
legend('|X| by approximation', '|X|', 'Location', 'northeast');
title('phase of X and approximation of X');
saveas(gcf, "plots/P4_2_f_out1.png")
close

%4.2(g)
magnitudeY = abs(Y)
phaseY = angle(Y)

figure;
subplot(2, 1, 1)
hold on
plot(w, magnitudeY , 'g')
plot(w, magnitudeX, 'b')
legend('Y', 'X', 'Location', 'northeast');
title('magnitude of X and Y');
subplot(2, 1, 2)
hold on
plot(w, phaseY, 'g')
plot(w, phaseX, 'b')
legend('Y', 'X', 'Location', 'northeast');
title('phase of X and Y');
saveas(gcf, "plots/P4_2_f_out2.png")
close

+7 −13
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ y = exp(-2 * abs(t-5))
%4.2(c)
Y = fftshift(tau*fft(y))

%4.2(d)
%4.2(d
w = -(pi/tau)+(0:N-1)*(2*pi/(N*tau))

%4.2(e)
@@ -26,21 +26,15 @@ X2 = fftshift(tau * fft(x))
magnitudeX = abs(X2)
phaseX = angle(X2)

% plot(t, x, 'g');
% hold on;
% plot(t, y, 'b');

figure;
subplot(2, 1, 1)
hold on
plot(w, magnitudeX_app , 'g')
plot(w, magnitudeX, 'b')
semilogy(w, magnitudeX_app , w, magnitudeX)
legend('|X| by approximation', '|X|', 'Location', 'northeast');
title('magnitude of X and approximation of X');
subplot(2, 1, 2)
hold on
plot(w, phaseX_app, 'g')
plot(w, phaseX, 'b')
semilogy(w, phaseX_app, w, phaseX)
legend('|X| by approximation', '|X|', 'Location', 'northeast');
title('phase of X and approximation of X');
saveas(gcf, "plots/P4_2_f_out1.png")
@@ -53,14 +47,14 @@ phaseY = angle(Y)
figure;
subplot(2, 1, 1)
hold on
plot(w, magnitudeY , 'g')
plot(w, magnitudeX, 'b')
semilogy(w, magnitudeY , 'g')
semilogy(w, magnitudeX, 'b')
legend('Y', 'X', 'Location', 'northeast');
title('magnitude of X and Y');
subplot(2, 1, 2)
hold on
plot(w, phaseY, 'g')
plot(w, phaseX, 'b')
semilogy(w, phaseY, 'g')
semilogy(w, phaseX, 'b')
legend('Y', 'X', 'Location', 'northeast');
title('phase of X and Y');
saveas(gcf, "plots/P4_2_f_out2.png")

LAB4/P4_3_all.m

deleted100644 → 0
+0 −5
Original line number Diff line number Diff line
%4.3(a)

a = [1 1.5 0.5]
b = [1 -2]
[b1 a1] = freqz(b, a)
 No newline at end of file

LAB4/P4_5_all.m

0 → 100644
+40 −0
Original line number Diff line number Diff line
% 4.5(a)

a1 = [1 1.5 0.5]
b1 = [1 -2]

% 4.5(b)
[r1, p1] = residue(b1, a1)

% r1 = [6, -5]
% p1 = [-1, -0.5]

% 4.5(c)

% 4.5(d)
a2 = [1 7 16 12]
b2 = [3 10 5]

[r2, p2] = residue(b2, a2)

% r2 = [2 1 -3]
% p2 = [-3 -2 -2]

% 4.5(e)

% 4.5(g)

a3 = [1 -4]
b3 = [-4]

% 4.5(h)
[r3, p3] = residue(b3, a3)

% r3 = [-4]
% p3 = [4]
% 4.5(i)




   
Loading