MCPcopy Create free account
hub / github.com/Hamlib/Hamlib / interpolateSWR

Function interpolateSWR

rigs/dummy/flrig.c:2314–2339  ·  view source on GitHub ↗

Function to interpolate SWR from MTR

Source from the content-addressed store, hash-verified

2312
2313// Function to interpolate SWR from MTR
2314float interpolateSWR(float mtr)
2315{
2316 int i;
2317
2318 for (i = 0; i < sizeof(swrtbl) / sizeof(swrpair) - 1; i++)
2319 {
2320 if (mtr == swrtbl[i].mtr)
2321 {
2322 // Exact match
2323 return swrtbl[i].swr;
2324 }
2325
2326 if (mtr < swrtbl[i + 1].mtr)
2327 {
2328 // Perform linear interpolation
2329 float slope = (swrtbl[i + 1].swr - swrtbl[i].swr) / (swrtbl[i + 1].mtr -
2330 swrtbl[i].mtr);
2331 float swr = round((swrtbl[i].swr + slope * (mtr - swrtbl[i].mtr)) * 10) / 10.0;
2332 rig_debug(RIG_DEBUG_VERBOSE, "%s: swr=%f\n", __func__, swr);
2333 return swr;
2334 }
2335 }
2336
2337 // If mtr is not within the range of values in the table, you could choose to return an error or extrapolate
2338 return 10; // Example er
2339}
2340/*
2341* flrig_get_level
2342* Assumes rig!=NULL, STATE(rig)->priv!=NULL, val!=NULL

Callers 1

flrig_get_levelFunction · 0.85

Calls 1

rig_debugFunction · 0.85

Tested by

no test coverage detected