Error in Build,deploy android app model using Accelerometer sensor.

function [peaks, peakno]= Accelerometerdata(Acceleration)
z = Acceleration.Z;
smtlb = sgolayfilt(z,9,21);
peaks=findpeaks(smtlb,t,'MinPeakDistance',1);
peakno=numel(findpeaks(smtlb));
end

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 1 月 31 日
Is there a particular reason your last line is not
peakno = numel(peaks);
??
I would suggest that you pre-allocate peaks and that you pass the maximum size as NPeaks to findpeaks() . That will prevent Simulink from complaining about peaks being unknown size.

5 件のコメント

Kelvin John
Kelvin John 2023 年 1 月 31 日
I am trying to acquire the accelerometer Z signal to display the filtered signal and use the find feaks command and display the number number of peaks in the signal.
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component:MATLAB Function | Category:Coder error
Property 'Z' is not recognized as valid. Function 'MATLAB Function' (#24.64.78), line 4, column 5: "Acceleration.Z" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'z'. The first assignment to a local variable determines its class. Function 'MATLAB Function' (#24.100.101), line 6, column 20: "z" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'smtlb'. The first assignment to a local variable determines its class. Function 'MATLAB Function' (#24.125.130), line 7, column 17: "smtlb" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable 'smtlb'. The first assignment to a local variable determines its class. Function 'MATLAB Function' (#24.178.183), line 8, column 24: "smtlb" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'androidscopesimjohn/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'androidscopesimjohn/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Component:MATLAB Function | Category:Coder error
You should expect this. findpeaks() can return a list of peaks that is anywhere between empty and half the length of the original data. Static analysis does not have any way of knowing how many peaks are going to be returned.
If you do
maxpeaks = 50;
peaks = zeros(1, maxpeaks);
coder.varsize('peaks', [1 maxpeaks]);
peaks = findpeaks(smtlb, t, 'MinPeakDistance', 1, 'NPeaks', maxpeaks);
peakno = numel(peaks);
Now Simulink can be sure of the maximum size of peaks.
Note that passing around variable-sized arrays in Simulink can be tricky.
Kelvin John
Kelvin John 2023 年 2 月 8 日
I tried woking on the size of peaks, however im facing an issue such as below;
The simulink file is attached here in the attachement, kindly have a look and advice on the following to on advice on how i can run the code.
=== Simulation (Elapsed: 4 sec) ===
Error:Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Error:The length of the input must be >= frame length.
Function 'MATLAB Function' (#35.87.105), line 6, column 9:
"sgolayfilt(z,9,21)"
Launch diagnostic report.
Error:coder.varsize cannot change the size of the block output 'peaks'. Use block configuration dialog to modify the size of the output.
Function 'MATLAB Function' (#35.164.171), line 9, column 15:
"'peaks'"
Launch diagnostic report.
Error:Undefined function or variable 'smtlb'. The first assignment to a local variable determines its class.
Function 'MATLAB Function' (#35.207.212), line 11, column 19:
"smtlb"
Launch diagnostic report.
Error:Errors occurred during parsing of MATLAB function 'androidscopesimjohn/MATLAB Function'
Error:Simulink cannot determine sizes and/or types of the outputs for block 'androidscopesimjohn/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Error:Simulink cannot determine sizes and/or types of the outputs for block 'androidscopesimjohn/MATLAB Function' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.
Error:Port width mismatch. Input 'Acceleration' expects a signal of size 1. The signal received is of size [1x1].
Walter Roberson
Walter Roberson 2023 年 2 月 8 日
Suppose that you did manage to return a variable-length list of peak heights. What would you do with the variable-length list downstream ?
Kelvin John
Kelvin John 2023 年 2 月 8 日
plot the accelerometer signal, to show the peaks in the signal to determine the number of peaks in the signal

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

カテゴリ

質問済み:

2023 年 1 月 31 日

コメント済み:

2023 年 2 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by