f



Matlab 2011: matlab coder (build failed)

When I create a MATLAB Coder Project and try to convert this function:

-------------------------
function y = myResampler(x,m,n) %#codegen

fsVec = [8000 16000 32000 48000];
targetFsVec = [8000 16000 32000 48000];

fs = fsVec(m);
targetFs = targetFsVec(n);

y = resample(x,targetFs,fs);
-------------------------

to C-code I get a build error saying:

coder -build resamplerproj.prj ??? The upsample factor P must be constant. 
Error in ==> myResampler Line: 12 Column: 5 Code generation failed: Open 
error report.



But I want to be able to resample x using a variable P/Q ratio.

Is this just a limitation of Matlab Coder or am I doing something wrong?? 

0
john5939 (28)
5/2/2011 5:43:36 PM
comp.soft-sys.matlab 211266 articles. 23 followers. lunamoonmoon (257) is leader. Post Follow

4 Replies
1616 Views

Similar Articles

[PageSpeed] 54

John wrote:
> When I create a MATLAB Coder Project and try to convert this function:
>
> -------------------------
> function y = myResampler(x,m,n) %#codegen
>
> fsVec = [8000 16000 32000 48000];
> targetFsVec = [8000 16000 32000 48000];
>
> fs = fsVec(m);
> targetFs = targetFsVec(n);
>
> y = resample(x,targetFs,fs);
> -------------------------
>
> to C-code I get a build error saying:
>
> coder -build resamplerproj.prj ??? The upsample factor P must be
> constant. Error in ==> myResampler Line: 12 Column: 5 Code generation
> failed: Open error report.
>
>
>
> But I want to be able to resample x using a variable P/Q ratio.
>
> Is this just a limitation of Matlab Coder or am I doing something wrong??

Apparently it's a limitation of RESAMPLE in the Signal Processing 
Toolbox.  The documentation (my version) in the "Functions Supported for 
Code Generation" table says "The upsampling and downsampling factors 
must be specified as constants. Expressions or variables are allowed if 
their values do not change."

--
Mike
0
mhosea (110)
5/2/2011 6:06:38 PM
"John" <john@nospam.thanks> wrote in message <4dbeed4f$0$309$14726298@news.sunsite.dk>...
> When I create a MATLAB Coder Project and try to convert this function:
> 
> -------------------------
> function y = myResampler(x,m,n) %#codegen
> 
> fsVec = [8000 16000 32000 48000];
> targetFsVec = [8000 16000 32000 48000];
> 
> fs = fsVec(m);
> targetFs = targetFsVec(n);
> 
> y = resample(x,targetFs,fs);
> -------------------------
> 
> to C-code I get a build error saying:
> 
> coder -build resamplerproj.prj ??? The upsample factor P must be constant. 
> Error in ==> myResampler Line: 12 Column: 5 Code generation failed: Open 
> error report.
> 
> 
> 
> But I want to be able to resample x using a variable P/Q ratio.
> 
> Is this just a limitation of Matlab Coder or am I doing something wrong?? 

Hi John, You have to specify the upsampling and decimation factors as constants, or you can use expressions or variables within your code as long as those values don't change.

For example:

function y = myResampler(x,P,Q) %#codegen
y = resample(x,P,Q);

Now let's say you want to take a 512x1 input vector and resample it at 3/2 times the initial sample rate. 

This command will generate your C code:

codegen myResampler  -o myResampler -args {zeros(512,1), coder.newtype('constant',3),coder.newtype('constant',2) } -report

You can call the MEX file generated by the above with:

y = myResampler(randn(512,1));


Hope that helps,
Wayne
0
wmkingty (1430)
5/2/2011 6:43:21 PM
Thank you so much :o)


0
john5939 (28)
5/2/2011 8:59:47 PM
"John" <john@nospam.thanks> wrote in message <4dbeed4f$0$309$14726298@news.sunsite.dk>...
> When I create a MATLAB Coder Project and try to convert this function:
> 
> -------------------------
> function y = myResampler(x,m,n) %#codegen
> 
> fsVec = [8000 16000 32000 48000];
> targetFsVec = [8000 16000 32000 48000];
> 
> fs = fsVec(m);
> targetFs = targetFsVec(n);
> 
> y = resample(x,targetFs,fs);
> -------------------------
> 
> to C-code I get a build error saying:
> 
> coder -build resamplerproj.prj ??? The upsample factor P must be constant. 
> Error in ==> myResampler Line: 12 Column: 5 Code generation failed: Open 
> error report.
> 
> 
> 
> But I want to be able to resample x using a variable P/Q ratio.
> 
> Is this just a limitation of Matlab Coder or am I doing something wrong?? 

Sorry for bumping old thread, but is there any workaround to this limitation?
I absolutely need to use variable Q downsampling factor in my code and need to generate a C code from it.

Thanks!
0
Arya
8/10/2016 12:50:03 PM
Reply: