MMS-Loesung-2024-25/MMS24_25.c

42 lines
1.1 KiB
C

//
// Created by minhd on 03.12.2024.
//
#include "MMS24_25.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
double interpolateLine(double x1, double y1,double x2, double y2, double x){
double y = ((y2 - y1) / (x2 - x1)) * x + y1 - ((y2 - y1) / (x2 - x1)) * x1;
return y;
}
void rescaleDoubleArray(double *pdIn, int iLen, int iMin, double dFactor, double *pdOut){
for (int i = 0; i < iLen; i++) {
pdOut[i] = pdIn[i + iMin] * dFactor;
}
}
double *generateSineValues(int iNumValues, int iNumSamplesPerPeriod, double dAmp){
double* sineArray = (double*)malloc(iNumValues * sizeof(double));
for (int i=0; i<iNumValues;i++){
sineArray[i] = dAmp*sin(((2*M_PI)/iNumSamplesPerPeriod) * i);
}
return sineArray;
}
void writeDoubleArray(double *pdOut, int iLen, char *pcOutName) {
FILE* datei = fopen(pcOutName, "w");
if (datei == NULL) {
printf("Fehler beim Öffnen der Datei.\n");
return;
}
for (int i = 0; i < iLen; i++) {
fprintf(datei, "%f\n", pdOut[i]);
}
fclose(datei);
}