0
我想將一些Matlab代碼轉化爲Python。我遇到切片問題。Matlab vs Python:切片
MATLAB代碼:
demod_1_b=-1*mod_noisy*2.*sin(2*pi*Fc*t+phi);
y = filter(Hd,demod_1_b);
y2=conv(y,raised)/ConvFac;
%% till this line the length in python and Matlab are same
y2=y2(sa/2:end-(sa/2));
%%%% when i write this line in Python it gives me wrong answer it should come out as 26 but in python it gives me 33 i think i havnt converted it in a rigth way
demod_3_b=y2(sa/2:sa:end);
Python代碼:
demod_1_b=-1*mod_noisy*2*sin((2*pi*Fc*t)+phi)
N=10
Fc=40
Fs=1600
d=firwin(numtaps=N,cutoff=40,nyq=Fs/2)
print(len(d))
Hd=lfilter(d, 1.0, demod_1_b)
y2=(convolve(Hd,raised))/Convfac
print(len(y2))
y2=y2[(sa/2)-1:-sa/2]
print(len(y2))
# problem starts here
demod_3_b=y2[(sa/2)-1:sa:,]
print(len(demod_3_a))
我只想問,在Matlab demod_3_b=y2(sa/2:sa:end);
和demod_3_v=y2[(sa/2)-1:sa:,]
在Python一樣嗎?
抱歉無法發佈整個代碼非常巨大 –
你甚至想要做什麼?您是否可以將代碼修剪爲一個簡短的,自包含的,可運行的代碼片段,以顯示問題? – user2357112