From e2d507070fcdb68fd0a2ad5bb5616fb8e15dd028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Tue, 10 Dec 2024 22:59:53 +0000 Subject: [PATCH] SM: Add missing files --- 2ano1/SM/aula03/calcCoef_complex.m | 14 + 2ano1/SM/aula03/ex03.m | 17 +- 2ano1/SM/aula03/ex05.m | 35 + 2ano1/SM/aula03/serie_exponencial.m | 19 + 2ano1/SM/aula03/serie_exponencial2.m | 13 + 2ano1/SM/aula07/Espetro.m | 15 + 2ano1/SM/aula07/ex01.m | 9 + 2ano1/SM/aula07/ex02.m | 12 + 2ano1/SM/aula07/ex03.m | 22 + 2ano1/SM/aula07/ex04.m | 38 + 2ano1/SM/aula07/respfreq.m | 6 + 2ano1/SM/aula08/Alfabeto1.m | 3 + 2ano1/SM/aula08/Alfabeto2.m | 4 + 2ano1/SM/aula08/Entropia.m | 6 + 2ano1/SM/aula08/NumeroBitsCodigo2.m | 20 + 2ano1/SM/aula08/ex01.m | 3 + 2ano1/SM/aula08/ex02.m | 3 + 2ano1/SM/aula08/ex03.m | 6 + 2ano1/SM/aula08/ex04.m | 3 + 2ano1/SM/aula08/ex05.excalidraw | 723 ++++++++++++++++++ 2ano1/SM/aula08/ex06.m | 3 + 2ano1/SM/pratico1-2022/ex01d.m | 23 + 2ano1/SM/pratico1-2022/tempo_espetro.m | 42 + .../Espetro.m | 15 + .../Reconstroi.m | 12 + .../teste-1-2023-2024-Turma-Anterior/ex02.m | 52 ++ .../teste-1-2023-2024-Turma-Anterior/exame.p | Bin 0 -> 503 bytes 2ano1/SM/teste-1-2023-2024/Reconstroi.m | 12 + 2ano1/SM/teste-1-2023-2024/calcCoef_complex.m | 10 + 2ano1/SM/teste-1-2023-2024/ex01.m | 23 + 2ano1/SM/teste-1-2023-2024/ex02.m | 97 +++ 2ano1/SM/teste-1-2023-2024/exame.p | Bin 0 -> 503 bytes .../Espetro.m | 15 + .../teste-2-2023-2024-Turma-Anterior/exame2.p | Bin 0 -> 434 bytes .../resolucao.m | 62 ++ .../respfreq.m | 6 + 2ano1/SM/teste-2-2023-2024/Espetro.m | 15 + 2ano1/SM/teste-2-2023-2024/exame2.p | Bin 0 -> 434 bytes 2ano1/SM/teste-2-2023-2024/resolucao.m | 65 ++ 2ano1/SM/teste-2-2023-2024/respfreq.m | 6 + 40 files changed, 1423 insertions(+), 6 deletions(-) create mode 100644 2ano1/SM/aula03/calcCoef_complex.m create mode 100644 2ano1/SM/aula03/ex05.m create mode 100644 2ano1/SM/aula03/serie_exponencial.m create mode 100644 2ano1/SM/aula03/serie_exponencial2.m create mode 100644 2ano1/SM/aula07/Espetro.m create mode 100644 2ano1/SM/aula07/ex01.m create mode 100644 2ano1/SM/aula07/ex02.m create mode 100644 2ano1/SM/aula07/ex03.m create mode 100644 2ano1/SM/aula07/ex04.m create mode 100644 2ano1/SM/aula07/respfreq.m create mode 100644 2ano1/SM/aula08/Alfabeto1.m create mode 100644 2ano1/SM/aula08/Alfabeto2.m create mode 100644 2ano1/SM/aula08/Entropia.m create mode 100644 2ano1/SM/aula08/NumeroBitsCodigo2.m create mode 100644 2ano1/SM/aula08/ex01.m create mode 100644 2ano1/SM/aula08/ex02.m create mode 100644 2ano1/SM/aula08/ex03.m create mode 100644 2ano1/SM/aula08/ex04.m create mode 100644 2ano1/SM/aula08/ex05.excalidraw create mode 100644 2ano1/SM/aula08/ex06.m create mode 100644 2ano1/SM/pratico1-2022/ex01d.m create mode 100644 2ano1/SM/pratico1-2022/tempo_espetro.m create mode 100644 2ano1/SM/teste-1-2023-2024-Turma-Anterior/Espetro.m create mode 100644 2ano1/SM/teste-1-2023-2024-Turma-Anterior/Reconstroi.m create mode 100644 2ano1/SM/teste-1-2023-2024-Turma-Anterior/ex02.m create mode 100644 2ano1/SM/teste-1-2023-2024-Turma-Anterior/exame.p create mode 100644 2ano1/SM/teste-1-2023-2024/Reconstroi.m create mode 100644 2ano1/SM/teste-1-2023-2024/calcCoef_complex.m create mode 100644 2ano1/SM/teste-1-2023-2024/ex01.m create mode 100644 2ano1/SM/teste-1-2023-2024/ex02.m create mode 100644 2ano1/SM/teste-1-2023-2024/exame.p create mode 100644 2ano1/SM/teste-2-2023-2024-Turma-Anterior/Espetro.m create mode 100644 2ano1/SM/teste-2-2023-2024-Turma-Anterior/exame2.p create mode 100644 2ano1/SM/teste-2-2023-2024-Turma-Anterior/resolucao.m create mode 100644 2ano1/SM/teste-2-2023-2024-Turma-Anterior/respfreq.m create mode 100644 2ano1/SM/teste-2-2023-2024/Espetro.m create mode 100644 2ano1/SM/teste-2-2023-2024/exame2.p create mode 100644 2ano1/SM/teste-2-2023-2024/resolucao.m create mode 100644 2ano1/SM/teste-2-2023-2024/respfreq.m diff --git a/2ano1/SM/aula03/calcCoef_complex.m b/2ano1/SM/aula03/calcCoef_complex.m new file mode 100644 index 0000000..4fed548 --- /dev/null +++ b/2ano1/SM/aula03/calcCoef_complex.m @@ -0,0 +1,14 @@ +function [C_k] = calcCoef_complex(T_a, T_0, x, K) + t = 0:T_a:T_0 -T_a; + + N = T_0/T_a; + f_0 = 1/T_0; + x1 = x(1:N); + + C_k = zeros(1, K + 1); + + for k = 1:K + 1 + C_k(k) = (1/N) * sum(x1 .* exp(-1j * 2 * pi * (k - 1) * f_0 * t)); + end +end + diff --git a/2ano1/SM/aula03/ex03.m b/2ano1/SM/aula03/ex03.m index bc2c2d1..a8d01b5 100644 --- a/2ano1/SM/aula03/ex03.m +++ b/2ano1/SM/aula03/ex03.m @@ -1,15 +1,20 @@ T_a = 1/256; T_0 = 1; t = 0:T_a:4-T_a; -x = square(2*pi*(1/T_0)*t); +x = square(2*pi*(1/T_0)*t) + 1; plot(t, x); [a_k, b_k] = calcCoef(T_a, T_0, x, 50); -figure; -subplot(1, 2, 1); -stem(0:length(a_k) - 1, a_k, "g"); +%figure; +%subplot(1, 2, 1); +%stem(0:length(a_k) - 1, a_k, "g"); + +%subplot(1, 2, 2); +%stem(0:length(b_k) - 1, b_k, "r"); -subplot(1, 2, 2); -stem(0:length(b_k) - 1, b_k, "r"); \ No newline at end of file +[C_k] = calcCoef_complex(T_a, T_0, x, 5); + +figure; +stem(abs(C_k)); \ No newline at end of file diff --git a/2ano1/SM/aula03/ex05.m b/2ano1/SM/aula03/ex05.m new file mode 100644 index 0000000..b47fe59 --- /dev/null +++ b/2ano1/SM/aula03/ex05.m @@ -0,0 +1,35 @@ +T_a = 1/1000; +f_0 = 1; +L = 5000; + +C_k = zeros(1, L + 1); +%idx = 1:2:L; +%C_k(2:2:end) = -1j*2./(pi*idx); + +a_k = zeros(1, L + 1); +b_k = zeros(1, L + 1); +idx = 1:2:L; +b_k(2:2:end) = 4./(pi*idx); + +C_k(1) = a_k(1)/2; +C_k(2:end) = (a_k(2:end) - 1j*b_k(2:end))/2; + +[sinal, t] = serie_exponencial2(T_a, f_0, 5, C_k); +subplot(2, 1, 1); +plot(t, real(sinal)) +ylim([-1.5 1.5]) +subplot(2, 1, 2); +plot(t, imag(sinal)) + +max(imag(sinal)) + +figure; +[sinal, t] = serie_exponencial(T_a, f_0, 5, C_k); +subplot(2, 1, 1); +plot(t, real(sinal)) +title("Correct") +ylim([-1.5 1.5]) +subplot(2, 1, 2); +plot(t, imag(sinal)) + +max(imag(sinal)) \ No newline at end of file diff --git a/2ano1/SM/aula03/serie_exponencial.m b/2ano1/SM/aula03/serie_exponencial.m new file mode 100644 index 0000000..4940981 --- /dev/null +++ b/2ano1/SM/aula03/serie_exponencial.m @@ -0,0 +1,19 @@ +function [x, t] = serie_exponencial(T_a, f_0, N_p, C_k) + T_0 = 1/f_0; + t = 0:T_a:N_p*T_0 - T_a; + + K = length(C_k); + x = 0; + + C_conj_k = conj(C_k); + + % Negative part + for k=1:(K - 1) + x = x + C_conj_k(k + 1) * exp(1j * 2 * pi * -k * f_0 * t); + end + + % Positive part + for k=1:K + x = x + C_k(k) * exp(1j * 2 * pi * (k -1) * f_0 * t); + end +end \ No newline at end of file diff --git a/2ano1/SM/aula03/serie_exponencial2.m b/2ano1/SM/aula03/serie_exponencial2.m new file mode 100644 index 0000000..d89ced4 --- /dev/null +++ b/2ano1/SM/aula03/serie_exponencial2.m @@ -0,0 +1,13 @@ +function [x, t] = serie_exponencial2(T_a, f_0, N_p, C_k) + T_0 = 1/f_0; + t = 0:T_a:N_p*T_0 - T_a; + + K = length(C_k); + + C_minus_k = conj(C_k(2:end)); + C_k_ext = [fliplr(C_minus_k) C_k]; + + k = -(K-1):K-1; + + x = sum(C_k_ext.' .* exp(1j * 2 * pi * f_0 * t .* k')); +end \ No newline at end of file diff --git a/2ano1/SM/aula07/Espetro.m b/2ano1/SM/aula07/Espetro.m new file mode 100644 index 0000000..d3289a9 --- /dev/null +++ b/2ano1/SM/aula07/Espetro.m @@ -0,0 +1,15 @@ +function [X, f] = Espetro(x, T_a) + N = length(x); + f_a = 1/T_a; + + x1 = fft(x); + X = fftshift(x1); + + + if rem(N, 2) == 0 + f = (-N/2:N/2 - 1)*(f_a/N); + else + f = (-(N-1)/2:(N-1)/2)*(f_a/N); + end +end + diff --git a/2ano1/SM/aula07/ex01.m b/2ano1/SM/aula07/ex01.m new file mode 100644 index 0000000..e417681 --- /dev/null +++ b/2ano1/SM/aula07/ex01.m @@ -0,0 +1,9 @@ +load Guitar03.mat + +[X, f] = Espetro(x, 1/fa); +stem(f, abs(X)); +figure +spectrogram(x, 1024, 512, 1024, fa, "yaxis"); +colorbar; + +%soundsc(x, fa); \ No newline at end of file diff --git a/2ano1/SM/aula07/ex02.m b/2ano1/SM/aula07/ex02.m new file mode 100644 index 0000000..1815633 --- /dev/null +++ b/2ano1/SM/aula07/ex02.m @@ -0,0 +1,12 @@ +load Guitar03.mat + +teta=2*pi*(5000/fa); +xr=x+ 0.6*cos(teta*(0:length(x)-1)'+0.1*pi); + +[X, f] = Espetro(xr, 1/fa); +stem(f, abs(X)); +figure +spectrogram(xr, 1024, 512, 1024, fa, "yaxis"); +colorbar; + +%soundsc(xr, fa); \ No newline at end of file diff --git a/2ano1/SM/aula07/ex03.m b/2ano1/SM/aula07/ex03.m new file mode 100644 index 0000000..66e1fcf --- /dev/null +++ b/2ano1/SM/aula07/ex03.m @@ -0,0 +1,22 @@ +load Guitar03.mat; + +R=0.9; +theta=2*pi*(5000/fa); + +xr=x+ 0.6*cos(theta * (0:length(x)-1)' + 0.1*pi); + +num=[1 -2*cos(theta) 1]; +den=[1 -2*R*cos(teta) R^2]; + +[H, f] = respfreq(num, den, fa); + +y = filter(num, den, x); + +subplot(2, 2, 1) +spectrogram(xr, 1024, 512, 1024, fa, "yaxis"); +subplot(2, 2, 2) +plot(f, H); +subplot(2, 2, 3) +spectrogram(y, 1024, 512, 1024, fa, "yaxis"); + +%soundsc(xr, fa); \ No newline at end of file diff --git a/2ano1/SM/aula07/ex04.m b/2ano1/SM/aula07/ex04.m new file mode 100644 index 0000000..62323c8 --- /dev/null +++ b/2ano1/SM/aula07/ex04.m @@ -0,0 +1,38 @@ +load Guitar03.mat; + +a = 0.9; +D = 34/340 * fa; +D = fa/5; +num = [1 zeros(1,D-1) a]; +den = 1; + +% a) +% H(e^jw) = 1 + ae^(-j omega D) +% = 1 + a +[H, f] = respfreq(num, den, fa); + +%plot(f, H); + +% b) +y = filter(num, den, x); +spectrogram(y, 1024, 512, 1024, fa, "yaxis"); +%soundsc(y, fa); + +% c) +% Serie geometrica de termo az^-D + +% d) +D = 8; +num = 1; +den = [1 zeros(1,D-1) -a]; +[H, f] = respfreq(num, den, fa); +plot(f, H); + +% e) +D = 0.010 * fa; +num = 1; +den = [1 zeros(1,D-1) -a]; +y = filter(num, den, x); +figure +spectrogram(y, 1024, 512, 1024, fa, "yaxis"); +soundsc(y, fa); \ No newline at end of file diff --git a/2ano1/SM/aula07/respfreq.m b/2ano1/SM/aula07/respfreq.m new file mode 100644 index 0000000..a89963c --- /dev/null +++ b/2ano1/SM/aula07/respfreq.m @@ -0,0 +1,6 @@ +function [H, f] = respfreq(num, den, fa) + [H1, f1] = freqz(num, den, 1024, fa, 'whole'); + H = abs(fftshift(H1)); + f = f1 - fa/2; +end + diff --git a/2ano1/SM/aula08/Alfabeto1.m b/2ano1/SM/aula08/Alfabeto1.m new file mode 100644 index 0000000..3b240cb --- /dev/null +++ b/2ano1/SM/aula08/Alfabeto1.m @@ -0,0 +1,3 @@ +function [Simbolos] = Alfabeto1(Texto) + Simbolos = unique(Texto); +end \ No newline at end of file diff --git a/2ano1/SM/aula08/Alfabeto2.m b/2ano1/SM/aula08/Alfabeto2.m new file mode 100644 index 0000000..c733584 --- /dev/null +++ b/2ano1/SM/aula08/Alfabeto2.m @@ -0,0 +1,4 @@ +function [Simbolos, Frequencia] = Alfabeto2(Texto) + [Frequencia, Simbolos] = groupcounts(Texto'); + Frequencia = Frequencia / sum(Frequencia); +end \ No newline at end of file diff --git a/2ano1/SM/aula08/Entropia.m b/2ano1/SM/aula08/Entropia.m new file mode 100644 index 0000000..3d0be3f --- /dev/null +++ b/2ano1/SM/aula08/Entropia.m @@ -0,0 +1,6 @@ +function [H] = Entropia(Texto) + [~, Frequencia] = Alfabeto2(Texto); + + H = -sum(Frequencia .* log2(Frequencia)); +end + diff --git a/2ano1/SM/aula08/NumeroBitsCodigo2.m b/2ano1/SM/aula08/NumeroBitsCodigo2.m new file mode 100644 index 0000000..067be4a --- /dev/null +++ b/2ano1/SM/aula08/NumeroBitsCodigo2.m @@ -0,0 +1,20 @@ +function [NumBits, mensagem] = NumeroBitsCodigo2(Texto) + [Simbolos, ~] = Alfabeto2(Texto); + + N = length(Simbolos); + + Codigos = cell(1, N); + + for k=1:length(Simbolos) + Codigos{k} = [repmat('1', 1, k - 1) '0']; + end + + [~, indexes] = ismember(Texto, Simbolos); + + mensagem = []; + for idx=indexes + mensagem = [mensagem Codigos{idx}]; + end + + NumBits = length(mensagem); +end \ No newline at end of file diff --git a/2ano1/SM/aula08/ex01.m b/2ano1/SM/aula08/ex01.m new file mode 100644 index 0000000..9dd6003 --- /dev/null +++ b/2ano1/SM/aula08/ex01.m @@ -0,0 +1,3 @@ +load Mensagem.mat; + +Simbolos = Alfabeto1(Mensagem); \ No newline at end of file diff --git a/2ano1/SM/aula08/ex02.m b/2ano1/SM/aula08/ex02.m new file mode 100644 index 0000000..ca96e80 --- /dev/null +++ b/2ano1/SM/aula08/ex02.m @@ -0,0 +1,3 @@ +load Mensagem.mat; + +[Simbolos, Frequencia] = Alfabeto2(Mensagem); \ No newline at end of file diff --git a/2ano1/SM/aula08/ex03.m b/2ano1/SM/aula08/ex03.m new file mode 100644 index 0000000..aa32a62 --- /dev/null +++ b/2ano1/SM/aula08/ex03.m @@ -0,0 +1,6 @@ +load Mensagem.mat; + +[Simbolos, Frequencia] = Alfabeto2(Mensagem); + +num_bits = ceil(log2(length(Simbolos))); +repr = int2bit(0:length(Simbolos) - 1, num_bits)'; \ No newline at end of file diff --git a/2ano1/SM/aula08/ex04.m b/2ano1/SM/aula08/ex04.m new file mode 100644 index 0000000..8f5d455 --- /dev/null +++ b/2ano1/SM/aula08/ex04.m @@ -0,0 +1,3 @@ +load Mensagem.mat; + +[NumBits, mensagem] = NumeroBitsCodigo2(Mensagem); \ No newline at end of file diff --git a/2ano1/SM/aula08/ex05.excalidraw b/2ano1/SM/aula08/ex05.excalidraw new file mode 100644 index 0000000..f2a94ea --- /dev/null +++ b/2ano1/SM/aula08/ex05.excalidraw @@ -0,0 +1,723 @@ +{ + "type": "excalidraw", + "version": 2, + "source": "https://excalidraw.com", + "elements": [ + { + "id": "mJB1_Xp9qzEP45Wzg37xi", + "type": "ellipse", + "x": 513.4680169941803, + "y": 1497.25867781554, + "width": 80.91391735504158, + "height": 80.91391735504158, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 644983951, + "version": 146, + "versionNonce": 1343388079, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false + }, + { + "id": "hjhVFeTY75ePlpkwbDsFS", + "type": "line", + "x": 526.9536698866873, + "y": 1565.8107466857837, + "width": 62.9330468316989, + "height": 62.9330468316989, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 463158927, + "version": 42, + "versionNonce": 1269726401, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + -62.9330468316989, + 62.9330468316989 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "r-f_8DT9MqVQb_Z-sHIt3", + "type": "line", + "x": 579.772477049006, + "y": 1568.0583555012015, + "width": 56.752122589299915, + "height": 56.752122589299915, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 1711425793, + "version": 21, + "versionNonce": 1779788751, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 56.752122589299915, + 56.752122589299915 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "QSuo-6QjAK8Rxyhlb-If7", + "type": "ellipse", + "x": 625.8484577650714, + "y": 1613.010531809558, + "width": 83.1615261704593, + "height": 83.1615261704593, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 1522281935, + "version": 23, + "versionNonce": 2099461281, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false + }, + { + "id": "NOGE4gDj1dBHA4OQcikpF", + "type": "line", + "x": 639.3341106575783, + "y": 1687.181622718346, + "width": 45.51407851221086, + "height": 45.51407851221097, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 1863279, + "version": 62, + "versionNonce": 1194662383, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + -45.51407851221086, + 45.51407851221097 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "Kga8AiEcYVCHMOrKzlis8", + "type": "line", + "x": 697.7719398584417, + "y": 1688.3054271260548, + "width": 42.70456749293862, + "height": 42.70456749293862, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 1982345377, + "version": 41, + "versionNonce": 1169490049, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 42.70456749293862, + 42.70456749293862 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "DQzs9IFosxHoJyEyx2yTF", + "type": "ellipse", + "x": 729.2384632742912, + "y": 1723.143363765031, + "width": 85.40913498587724, + "height": 85.40913498587724, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 1314679471, + "version": 138, + "versionNonce": 1551500303, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false + }, + { + "id": "ahGN7Zryx67SOHN-e4o-l", + "type": "line", + "x": 740.4765073513803, + "y": 1799.562063489237, + "width": 38.771252065957356, + "height": 38.77125206595747, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 1694726817, + "version": 41, + "versionNonce": 1126385761, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + -38.771252065957356, + 38.77125206595747 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "72L6O9NunEH_aKR6SG71t", + "type": "line", + "x": 798.9143365522435, + "y": 1798.438259081528, + "width": 42.142665289084334, + "height": 42.142665289084334, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": { + "type": 2 + }, + "seed": 1998733487, + "version": 62, + "versionNonce": 1776069167, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "points": [ + [ + 0, + 0 + ], + [ + 42.142665289084334, + 42.142665289084334 + ] + ], + "lastCommittedPoint": null, + "startBinding": null, + "endBinding": null, + "startArrowhead": null, + "endArrowhead": null + }, + { + "id": "S-tcy74T8ps4_o3IBIo8Q", + "type": "text", + "x": 443.7921437162279, + "y": 1629.8675979251914, + "width": 23.616666793823242, + "height": 45, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": null, + "seed": 942168111, + "version": 28, + "versionNonce": 792564801, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "text": "A", + "fontSize": 36, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 32, + "containerId": null, + "originalText": "A", + "lineHeight": 1.25 + }, + { + "id": "lBBO-noShbLjlXEeUe_87", + "type": "text", + "x": 569.6582373796258, + "y": 1732.1337990267025, + "width": 26.16666603088379, + "height": 45, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": null, + "seed": 188574401, + "version": 20, + "versionNonce": 474319951, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "text": "B", + "fontSize": 36, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 32, + "containerId": null, + "originalText": "B", + "lineHeight": 1.25 + }, + { + "id": "mwmvYuvJd3_wr3xLAoPn9", + "type": "text", + "x": 679.7910693350991, + "y": 1841.1428265744669, + "width": 23.183332443237305, + "height": 45, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": null, + "seed": 5912975, + "version": 33, + "versionNonce": 1871522415, + "isDeleted": false, + "boundElements": null, + "updated": 1700758383689, + "link": null, + "locked": false, + "text": "C", + "fontSize": 36, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 32, + "containerId": null, + "originalText": "C", + "lineHeight": 1.25 + }, + { + "id": "M2cLSq_QPcjGEWlrg8Klz", + "type": "text", + "x": 811.2761850370415, + "y": 1843.3904353898847, + "width": 137.06666564941406, + "height": 45, + "angle": 0, + "strokeColor": "#e03131", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": null, + "seed": 844936673, + "version": 47, + "versionNonce": 749775279, + "isDeleted": false, + "boundElements": null, + "updated": 1700758493003, + "link": null, + "locked": false, + "text": "Invalido", + "fontSize": 36, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 32, + "containerId": null, + "originalText": "Invalido", + "lineHeight": 1.25 + }, + { + "id": "5WjmiPRIwW3vfATqXHBYh", + "type": "text", + "x": 485.3729068014576, + "y": 1543.3346585316053, + "width": 24.766666412353516, + "height": 45, + "angle": 0, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "groupIds": [], + "frameId": null, + "roundness": null, + "seed": 790719695, + "version": 35, + "versionNonce": 1739395407, + "isDeleted": false, + "boundElements": null, + "updated": 1700758390786, + "link": null, + "locked": false, + "text": "0", + "fontSize": 36, + "fontFamily": 1, + "textAlign": "left", + "verticalAlign": "top", + "baseline": 32, + "containerId": null, + "originalText": "0", + "lineHeight": 1.25 + }, + { + "type": "text", + "version": 86, + "versionNonce": 1384592513, + "isDeleted": false, + "id": "vZiq21RzJl5PtiYwlbo3i", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "angle": 0, + "x": 602.2270804818055, + "y": 1655.6911874566745, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "width": 24.766666412353516, + "height": 45, + "seed": 830884239, + "groupIds": [], + "frameId": null, + "roundness": null, + "boundElements": [], + "updated": 1700758393203, + "link": null, + "locked": false, + "fontSize": 36, + "fontFamily": 1, + "text": "0", + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "0", + "lineHeight": 1.25, + "baseline": 32 + }, + { + "type": "text", + "version": 143, + "versionNonce": 1370247489, + "isDeleted": false, + "id": "qgTTRa-ZlMFA3-WO3wZMa", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "angle": 0, + "x": 714.6075212526966, + "y": 1769.1954326352748, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "width": 24.766666412353516, + "height": 45, + "seed": 739428417, + "groupIds": [], + "frameId": null, + "roundness": null, + "boundElements": [], + "updated": 1700758395009, + "link": null, + "locked": false, + "fontSize": 36, + "fontFamily": 1, + "text": "0", + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "0", + "lineHeight": 1.25, + "baseline": 32 + }, + { + "type": "text", + "version": 225, + "versionNonce": 121539169, + "isDeleted": false, + "id": "YGBjfcmNk4K83e5ti9tqg", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "angle": 0, + "x": 597.73186285097, + "y": 1547.805964316619, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "width": 9.75, + "height": 45, + "seed": 346535169, + "groupIds": [], + "frameId": null, + "roundness": null, + "boundElements": [], + "updated": 1700758400466, + "link": null, + "locked": false, + "fontSize": 36, + "fontFamily": 1, + "text": "1", + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "1", + "lineHeight": 1.25, + "baseline": 32 + }, + { + "type": "text", + "version": 290, + "versionNonce": 1026203169, + "isDeleted": false, + "id": "m52LVbi-BXwS9vAhs6uEI", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "angle": 0, + "x": 717.6206368280375, + "y": 1655.6911874566747, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "width": 9.75, + "height": 45, + "seed": 563488289, + "groupIds": [], + "frameId": null, + "roundness": null, + "boundElements": [], + "updated": 1700758402710, + "link": null, + "locked": false, + "fontSize": 36, + "fontFamily": 1, + "text": "1", + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "1", + "lineHeight": 1.25, + "baseline": 32 + }, + { + "type": "text", + "version": 347, + "versionNonce": 1288729313, + "isDeleted": false, + "id": "qZnnFdmWjdEueMS6FF-ky", + "fillStyle": "hachure", + "strokeWidth": 1, + "strokeStyle": "solid", + "roughness": 1, + "opacity": 100, + "angle": 0, + "x": 814.267815891004, + "y": 1774.8144546738195, + "strokeColor": "#1e1e1e", + "backgroundColor": "transparent", + "width": 9.75, + "height": 45, + "seed": 383797729, + "groupIds": [], + "frameId": null, + "roundness": null, + "boundElements": [], + "updated": 1700758404383, + "link": null, + "locked": false, + "fontSize": 36, + "fontFamily": 1, + "text": "1", + "textAlign": "left", + "verticalAlign": "top", + "containerId": null, + "originalText": "1", + "lineHeight": 1.25, + "baseline": 32 + } + ], + "appState": { + "gridSize": null, + "viewBackgroundColor": "#ffffff" + }, + "files": {} +} \ No newline at end of file diff --git a/2ano1/SM/aula08/ex06.m b/2ano1/SM/aula08/ex06.m new file mode 100644 index 0000000..083226f --- /dev/null +++ b/2ano1/SM/aula08/ex06.m @@ -0,0 +1,3 @@ +load Mensagem.mat; + +H = Entropia(Mensagem); \ No newline at end of file diff --git a/2ano1/SM/pratico1-2022/ex01d.m b/2ano1/SM/pratico1-2022/ex01d.m new file mode 100644 index 0000000..e3541cb --- /dev/null +++ b/2ano1/SM/pratico1-2022/ex01d.m @@ -0,0 +1,23 @@ +%% a) +f0 = 2.5; +f1 = 3.5; +f = gcd(10*f0, 10*f1)/10; +Ta = 0.01; +T = 1/f; +Np = 20; + +T_F = 2; +N = round(Np*T/Ta); +t = (0:N-1)*Ta; +y = 8*cos(5*pi*t + pi/4) + 6*sin(7*pi*t - pi/5); +tempo_espetro(y, Ta, f, Np, T_F); + +%% b) +Ta = 0.01; +f = 4; +T=1/f; +t = 0:Ta:2.5; +Np = 2.5/T; +T_F = 2; +y = 2*square(f*2*pi*t); +tempo_espetro(y,Ta,f,Np,T_F); \ No newline at end of file diff --git a/2ano1/SM/pratico1-2022/tempo_espetro.m b/2ano1/SM/pratico1-2022/tempo_espetro.m new file mode 100644 index 0000000..79e4b1b --- /dev/null +++ b/2ano1/SM/pratico1-2022/tempo_espetro.m @@ -0,0 +1,42 @@ +function tempo_espetro(y, Ta, Fo, Np, T_F) + if (T_F > 2 || T_F < 0) + error("T_F devera ter valores de 0,1 e 2") + end + + N = length(y); + + if T_F == 0 || T_F == 2 + t = (0:N - 1)*Ta; + + if T_F == 2 + subplot(1,2,1); + end + + plot(t, y); + xlabel("Tempo (s)"); + ylabel("y"); + grid on; + end + + if T_F == 1 || T_F == 2 + fa = 1/Ta; + + x1 = fft(y); + X = fftshift(x1) / N; + + if rem(N, 2) == 0 + f = (-N/2:N/2 - 1)*(fa/N); + else + f = (-(N-1)/2:(N-1)/2)*(fa/N); + end + + if T_F == 2 + subplot(1,2,2); + end + + plot(f, abs(X)); + xlabel("Frequência (Hz)"); + ylabel("Magnitude"); + grid on; + end +end \ No newline at end of file diff --git a/2ano1/SM/teste-1-2023-2024-Turma-Anterior/Espetro.m b/2ano1/SM/teste-1-2023-2024-Turma-Anterior/Espetro.m new file mode 100644 index 0000000..d3289a9 --- /dev/null +++ b/2ano1/SM/teste-1-2023-2024-Turma-Anterior/Espetro.m @@ -0,0 +1,15 @@ +function [X, f] = Espetro(x, T_a) + N = length(x); + f_a = 1/T_a; + + x1 = fft(x); + X = fftshift(x1); + + + if rem(N, 2) == 0 + f = (-N/2:N/2 - 1)*(f_a/N); + else + f = (-(N-1)/2:(N-1)/2)*(f_a/N); + end +end + diff --git a/2ano1/SM/teste-1-2023-2024-Turma-Anterior/Reconstroi.m b/2ano1/SM/teste-1-2023-2024-Turma-Anterior/Reconstroi.m new file mode 100644 index 0000000..23af959 --- /dev/null +++ b/2ano1/SM/teste-1-2023-2024-Turma-Anterior/Reconstroi.m @@ -0,0 +1,12 @@ +function [Y, t] = Reconstroi(X, f) + N = length(X); + dummy = diff(f); + f_a = N*dummy(1); + T_a = 1/f_a; + + x1 = ifftshift(X); + Y = ifft(x1); + + t = (0:N-1)*T_a; +end + diff --git a/2ano1/SM/teste-1-2023-2024-Turma-Anterior/ex02.m b/2ano1/SM/teste-1-2023-2024-Turma-Anterior/ex02.m new file mode 100644 index 0000000..baf0075 --- /dev/null +++ b/2ano1/SM/teste-1-2023-2024-Turma-Anterior/ex02.m @@ -0,0 +1,52 @@ +% a) +[s, Fa] = exame(1999, 2); + +% a.1) +T=0.2; % (segundos +% a.2) 1.9975s +% a.3) 3: 20Hz, 25Hz, 30Hz + +% b) +N = length(s); +fprintf("%d amostras\n", N); +Ta = 1/Fa; +t = (0:(N-1))*Ta; +if rem(N, 2) == 0 + f = (-N/2:N/2 - 1) * (Fa/N); +else + f = (-(N-1)/2:(N-1)/2) * (Fa/N); +end + +% c) +y = 1*sin(20*2*pi*t) + 0.5*sin(25*2*pi*t) + 0.25*sin(30*2*pi*t); +%figure; +%plot(t, y); +%xlabel("segundos"); + +% d) +% Somar uma constante a um sinal ira provocar uma transalacao vertical no +% grafico do sinal, e o o componente DC sera incrementado com o valor no +% espetro do novo sinal. + +[X, f] = Espetro(s, Ta); +%figure; +%plot(f, abs(X) / N); + +% e) +% Se f0 e -f0 forem removidos, o periodo nao vai mudar, pois as frequencias +% restantes (25Hz e 30Hz), continuam a ter uma frequencia fundamental de +% 5Hz, o periodo continua entao em 0.2s. +%X(abs(f) == 20) = 0; +%[new_y, new_t] = Reconstroi(X, f); +%figure; +%plot(new_t, new_y); + +% f) +% Se f0 e -f0 forem removidos, o periodo nao vai mudar, pois as frequencias +% restantes (25Hz e 30Hz), continuam a ter uma frequencia fundamental de +% 5Hz, o periodo continua entao em 0.2s. +X(abs(f) == 20) = 0; +X(abs(f) == 25) = 0; +[new_y, new_t] = Reconstroi(X, f); +figure; +plot(new_t, new_y); \ No newline at end of file diff --git a/2ano1/SM/teste-1-2023-2024-Turma-Anterior/exame.p b/2ano1/SM/teste-1-2023-2024-Turma-Anterior/exame.p new file mode 100644 index 0000000000000000000000000000000000000000..3e33df162d51dabfba45065ac6d36d5449817eb9 GIT binary patch literal 503 zcmVn@i790Z0?LZE!Ukhs)D zi?8SD{OtL#?;5P;YD2tO3Sxb%xv_WLGRtX1gqy-|q43svkO$G+DW~4fZCNQt(G=wwZ^__oezy%)&P#a+7QLflQ9=>UFo!#;2n@i790Z0?LZE!Ukhs)D zi?8SD{OtL#?;5P;YD2tO3Sxb%xv_WLGRtX1gqy-|q43svkO$G+DW~4fZCNQt(G=wwZ^__oezy%)&P#a+7QLflQ9=>UFo!#;22YNUtyS5#|zy}DAfkE^DGId+9UoU@0S%q@nWXy(n>RSy;8JPo#cAJ|?c#|O}o#GY{2 zCBmOQzG2~W)B>7ff|xM;-&i>$NOj~GG0CMvslcZzR(9n|fIaN=3wu=vod4FwitPym zI;x!hV%MGOu|+|kv{%~Om5(< z$1%p+M~7PV{u3soibBIpV&y_Zu$#0h3{Z2@d_KhDnILE14qUzYqHxN?ZV?uZtlq_z c=fZz$r;irC7%lh%_GMFbpgoQ=t9Dh{s2jf3tpET3 literal 0 HcmV?d00001 diff --git a/2ano1/SM/teste-2-2023-2024-Turma-Anterior/resolucao.m b/2ano1/SM/teste-2-2023-2024-Turma-Anterior/resolucao.m new file mode 100644 index 0000000..df8e2f4 --- /dev/null +++ b/2ano1/SM/teste-2-2023-2024-Turma-Anterior/resolucao.m @@ -0,0 +1,62 @@ +[x, t, num, den] = exame2(2999, 2); +a = diff(t); + +% Exercício 1 +% `a` corresponde as diferenças entre os instantes de amostragem em relação ao +% seguinte, ou seja, `a` representa os deltas entre os instantes ou seja os períodos +% de amostragem. + +fa = 1 / mean(a); % Frequência de amostragem + +% Exercício 2 +% O sinal filtrado apresenta as frequências: 40Hz, 80Hz e 120Hz +[X, f] = Espetro(x, 1/fa); + + +subplot(2, 1, 1) +stem(f, abs(X)); +title("Espetro do sinal original"); +xlabel("Frequencia (Hertz)") +ylabel("magnitude") + +y = filter(num, den, x); +[Y, ~] = Espetro(y, 1/fa); + +subplot(2, 1, 2) +stem(f, abs(Y)); +title("Espetro do sinal filtrado"); +xlabel("Frequencia (Hertz)") +ylabel("magnitude") + +% Exercício 3 +% A resposta em frequência do filtro mostra que este mantêm quase iguais as +% frequências entre 0 e ~70Hz e todas as frequências maiores que 70Hz são +% atenuadas (sendo atenuadas quanto maiores forem). Isto explica porque o +% sinal filtrado anterior aprsenta a frequência de 40Hz com um magnitude +% em que quase nada foi alterada enquanto que 80hz e 120Hz foram bastante +% atenuadas (120Hz quase que desaparece) e as outras frequências maiores +% nem estão presentes. +[H, f] = respfreq(num, den, fa); +figure +plot(f, H); +% plot(f, 20*log10(H)); +title("Resposta em frequência"); +xlabel('Frequency (Hz)') +ylabel('Magnitude') +% ylabel('Magnitude (dB)') + +%% Exercício 3 +a = 0.99; +cos_w = cos(2*pi*80/fa); +num = [1 -2*cos_w 1]; +denom = [1 -2*a*cos_w a^2]; + +K = (1 - 2*a*cos_w + a^2)/(2 - 2*cos_w); + +[H, f] = respfreq(K * num, denom, fa); + +figure +plot(f, 20*log10(H)); +title("Resposta em frequência"); +xlabel('Frequency (Hz)') +ylabel('Magnitude (dB)') diff --git a/2ano1/SM/teste-2-2023-2024-Turma-Anterior/respfreq.m b/2ano1/SM/teste-2-2023-2024-Turma-Anterior/respfreq.m new file mode 100644 index 0000000..acb8afc --- /dev/null +++ b/2ano1/SM/teste-2-2023-2024-Turma-Anterior/respfreq.m @@ -0,0 +1,6 @@ +function [H, f] = respfreq(num, den, fa) +[H1, f1] = freqz(num, den, 4096, fa, 'whole'); +H = abs(fftshift(H1)); +f = f1 - fa/2; +end + diff --git a/2ano1/SM/teste-2-2023-2024/Espetro.m b/2ano1/SM/teste-2-2023-2024/Espetro.m new file mode 100644 index 0000000..d3289a9 --- /dev/null +++ b/2ano1/SM/teste-2-2023-2024/Espetro.m @@ -0,0 +1,15 @@ +function [X, f] = Espetro(x, T_a) + N = length(x); + f_a = 1/T_a; + + x1 = fft(x); + X = fftshift(x1); + + + if rem(N, 2) == 0 + f = (-N/2:N/2 - 1)*(f_a/N); + else + f = (-(N-1)/2:(N-1)/2)*(f_a/N); + end +end + diff --git a/2ano1/SM/teste-2-2023-2024/exame2.p b/2ano1/SM/teste-2-2023-2024/exame2.p new file mode 100644 index 0000000000000000000000000000000000000000..f92b40e405207559109dbab80e3898b3cc657ea3 GIT binary patch literal 434 zcmV;j0ZsmPFflGLFm^C7E-)|v3IH4ps^75y00A%n00EK!00M~BdkZC_3hn@Sg@S6z za=xz+o{^_schNK6d`f$cHmcF_m3vlXD>2YNUtyS5#|zy}DAfkE^DGId+9UoU@0S%q@nWXy(n>RSy;8JPo#cAJ|?c#|O}o#GY{2 zCBmOQzG2~W)B>7ff|xM;-&i>$NOj~GG0CMvslcZzR(9n|fIaN=3wu=vod4FwitPym zI;x!hV%MGOu|+|kv{%~Om5(< z$1%p+M~7PV{u3soibBIpV&y_Zu$#0h3{Z2@d_KhDnILE14qUzYqHxN?ZV?uZtlq_z c=fZz$r;irC7%lh%_GMFbpgoQ=t9Dh{s2jf3tpET3 literal 0 HcmV?d00001 diff --git a/2ano1/SM/teste-2-2023-2024/resolucao.m b/2ano1/SM/teste-2-2023-2024/resolucao.m new file mode 100644 index 0000000..ed79e8e --- /dev/null +++ b/2ano1/SM/teste-2-2023-2024/resolucao.m @@ -0,0 +1,65 @@ +% 103252 - André de Sousa Fernandes +% 113713 - João Pinto Capucho + +[x, t, num, den] = exame2(1221,2); +a=diff(t); + +%% Exercício 1 +% A váriavel a é um vetor com as diferenças entre os instantes de amostragem, +% ou seja representa os períodos de amostragem. +Ta = mean(a); +fa = 1/Ta; % fa = 400Hz + +fprintf("A frequência de amostragem é de %f Hz\n", fa); + +%% Exercício 2 +% O conteúdo de frequência após o filtro é de 5Hz e 20Hz +[X, f] = Espetro(x, Ta); + +subplot(2, 1, 1) +stem(f, abs(X)); +title("Espetro do sinal original"); +xlabel("Frequencia (Hertz)") +ylabel("magnitude") + +y = filter(num, den, x); +[Y, ~] = Espetro(y, Ta); + +subplot(2, 1, 2) +stem(f, abs(Y)); +title("Espetro do sinal filtrado"); +xlabel("Frequencia (Hertz)") +ylabel("magnitude") + +sgtitle("Exercício 2") + +%% Exercício 3 +% A resposta em frequência do filtro mostra que este atenua frequências +% maiores que ~40Hz-50Hz e "completamente" elimina as frequências de 143Hz +% e 183Hz. +% +% Isto explica apenas as frequências de 5Hz e 20Hz terem permanecido após a +% aplicação do filtro. +[H, f] = respfreq(num, den, fa); +figure +plot(f, 20*log10(H)); +title("Exercício 3: Resposta em frequência"); +xlabel('Frequency (Hz)') +ylabel('Magnitude (dB)') + +%% Exercício 4 +D = 0.1/Ta; % 100 ms = 0.1 s + +z = x; +z(D + 1:end) = x(D + 1:end) - 0.8*x(1:end - D); + +figure +plot(t, x, 'b', 'DisplayName', 'original'); +title('Exercício 4: Sinal z(n) = x(n) - 0.8 \times x(n-D)'); +xlabel('Tempo (s)') +ylabel('Amplitude') +hold on +plot(t, z, 'r', 'DisplayName', 'resultado sistema'); +hold off + +legend('location', 'best'); diff --git a/2ano1/SM/teste-2-2023-2024/respfreq.m b/2ano1/SM/teste-2-2023-2024/respfreq.m new file mode 100644 index 0000000..acb8afc --- /dev/null +++ b/2ano1/SM/teste-2-2023-2024/respfreq.m @@ -0,0 +1,6 @@ +function [H, f] = respfreq(num, den, fa) +[H1, f1] = freqz(num, den, 4096, fa, 'whole'); +H = abs(fftshift(H1)); +f = f1 - fa/2; +end +