Convolution in Simulink Wrong? element-wise multiplication instead of convolution 2018b

3 views (last 30 days)
Block diagram is very simple like this Screenshot from 2019-01-03 09-48-12.png
simData.xt, simData.ht are periodic trigonometric polynomial signals (fourier series) and are imported from MATLAB workspace variables with cyclic repetition enabled.
The output with both convolution and FIR filtering return element-wise multiplication result between the two inputs.
This is confirmed by checking the result against element-wise mulitiplication manually, as well as through Code Generation, which returns this block:
```
84 /* S-Function (sdspconvcorr): '<Root>/Convolution1' incorporates:
85 * DiscreteFir: '<Root>/Discrete FIR Filter'
86 * Outport: '<Root>/output1'
87 * Outport: '<Root>/output2'
88 */
89 y_conv_tmp = test_simulink_slink_Y.output1 * test_simulink_slink_Y.output2;
90
91 /* Outport: '<Root>/y_conv' incorporates:
92 * S-Function (sdspconvcorr): '<Root>/Convolution1'
93 */
94 test_simulink_slink_Y.y_conv = y_conv_tmp;
95
96 /* Outport: '<Root>/y_fir' */
97 test_simulink_slink_Y.y_fir = y_conv_tmp;
```
At link 89, we see that the y_conv_tmp result is just a multiplication of the two signals (which are sent to output ports in this case).
--
I'm sure I'm doing something wrong but can't figure out what.

Accepted Answer

Tingkai Liu
Tingkai Liu on 5 Jan 2019
Solved my own problem.
The problem is my lack of understanding for sample-based vs frame-based processing. https://www.mathworks.com/help/dsp/ug/sample-and-frame-based-concepts.html
Essentially, the from workspace block seem only to support sample-based processing, in which case the signal is being fed-in one at a time. This is a problem because at each given time-step of the simulation, only 1 value of the impulse response of the filter (simData.ht ) is available. Hence, the convolution is between 2 scalar values.
To fix this, use the signal from workspace block, which supports conversion to frame-based signals from workspace arrays. I set the size of the frame (number of samples in one frame per one time-step) to be the same length as the signals, putting the entire array in a signal frame. I then set the simulation stop time to be 0. What this does is cheating the simulation by saying that I'm only simulation 1 time-step, but this 1 time step contains entire time series data from workspace.

More Answers (0)

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!