diff --git a/src-ref/ECG_raw_3filters-inc.pdf b/src-ref/ECG_raw_3filters-inc.pdf index 355124ca47ee75d8f7d5002187e1919781adbbb8..a3ff5c14c70507147ba604e086ae030aec490c3a 100644 Binary files a/src-ref/ECG_raw_3filters-inc.pdf and b/src-ref/ECG_raw_3filters-inc.pdf differ diff --git a/src-ref/ECG_raw_3filters.tex b/src-ref/ECG_raw_3filters.tex index 2c2602a667849c8f4598c24563eedf3ec21d5e6f..b1d4c777ed43d007ee7a08272477878b80f7ccae 100644 --- a/src-ref/ECG_raw_3filters.tex +++ b/src-ref/ECG_raw_3filters.tex @@ -1,33 +1,49 @@ \documentclass{minimal} \usepackage{graphicx,color} \usepackage[utf8]{inputenc} -\usepackage[papersize={418.00bp,314.00bp},text={418.00bp,314.00bp}]{geometry} +\usepackage[papersize={419.00bp,291.00bp},text={419.00bp,291.00bp}]{geometry} \begin{document} \centering % Title: Figure 2 % Creator: GL2PS 1.4.2, (C) 1999-2020 C. Geuzaine % For: Octave -% CreationDate: Sat Mar 8 18:00:29 2025 +% CreationDate: Wed Mar 12 10:25:33 2025 \setlength{\unitlength}{1pt} \begin{picture}(0,0) \includegraphics[scale=1]{ECG_raw_3filters-inc} \end{picture}% -\begin{picture}(418,314)(0,0) -\fontsize{10}{0}\selectfont\put(59.9993,183.904){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{0}}}} -\fontsize{10}{0}\selectfont\put(123.789,183.904){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{2000}}}} -\fontsize{10}{0}\selectfont\put(187.578,183.904){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{4000}}}} -\fontsize{10}{0}\selectfont\put(251.368,183.904){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{6000}}}} -\fontsize{10}{0}\selectfont\put(315.157,183.904){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{8000}}}} -\fontsize{10}{0}\selectfont\put(378.946,183.904){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{10000}}}} -\fontsize{10}{0}\selectfont\put(55.0001,191.426){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{-100}}}} -\fontsize{10}{0}\selectfont\put(55.0001,206.971){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{-50}}}} -\fontsize{10}{0}\selectfont\put(55.0001,222.517){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{0}}}} -\fontsize{10}{0}\selectfont\put(55.0001,238.062){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{50}}}} -\fontsize{10}{0}\selectfont\put(59.9993,26.979){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{0}}}} -\fontsize{10}{0}\selectfont\put(123.789,26.979){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{2000}}}} -\fontsize{10}{0}\selectfont\put(187.578,26.979){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{4000}}}} -\fontsize{10}{0}\selectfont\put(251.368,26.979){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{6000}}}} -\fontsize{10}{0}\selectfont\put(315.157,26.979){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{8000}}}} -\fontsize{10}{0}\selectfont\put(378.946,26.979){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{10000}}}} +\begin{picture}(419,291)(0,0) +\fontsize{10}{0}\selectfont\put(54.5866,163.325){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{0}}}} +\fontsize{10}{0}\selectfont\put(119.671,163.325){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{2000}}}} +\fontsize{10}{0}\selectfont\put(184.755,163.325){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{4000}}}} +\fontsize{10}{0}\selectfont\put(249.839,163.325){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{6000}}}} +\fontsize{10}{0}\selectfont\put(314.922,163.325){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{8000}}}} +\fontsize{10}{0}\selectfont\put(380.006,163.325){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{10000}}}} +\fontsize{10}{0}\selectfont\put(49.5801,170.849){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{-100}}}} +\fontsize{10}{0}\selectfont\put(49.5801,185.062){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{-50}}}} +\fontsize{10}{0}\selectfont\put(49.5801,199.274){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{0}}}} +\fontsize{10}{0}\selectfont\put(49.5801,213.487){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{50}}}} +\fontsize{10}{0}\selectfont\put(49.5801,227.699){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{100}}}} +\fontsize{10}{0}\selectfont\put(49.5801,241.912){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{150}}}} +\fontsize{10}{0}\selectfont\put(49.5801,256.124){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{200}}}} +\fontsize{11}{0}\selectfont\put(217.297,151.325){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{Samples (Fs=500Hz)}}}} +\fontsize{11}{0}\selectfont\put(26.5801,213.487){\rotatebox{90}{\makebox(0,0)[b]{\textcolor[rgb]{0.15,0.15,0.15}{{Magnitude (digital signal)}}}}} +\fontsize{11}{0}\selectfont\put(217.297,266.124){\makebox(0,0)[b]{\textcolor[rgb]{0,0,0}{{Raw ECG signal}}}} +\fontsize{10}{0}\selectfont\put(54.5866,23.8821){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{0}}}} +\fontsize{10}{0}\selectfont\put(119.671,23.8821){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{2000}}}} +\fontsize{10}{0}\selectfont\put(184.755,23.8821){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{4000}}}} +\fontsize{10}{0}\selectfont\put(249.839,23.8821){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{6000}}}} +\fontsize{10}{0}\selectfont\put(314.922,23.8821){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{8000}}}} +\fontsize{10}{0}\selectfont\put(380.006,23.8821){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{10000}}}} +\fontsize{10}{0}\selectfont\put(49.5801,31.4064){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{-100}}}} +\fontsize{10}{0}\selectfont\put(49.5801,45.6189){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{-50}}}} +\fontsize{10}{0}\selectfont\put(49.5801,59.8314){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{0}}}} +\fontsize{10}{0}\selectfont\put(49.5801,74.0439){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{50}}}} +\fontsize{10}{0}\selectfont\put(49.5801,88.2564){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{100}}}} +\fontsize{10}{0}\selectfont\put(49.5801,102.469){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{150}}}} +\fontsize{10}{0}\selectfont\put(49.5801,116.681){\makebox(0,0)[r]{\textcolor[rgb]{0.15,0.15,0.15}{{200}}}} +\fontsize{11}{0}\selectfont\put(217.297,11.8821){\makebox(0,0)[t]{\textcolor[rgb]{0.15,0.15,0.15}{{Samples (Fs=500Hz)}}}} +\fontsize{11}{0}\selectfont\put(26.5801,74.0439){\rotatebox{90}{\makebox(0,0)[b]{\textcolor[rgb]{0.15,0.15,0.15}{{Magnitude (digital signal)}}}}} +\fontsize{11}{0}\selectfont\put(217.297,126.681){\makebox(0,0)[b]{\textcolor[rgb]{0,0,0}{{After 3 filters}}}} \end{picture} \end{document} diff --git a/src-ref/coeficientes_vhdl.txt b/src-ref/coeficientes_vhdl.txt index e1d30f9f474ead23d9e0a3cabaebaeabd261c31d..c4d76a269692c0dbbdfdb6c3656028491337df40 100644 --- a/src-ref/coeficientes_vhdl.txt +++ b/src-ref/coeficientes_vhdl.txt @@ -1,247 +1,154 @@ --- Coefficients du filtre Baseline --- -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(64, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-2, 11), +to_signed(-2, 11), +to_signed(-2, 11), +to_signed(-3, 11), +to_signed(-3, 11), +to_signed(-3, 11), +to_signed(-4, 11), +to_signed(-4, 11), +to_signed(-5, 11), +to_signed(-5, 11), +to_signed(-6, 11), +to_signed(-6, 11), +to_signed(-7, 11), +to_signed(-7, 11), +to_signed(-8, 11), +to_signed(-8, 11), +to_signed(-9, 11), +to_signed(-10, 11), +to_signed(-10, 11), +to_signed(-11, 11), +to_signed(-11, 11), +to_signed(-12, 11), +to_signed(-13, 11), +to_signed(-13, 11), +to_signed(-14, 11), +to_signed(-14, 11), +to_signed(-15, 11), +to_signed(-15, 11), +to_signed(-16, 11), +to_signed(-16, 11), +to_signed(-17, 11), +to_signed(-17, 11), +to_signed(-18, 11), +to_signed(-18, 11), +to_signed(-18, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(1004, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-19, 11), +to_signed(-18, 11), +to_signed(-18, 11), +to_signed(-18, 11), +to_signed(-17, 11), +to_signed(-17, 11), +to_signed(-16, 11), +to_signed(-16, 11), +to_signed(-15, 11), +to_signed(-15, 11), +to_signed(-14, 11), +to_signed(-14, 11), +to_signed(-13, 11), +to_signed(-13, 11), +to_signed(-12, 11), +to_signed(-11, 11), +to_signed(-11, 11), +to_signed(-10, 11), +to_signed(-10, 11), +to_signed(-9, 11), +to_signed(-8, 11), +to_signed(-8, 11), +to_signed(-7, 11), +to_signed(-7, 11), +to_signed(-6, 11), +to_signed(-6, 11), +to_signed(-5, 11), +to_signed(-5, 11), +to_signed(-4, 11), +to_signed(-4, 11), +to_signed(-3, 11), +to_signed(-3, 11), +to_signed(-3, 11), +to_signed(-2, 11), +to_signed(-2, 11), +to_signed(-2, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(-1, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), +to_signed(0, 11), ---- Coefficients du filtre Notch 50Hz --- -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(-1, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(1, 8), -to_signed(1, 8), -to_signed(1, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(0, 8), -to_signed(1, 8), -to_signed(1, 8), -to_signed(2, 8), -to_signed(2, 8), -to_signed(1, 8), -to_signed(-1, 8), -to_signed(-2, 8), -to_signed(-2, 8), -to_signed(-2, 8), -to_signed(-1, 8), -to_signed(1, 8), -to_signed(2, 8), -to_signed(3, 8), -to_signed(2, 8), -to_signed(1, 8), -to_signed(-1, 8), -to_signed(-2, 8), -to_signed(63, 8), -to_signed(-2, 8), -to_signed(-1, 8), -to_signed(1, 8), -to_signed(2, 8), -to_signed(3, 8), -to_signed(2, 8), -to_signed(1, 8), -to_signed(-1, 8), -to_signed(-2, 8), -to_signed(-2, 8), -to_signed(-2, 8), -to_signed(-1, 8), -to_signed(1, 8), -to_signed(2, 8), -to_signed(2, 8), -to_signed(1, 8), -to_signed(1, 8), -to_signed(0, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(-1, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(1, 8), -to_signed(1, 8), -to_signed(1, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(-1, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), -to_signed(0, 8), +--- Coefficients du filtre Pei-Tseng A --- +to_signed(1024, 11), +to_signed(-1554, 11), +to_signed(897, 11), + +--- Coefficients du filtre Pei-Tseng B --- +to_signed(961, 11), +to_signed(-1554, 11), +to_signed(961, 11), --- Coefficients du filtre Parks-McClellan --- -to_signed(-13, 8), -to_signed(13, 8), -to_signed(16, 8), -to_signed(21, 8), -to_signed(25, 8), -to_signed(26, 8), -to_signed(25, 8), -to_signed(21, 8), -to_signed(16, 8), -to_signed(13, 8), -to_signed(-13, 8), +to_signed(-119, 11), +to_signed(122, 11), +to_signed(149, 11), +to_signed(191, 11), +to_signed(226, 11), +to_signed(239, 11), +to_signed(226, 11), +to_signed(191, 11), +to_signed(149, 11), +to_signed(122, 11), +to_signed(-119, 11), diff --git a/src-ref/octaveScript.m b/src-ref/octaveScript.m index 2c6d3fce63957e72adf3d7645dc722a535b1b961..e3f61817441e85f35cdf398e97dd3fdb1385e8ba 100644 --- a/src-ref/octaveScript.m +++ b/src-ref/octaveScript.m @@ -5,9 +5,9 @@ Fs = 500; % Frequence d'echantillonnage Fn = Fs/2; % Frequence de Nyquist -figure(1) +%figure(1) T = csvread('./ADCSamplesOctave.csv'); -subplot(2,3,1);plot(T(:,2));title('Raw ECG signal');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (output of an 11-bit ADC)'); +%subplot(2,3,1);plot(T(:,2));title('Raw ECG signal');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (output of an 11-bit ADC)'); % Pour Octave (à supprimer sous Matlab) pkg load signal; @@ -17,24 +17,27 @@ pkg load signal; % Suppression de la baseline (High-pass FIR) fBaseLine = fir1(128, 5/Fn, 'high'); % Génération du filtre -fBaseLine = fBaseLine / sqrt(sum(fBaseLine.^2)) * 2^6; % Normalisation et mise à l'échelle +fBaseLine = round(fBaseLine * 2^10); % Normalisation et mise à l'échelle y_minus_BL = filter(fBaseLine, [1], T(:,2)); % Application du filtre -subplot(2,3,2);plot(y_minus_BL);title('Baseline wander reduced');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); -subplot(2,3,3);plot(y_minus_BL(1:1000));title('Baseline wander reduced -- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); +% subplot(2,3,2);plot(y_minus_BL);title('Baseline wander reduced');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); +% subplot(2,3,3);plot(y_minus_BL(1:1000));title('Baseline wander reduced -- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); % Élimination du bruit à 50Hz par un coupe-bande basique (Notch FIR) f50Hz = fir1(100, [45 55]/Fn, 'stop'); % Génération du filtre -f50Hz = f50Hz / sqrt(sum(f50Hz.^2)) * 2^6; % Normalisation et mise à l'échelle +f50Hz = round(f50Hz * 2^10); % Normalisation et mise à l'échelle y_minus_50Hz_simple = filter(f50Hz, [1], y_minus_BL); % Application du filtre -subplot(2,3,4);plot(y_minus_50Hz_simple(1:1000));title('FIR1 band-cut-- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); +% subplot(2,3,4);plot(y_minus_50Hz_simple(1:1000));title('FIR1 band-cut-- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); -% Élimination du bruit à 50Hz par un coupe-bande plus élaboré (Pei-Tseng) +% Élimination du bruit à 50Hz par un coupe-bande plus élaboré (Pei-Tseng) IIR [b, a] = pei_tseng_notch(50 / Fn, 10/Fn); +b = round(b * 2^10); +a = round(a * 2^10); y_minus_50Hz_pei_tseng = filter(b, a, y_minus_BL); -subplot(2,3,5);plot(y_minus_50Hz_pei_tseng(1:1000));title('Pei Tseng band-cut -- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); + +% subplot(2,3,5);plot(y_minus_50Hz_pei_tseng(1:1000));title('Pei Tseng band-cut -- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); % Lissage du bruit haute fréquence par filtre de Parks-McClellan (Low-pass FIR) Fpass = 50; @@ -42,20 +45,20 @@ Fstop = 60; F = [0 Fpass Fstop Fn]/(Fn); A = [1 1 0 0]; fLP = remez(10, F, A); % Génération du filtre -fLP = fLP / sqrt(sum(fLP.^2)) * 2^6; % Normalisation et mise à l'échelle +fLP = round(fLP * 2^10); % Normalisation et mise à l'échelle yLP = filter(fLP, [1], y_minus_50Hz_pei_tseng); % Application du filtre -subplot(2,3,6);plot(yLP(1:1000));title('Low-pass filter to suppress high-freq noise -- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); -figure(2) -subplot(2,1,1);plot(T(:,2));title('Raw ECG signal');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); -subplot(2,1,2);plot(yLP);title('After 3 filters');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); -print(2, "ECG_raw_3filters.pdf", "-dpdflatexstandalone"); +% subplot(2,3,6);plot(yLP(1:1000));title('Low-pass filter to suppress high-freq noise -- zoomed');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); +% figure(2) +% subplot(2,1,1);plot(T(:,2));title('Raw ECG signal');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); +% subplot(2,1,2);plot(yLP);title('After 3 filters');xlabel('Samples (Fs=500Hz)');ylabel('Magnitude (digital signal)'); +% print(2, "ECG_raw_3filters.pdf", "-dpdflatexstandalone"); -figure(3) +% figure(3) % L'artillerie lourde: fonction intégrant la méthode de Pan-Tompkin % Merci Sedghamiz. H !!! -pan_tompkin(T(:,2),500,1); +%pan_tompkin(T(:,2),500,1); % EXPORT DES COEFFICIENTS POUR VHDL % Conversion en entiers signés et exportation @@ -64,19 +67,29 @@ fid = fopen("coeficientes_vhdl.txt", "w"); fprintf(fid, "\n--- Coefficients du filtre Baseline ---\n"); for i = 1:length(fBaseLine) - fprintf(fid, "to_signed(%d, 8),\n", round(fBaseLine(i))); + fprintf(fid, "to_signed(%d, 11),\n", fBaseLine(i)); +end + +%fprintf(fid, "\n--- Coefficients du filtre Notch 50Hz ---\n"); +%for i = 1:length(f50Hz) +% fprintf(fid, "to_signed(%d, 11),\n", f50Hz(i)); +%end + +fprintf(fid, "\n--- Coefficients du filtre Pei-Tseng A ---\n"); +for i = 1:length(a) + fprintf(fid, "to_signed(%d, 11),\n", a(i)); end -fprintf(fid, "\n--- Coefficients du filtre Notch 50Hz ---\n"); -for i = 1:length(f50Hz) - fprintf(fid, "to_signed(%d, 8),\n", round(f50Hz(i))); +fprintf(fid, "\n--- Coefficients du filtre Pei-Tseng B ---\n"); +for i = 1:length(b) + fprintf(fid, "to_signed(%d, 11),\n", b(i)); end fprintf(fid, "\n--- Coefficients du filtre Parks-McClellan ---\n"); for i = 1:length(fLP) - fprintf(fid, "to_signed(%d, 8),\n", round(fLP(i))); + fprintf(fid, "to_signed(%d, 11),\n", fLP(i)); end fclose(fid); -printf("\nOs coeficientes foram salvos em 'coeficientes_vhdl.txt'.\n"); +printf("\nThe coefficients were saved in 'coeficientes_vhdl.txt'.\n");