Why do I receive an error "Undefined function 'cos' for input

Illustration
Victoria - 2021-03-08T10:03:47+00:00
Question: Why do I receive an error "Undefined function 'cos' for input

Why do I receive an error "Undefined function 'cos' for input arguments of type 'int32'" in Signal Processing Toolbox 6.16 (R2011b)? I have written a function in  MATLAB that uses the WINDOW function from the Signal Processing Toolbox (in this example, I call the WINDOW function with the BLACKMAN window type). Why do I receive an error? Reproduction steps:     N = int32(2048); awin = window(@blackman,N) Resulting error message: Undefined function 'cos' for input arguments of type 'int32'. Error in gencoswin>calc_window (line 90) w = 0.42 - 0.5*cos(2*pi*x) + 0.08*cos(4*pi*x); Error in gencoswin>sym_window (line 59) w = calc_window(half,n,window); Error in gencoswin (line 46) w = sym_window(n,window); Error in blackman (line 17) [w,msg,msgobj] = gencoswin('blackman',varargin{:}); Error in window (line 54) w = feval(wname,N,varargin{:});  

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

Workaround:
Recast the "N" parameter of WINDOW as a DOUBLE before calling the WINDOW function. Here is an example:
 
N = double(N);

awin = window(@blackman,N);
Explanation:
The MATLAB function WINDOW has a parameter N that specifies the length of the generated window. This parameter must be of type "double" because it is later used in the COS function, which cannot operate on "integer" data types.


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!