resample() function in code generation. Any way to use variable Q downsampling factor?

3 ビュー (過去 30 日間)
Arya
Arya 2016 年 8 月 10 日
回答済み: Dimitris Kalogiros 2018 年 7 月 23 日
Hi,
I need to use resample() function to take a variable argument of Q downsampling factor in Simulink. Basically a Simulink fcn block containing this code:
function y = resample_with_VarQ(data,Q)
y=resample(data,1000,Q);
On desktop simulation I can get variable Q to work as argument by specifying it as input to a MATLAB interpreted function, but since I need to generate a C code,my only option is to use the fcn block, obviously it won't compile due to non-constant Q. (i.e. error: the downsample factor Q must be constant)
I understand this is a documented limitation of the resample function:
resample: The upsampling and downsampling factors must be specified as constants. Expressions or variables are allowed if their values do not change.
Any workaround or different approach to address this? Perhaps other block which is capable of doing the same job? ofc it has to be compatible with Simulink coder.
Thanks!
  2 件のコメント
Pontus Carlsson
Pontus Carlsson 2018 年 1 月 22 日
First sorry for replying to old post, but seems to be exactly my issue.
Currently doing an implementation trying to utilize the resample function in a function block inside a simulink model and receives the same error.
Is there any known workaround to make a non-uniform signal into uniform and resample?
Dimitris Kalogiros
Dimitris Kalogiros 2018 年 7 月 23 日
I think is impossible to perform "variable-rate resampling" inside Simulink. The reason is that such a block would change its outpout sampling rate during run-time and this is forbidden in simulink.
The only workarround I can think is to implement a virtual resampling, where the resampling block would produce always the same number of output samples per input samples, accompanied by a "control signal" which would indicate the validity of the output samples.

サインインしてコメントする。

回答 (1 件)

Dimitris Kalogiros
Dimitris Kalogiros 2018 年 7 月 23 日
I think is impossible to perform "variable-rate resampling" inside Simulink. The reason is that such a block would change its outpout sampling rate during run-time and this is forbidden in simulink.
The only workarround I can think is to implement a virtual resampling, where the resampling block would produce always the same number of output samples per input samples, accompanied by a "control signal" which would indicate the validity of the output samples.

Community Treasure Hunt

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

Start Hunting!

Translated by