Limitations of Embedded MATLAB functions: Filter design in EMF possible?

1 view (last 30 days)
Please note that I am using Matlab 2009b for my project. Nonetheless, I am convinced that this does affect later versions as well.
I have the following simple setup that does not work:
  • My MATLAB script to execute the simulation:
clc
sim('main');
  • The Simulink Model with the EMF:
The content of the embedded MATLAB function:
function output = PSF_SW(freq_peak)
order = 30;
freq = [0 freq_peak-0.2 freq_peak-0.1 freq_peak+0.1 freq_peak+0.2 1];
mag = [0 0 1 1 0 0];
output = firpm(order,freq,mag);
Executing the MATLAB script, I receive the error message:
??? Error using ==> runmain at 4
Error due to multiple causes.
Caused by:
Error using ==> runmain at 4
Error reported by S-function 'sf_sfun' in
'main/Embedded MATLAB Function/ SFunction ':
Errors occurred during parsing of Embedded MATLAB
function 'Embedded MATLAB
Function'(#18)
Error using ==> runmain at 4
Error in port widths or dimensions. Output port 1 of
'main/Embedded MATLAB Function/freq_peak' is a one
dimensional vector with 1 elements
As you can see, I want to design a digital bandpass filter in real-time. However, this seems to be impossible since the error occurs each time the inputs of firpm depend on the inputs of the EMF. I do not receive an error, if I define freq_peak inside the EMF. Is there another way to do this? Is this problem related to the fact that MATLAB's code generation procedure does not allow dynamic memory allocation?

Answers (0)

Categories

Find more on Introduction to Installation and Licensing in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!