1
$\begingroup$

I tried to call decimate function in Scipy from Matlab but met an error. Can somebody point me in a direction, please?

Here is a code of Matlab

py.print("Hello, Python!")
% generate a sin signal
clear
fc=2;  % in Hz
f_sampling=100;   %in Hz
t=0:1/f_sampling:3;  %in 3s
y=sin(2*pi*fc.*t);   % signal
plot(t,y)
y_dem=py.scipy.signal.decimate(y,5); 

>> try_python
Hello, Python!
Error using signaltools>decimate (line 4401)
Python Error: TypeError: 'float' object cannot be interpreted as an integer
 
$\endgroup$
5
  • 1
    $\begingroup$ Code did not show line by line. Retype it for easy reading $\endgroup$ Commented May 7 at 14:39
  • 1
    $\begingroup$ fc=2; % in Hz f_sampling=100; %in Hz t=0:1/f_sampling:3; %in 7ms y=sin(2*pi*fc.*t); % signal $\endgroup$ Commented May 7 at 14:41
  • 1
    $\begingroup$ sorry, I am not able make it line by line $\endgroup$ Commented May 7 at 14:42
  • 1
    $\begingroup$ You can use the {} button to format text as code. Hover over the buttons and they tell you what they do $\endgroup$
    – Hilmar
    Commented May 7 at 15:01
  • $\begingroup$ Thank you, Hilmar $\endgroup$ Commented May 7 at 16:10

1 Answer 1

1
$\begingroup$

Matlab uses double values by default. Scipy.signal.decimate expects an integer as the second argument, the decimation factor.

Explicitly convert your decimation factor to an integer type:

y_dem=py.scipy.signal.decimate(y,int32(5));
$\endgroup$
1
  • $\begingroup$ Hi Jdip. It works. Thank you very much for your quick reply. $\endgroup$ Commented May 7 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.