matlab 从八度到巨蟒

bzzcjhmw  于 2023-08-06  发布在  Matlab
关注(0)|答案(1)|浏览(131)

我把这行八度音翻译成python,但是结果不一样,有人能告诉我问题出在哪里吗?我可以提供的csv如果needeed

八度:

Fs = 500;     % Frequence d'echantillonnage
Fn = Fs/2;    % Frequence de Nyquist
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)');

fBaseLine=fir1(128, 5/Fn, 'high');
fBaseLine

字符串

Python:

import matplotlib.pyplot as plt
from scipy.signal import firwin, lfilter
import csv

Fs = 500  
Fn = Fs / 2  
fig = plt.figure(1)

ecg_signal = []
with open('./ADCSamplesOctave.csv', 'r') as file:
    reader = csv.reader(file)
    for row in reader:
        ecg_signal.append(float(row[1]))

plt.subplot(2, 3, 1)
plt.plot(ecg_signal)
plt.title('Raw ECG signal')
plt.xlabel('Samples (Fs=500Hz)')
plt.ylabel('Magnitude (output of an 11-bit ADC)')

fBaseLine = firwin(129, 5 / Fn, pass_zero=False)  # "high" filter
print(fBaseLine)

  • python结果:*
[ 3.06481816e-04  2.96599543e-04  2.88853370e-04  2.82568524e-04
  2.76939286e-04  2.71033690e-04  2.63799868e-04  2.54074015e-04
  2.40589905e-04  2.21989891e-04  1.96837306e-04  1.63630147e-04
  1.20815920e-04  6.68075226e-05  1.00902679e-18 -8.12119837e-05
 -1.78416126e-04 -2.93164101e-04 -4.26953003e-04 -5.81206792e-04
 -7.57257960e-04 -9.56329590e-04 -1.17951801e-03 -1.42777626e-03
 -1.70189848e-03 -2.00250547e-03 -2.33003162e-03 -2.68471321e-03
 -3.06657840e-03 -3.47543896e-03 -3.91088381e-03 -4.37227461e-03
 -4.85874325e-03 -5.36919155e-03 -5.90229304e-03 -6.45649686e-03
 -7.03003384e-03 -7.62092465e-03 -8.22699010e-03 -8.84586330e-03
 -9.47500390e-03 -1.01117139e-02 -1.07531556e-02 -1.13963702e-02
 -1.20382988e-02 -1.26758042e-02 -1.33056929e-02 -1.39247397e-02
 -1.45297107e-02 -1.51173888e-02 -1.56845976e-02 -1.62282267e-02
 -1.67452552e-02 -1.72327763e-02 -1.76880199e-02 -1.81083747e-02
 -1.84914095e-02 -1.88348924e-02 -1.91368091e-02 -1.93953795e-02
 -1.96090716e-02 -1.97766146e-02 -1.98970092e-02 -1.99695355e-02
  9.79694208e-01 -1.99695355e-02 -1.98970092e-02 -1.97766146e-02
 -1.96090716e-02 -1.93953795e-02 -1.91368091e-02 -1.88348924e-02
 -1.84914095e-02 -1.81083747e-02 -1.76880199e-02 -1.72327763e-02
 -1.67452552e-02 -1.62282267e-02 -1.56845976e-02 -1.51173888e-02
 -1.45297107e-02 -1.39247397e-02 -1.33056929e-02 -1.26758042e-02
 -1.20382988e-02 -1.13963702e-02 -1.07531556e-02 -1.01117139e-02
 -9.47500390e-03 -8.84586330e-03 -8.22699010e-03 -7.62092465e-03
 -7.03003384e-03 -6.45649686e-03 -5.90229304e-03 -5.36919155e-03
 -4.85874325e-03 -4.37227461e-03 -3.91088381e-03 -3.47543896e-03
 -3.06657840e-03 -2.68471321e-03 -2.33003162e-03 -2.00250547e-03
 -1.70189848e-03 -1.42777626e-03 -1.17951801e-03 -9.56329590e-04
 -7.57257960e-04 -5.81206792e-04 -4.26953003e-04 -2.93164101e-04
 -1.78416126e-04 -8.12119837e-05  1.00902679e-18  6.68075226e-05
  1.20815920e-04  1.63630147e-04  1.96837306e-04  2.21989891e-04
  2.40589905e-04  2.54074015e-04  2.63799868e-04  2.71033690e-04
  2.76939286e-04  2.82568524e-04  2.88853370e-04  2.96599543e-04
  3.06481816e-04]

  • octave results:*
