Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Lab2.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <math.h>
- #include <fstream>
- #include <stdlib.h>
- #include <time.h>
- using namespace std;
- int sample_count(float time, float sample) {
- int sample_count = 0;
- for (float i = 0; i <= time; i += sample) {
- sample_count++;
- }
- return sample_count;
- }
- void amplitude_modulation(float amplitude_info, float frequency_info, float phase_info, float amplitude_carry, float frequency_carry, float phase_carry, float time, float sample, float kAM, fstream& file, string name)
- {
- file.open(name, ios::out);
- int N = sample_count(time, sample);
- float *m = new float[N]; //sygnał nośny
- float *s = new float[N]; //sygnał informacyjny
- float *w = new float[N]; //sygnał zmodulowany
- float i = 0;
- for (int t = 0; t < N; t++)
- {
- s[t] = amplitude_info * sin(2 * M_PI * frequency_info * i + phase_info);
- m[t] = amplitude_carry * sin(2 * M_PI * frequency_carry * i + phase_carry);
- w[t] = m[t] * ((kAM * s[t]) + 1);
- file << s[t] << "," << m[t] << "," << w[t] << endl;
- i += sample;
- if (i > time) {
- break;
- }
- }
- delete m, s, w;
- file.close();
- }
- void frequency_modulation(float amplitude_signal, float pulsation_signal, float phase_signal, float time, float sample, float amplitude, float frequency, float kFM, fstream& file, string name)
- {
- file.open(name, ios::out);
- int N = sample_count(time, sample);
- float *s = new float[N];
- float *w = new float[N];
- float i = 0;
- int index = 0;
- for (float i = 0; i <= time; i += sample) {
- s[index] = amplitude_signal * sin(pulsation_signal * i + phase_signal);
- index++;
- }
- for (int t = 0; t < N; t++)
- {
- float O = (2 * M_PI * frequency * t) + (kFM *s[t]);
- w[t] = amplitude * cos(O);
- file << s[t] << "," << w[t] << endl;
- i += sample;
- }
- file.close();
- }
- int main()
- {
- fstream modulation;
- amplitude_modulation(1, 40, 1, 2, 20, 1, 2, 0.001, 2, modulation, "amplitude_modulation.csv");
- frequency_modulation(1, 251.327, 1, 2, 0.001, 1, 5, 20, modulation, "frequency_modulation.csv");
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement