0

I have generated a C code using MATLAB coder which takes 2000 data points and then tries to find out the peaks in that data. You can see my main.c code bellow:

#include <stdio.h>
#include <stdlib.h>
#include "MYALGORITHM.h"

double PPG[2000]={0};
double a;
double heart_rate,summation;

int main()
{

    MYALGORITHM(PPG,1,1,&heart_rate,&summation);
    printf("%f",heart_rate);



}

I am not able to run this main code the error is as follows:

||=== Build: Debug in Heart_rate_Algorithm_test (compiler: GNU GCC Compiler) ===|
obj\Debug\main.o||In function `main':|
C:\Users\Syed Mir Hamza\Desktop\Heart_rate_Algorithm_test\main.c|12|undefined reference to `MYALGORITHM'|
||error: ld returned 1 exit status|
||=== Build failed: 2 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

can someone please help me out in this the. I have also generated a separate Addition function and it worked fine. Right now I added both the summation and peak detection algorithm in the same MATLAB function which is as follows:

function [HR,sum] = MYALGORITHM(PPG,k,l)
    
    a = PPG(1:2000,:);
    PKS = findpeaks(a,'MinPeakDistance',200);
    HR = length(PKS)*7.25;
    sum = k + l;

end

I would be really thankful if someone can help me out. Thanks in advance.

  • The error you are seeing is a linker error (https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) Without knowing what is in your ALGORITHM.h and how this is being built, it is difficult to say what the fix is. MATLAB Coder can generate an example main function that should work out of the box. Have you tried it ? See the following documentation to learn more: https://www.mathworks.com/help/coder/ug/generate-an-example-cc-main-function.html – ami91 Oct 24 '22 at 14:04

0 Answers0