MATLAB: How to achieve downsampling using an MATLAB file S-function in Simulink 7.4 (R2009b)

simulink

I am trying to create a block that takes in an input of varying sizes (512, 1024, 2048, etc.) and after scaling and processing, downsamples the input to produce only an integer fraction of the number of inputs. I have all the processing code, but I can't make the port dimensioning work. How do I do it ?

Best Answer

For frame based inputs and outputs, the output port dimensions are dependent on the input port dimensions; therefore the outport dimensions must be set in SetInputPortDimensions callback function. The attached single-rate model "testMult.mdl" demonstrates this using the S-function in MATLAB file "MDownsample.m". The model takes in a signal of frame size 2048x1 and outputs a signal of frame size 8x1.