Using Decimate fails with downsample parameter is a variable. Why?

4 views (last 30 days)
Hello all. I´m using Matlab2013.
I have a single-channel signal stored in a matrix, which i can process with standard commands. I used GLIDE to build a simple GUI to freely transform the signal with a slider... all transformations work so far.
The idea is to increase or decrease the decimation factor with the slider... which should be simple, right?.. Well, not quite.
If i execute this instructions:
NEWSIGNAL = decimate(ORIGINAL,10000);
TimeVector = decimate(TimeVector,10000);
It works and i downsample te signal by a factor of 10000.
However.. if i use a variable instead of a number in the second parameter, such as:
TimeVector = decimate(TimeVector,SLIDERVALUE);
The following error message pops every time i change the slider value.
Error using cheby1 (line 59)
The cutoff frequencies must be within the interval of (0,1).
Error in decimate (line 122)
[b,a] = cheby1(nfilt, rip, .8/r);
Error in Lab3>sumarN_Callback (line 217)
I suspected the variable type of SLIDERVALUE was not being an integer, but indeed it is... its actually an int16.
Why is the decimate() function working when i use a static integer as decimation factor, but failing when i use a variable as factor ??
I tried to pass a variable manually set to 10000 and it works fine. But it will not work with the int16() i get from the slider... What kind of cast type variable is the function expecting?
I tried doing SLIDERVALUE+0 and SLIDERVALUE/1 as arguments to force a more standard type as parameter... and nothing.
Pedro Universidad el Bosque

Answers (1)

Pedro GUillem
Pedro GUillem on 4 Apr 2017
Ok.. I just answered myself.
It turns out if i do this
r = 10000;
It works because the "r" variable is being auto-declared as a DOUBLE... i was passing an INT.... Go figure: the documentation of the decimate() function clearly states the downsample factor HAS TO BE AN INTEGER. (See the attached pic).
The solution is to do this to my slider int value:
r = double(abs(slidervalue));
Seriously MATLAB dudes... this software is damn expensive. So make up your minds around the arguments of functions needing to be an "integer in a double format", or an "integer in an int format" :-S

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!