环境:python 3.5
matlab R2016b 注意:matlab2016 支持的python最高版本为3.5
步骤1: 进入此文件夹 运行命令:
python setup.py install
步骤二:
pip 安装各种包
步骤三: 你就可以使用呢
接下里验张python 和MATLAB 混编,本文作者采用的是python 调用matlab ,
MATLAB代码:
function a = triangle(b,h)
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
S = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t);
%Corrupt the signal with zero-mean white noise with a variance of 4.
X = S + 2*randn(size(t));
figure();
subplot(211);
plot(1000*t(1:50),X(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')
Y = fft(X);
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
f = Fs*(0:(L/2))/L;
subplot(212)
plot(f,P1)
title('Single-Sided Amplitude Spectrum of X(t)')
xlabel('f (Hz)')
ylabel('|P1(f)|')
a=1
python 代码:
# coding=utf-8
import time
import matlab.engine
import os
eng = matlab.engine.start_matlab()
fs=360
print(eng.triangle(2,3))
os.system("pause")
#time.sleep(10)
#[RR,brady,tachy,PVC,PAC]=eng.ECG_diagnosis(sig,fs)
#print (ans)
eng.quit()
参考:
https://zhuanlan.zhihu.com/p/30630608
https://ww2.mathworks.cn/help/matlab/matlab-engine-for-python.html