Columns 1 through 8:

   2.4893e-04   2.3553e-04   2.2358e-04   2.1229e-04   2.0081e-04   1.8815e-04   1.7324e-04   1.5493e-04

 Columns 9 through 16:

   1.3198e-04   1.0309e-04   6.6897e-05   2.2017e-05  -3.2976e-05  -9.9516e-05  -1.7904e-04  -2.7295e-04

 Columns 17 through 24:

  -3.8264e-04  -5.0944e-04  -6.5462e-04  -8.1936e-04  -1.0048e-03  -1.2118e-03  -1.4413e-03  -1.6940e-03

 Columns 25 through 32:

  -1.9706e-03  -2.2713e-03  -2.5964e-03  -2.9460e-03  -3.3200e-03  -3.7181e-03  -4.1396e-03  -4.5840e-03

 Columns 33 through 40:

  -5.0503e-03  -5.5374e-03  -6.0439e-03  -6.5684e-03  -7.1092e-03  -7.6645e-03  -8.2321e-03  -8.8100e-03

 Columns 41 through 48:

  -9.3958e-03  -9.9871e-03  -1.0581e-02  -1.1176e-02  -1.1768e-02  -1.2354e-02  -1.2933e-02  -1.3500e-02

 Columns 49 through 56:

  -1.4054e-02  -1.4591e-02  -1.5108e-02  -1.5604e-02  -1.6074e-02  -1.6517e-02  -1.6931e-02  -1.7312e-02

 Columns 57 through 64:

  -1.7659e-02  -1.7970e-02  -1.8244e-02  -1.8478e-02  -1.8671e-02  -1.8822e-02  -1.8931e-02  -1.8997e-02

 Columns 65 through 72:

   9.8073e-01  -1.8997e-02  -1.8931e-02  -1.8822e-02  -1.8671e-02  -1.8478e-02  -1.8244e-02  -1.7970e-02

 Columns 73 through 80:
-1.7659e-02  -1.7312e-02  -1.6931e-02  -1.6517e-02  -1.6074e-02  -1.5604e-02  -1.5108e-02  -1.4591e-02

 Columns 81 through 88:

  -1.4054e-02  -1.3500e-02  -1.2933e-02  -1.2354e-02  -1.1768e-02  -1.1176e-02  -1.0581e-02  -9.9871e-03

 Columns 89 through 96:

  -9.3958e-03  -8.8100e-03  -8.2321e-03  -7.6645e-03  -7.1092e-03  -6.5684e-03  -6.0439e-03  -5.5374e-03

 Columns 97 through 104:

  -5.0503e-03  -4.5840e-03  -4.1396e-03  -3.7181e-03  -3.3200e-03  -2.9460e-03  -2.5964e-03  -2.2713e-03

 Columns 105 through 112:

  -1.9706e-03  -1.6940e-03  -1.4413e-03  -1.2118e-03  -1.0048e-03  -8.1936e-04  -6.5462e-04  -5.0944e-04

 Columns 113 through 120:

  -3.8264e-04  -2.7295e-04  -1.7904e-04  -9.9516e-05  -3.2976e-05   2.2017e-05   6.6897e-05   1.0309e-04

 Columns 121 through 128:

   1.3198e-04   1.5493e-04   1.7324e-04   1.8815e-04   2.0081e-04   2.1229e-04   2.2358e-04   2.3553e-04

 Column 129:

   2.4893e-04

bejyjqdl

bejyjqdl1#

结果不一样,但非常接近。差异来自舍入错误以及Octave fir1函数与Python firwin函数实现的差异。要理解差异来自何处,就需要详细理解这两个函数的实现。
下面是python(X)与octave(Y)

的结果
放大原点:

相关问题