#include #include #include #define SAMPLING_RATE 800.0 // Sampling rate in Hz #define AMPLITUDE 1.5 // Amplitude for all sinusoidal waves in volts #define NUM_SAMPLES 800 // Number of samples #define NUM_WAVES 3 // Number of sinusoidal waves #define NUM_PERIODS 5 // Number of periods to generate double samples[NUM_WAVES][NUM_SAMPLES] = {0}; // Array to store samples void generateSinusoidal(int frequency, double *value, double *phase); void generateSamples() { // Generate sinusoidal samples for frequencies 100 Hz, 200 Hz, and 400 Hz generateSinusoidal(100, samples[0], &samples[0][0]); generateSinusoidal(200, samples[1], &samples[1][0]); generateSinusoidal(400, samples[2], &samples[2][0]); } int main() { double time = 0.0; double sampleNumber = 0.0; int periodsGenerated = 0; // Generate samples for a certain duration (e.g., 1 second) for (int i = 0; i < SAMPLING_RATE * NUM_PERIODS; ++i) { // Check if five periods have been generated if (i % (int)SAMPLING_RATE == 0) { periodsGenerated++; if (periodsGenerated > NUM_PERIODS) { printf("xxxxx\n"); break; // Stop generating numbers } } // Initialize values for each iteration double sampleValues[3] = {0.0}; // Generate samples generateSamples(); // Print the output for each sample printf("vzorek-číslo:%.0f\t%.5f\t100Hz:%.5f\t200Hz:%.5f\t400Hz:%.5f\n", sampleNumber, time, samples[0][i], samples[1][i], samples[2][i]); // Increment time and sample number time += 1.0 / SAMPLING_RATE; sampleNumber += 1.0; } return 0; } void generateSinusoidal(int frequency, double *value, double *phase) { // Generate sinusoidal samples for a given frequency and amplitude for (int i = 0; i < NUM_SAMPLES; ++i) { value[i] = AMPLITUDE * sin(2.0 * M_PI * frequency * phase[i]); // Increment the phase for the next sample phase[i] += 1.0 / SAMPLING_RATE * frequency; } }