Clear Filters
Clear Filters

how to define initial dimention to variable that has various dimention in matlab function block simulink?

1 view (last 30 days)
I define matlab function block that compute continuos wavelet transfrom(CWT) in simulink and have problem to initialize output of cwt, because the wavelet coefficients have various dimention in each time step.
  1. how should i define initial value of cwt output?
  2. and how should i write that every 0.5 second pass, compute cwt?(not in all time steps)
my FCN code:
function [c,f]=cwtendpadding(x)
coder.extrinsic('cwt')
c=zeros(401)+0i;
f=nan(200,1);
global x_hist x_ind
x_hist(x_ind)=x;
x_ind = x_ind+1;
if x_ind>=100
[c,f]=cwt(x_hist(1:x_ind-1),'amor',1000,'ExtendSignal',false);
end
end
error: Size mismatch for MATLAB expression 'c'. Expected = 401x401 Actual = 38x99

Answers (1)

Shree Harsha Kodi
Shree Harsha Kodi on 30 Jun 2023
To initialize the output of the Continuous Wavelet Transform (CWT) block in Simulink, you can use a constant block that matches the expected dimensions of the wavelet coefficients. Since the wavelet coefficients have varying dimensions at each time step, you can set the initial value to an empty matrix or a zero matrix.
Regarding computing the CWT every 0.5 seconds, you can use the Sample Time parameter in Simulink to control the timing of the CWT computation
Go through the following documentation for a better understanding:
1)https://in.mathworks.com/help/wavelet/ref/cwt.html
2)https://in.mathworks.com/help/simulink/ug/model-configuration-parameters.html
3)https://in.mathworks.com/help/simulink/ug/block-libraries.html
  1 Comment
NIKOLAY YAKOVENKO
NIKOLAY YAKOVENKO on 6 Nov 2023
Well , usage of coder.extrinsic('cwt') points to the fact that you can create such matlab function block in Simulink (CWT), and it will work, but cannot generate production quality code using embedded coder? That is what happened to me.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!