Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Sebastian Bolewicz grupa 37A
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <math.h>
- #include <cmath>
- #include <bitset>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- MainWindow::makePlot();
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
- void MainWindow::makePlot()
- {
- //
- //Lab5
- //Demodulacja sygnału za(t)
- int A1 = 1, A2 = 2, fn = 14; //N = 2; Tb = 1/7
- double Tb = 1.0/7.0;
- double fs = 2000;
- //double counter;
- std::bitset<7> bit;
- bit[0] = 1;
- bit[1] = 1;
- bit[2] = 0;
- bit[3] = 0;
- bit[4] = 0;
- bit[5] = 1;
- bit[6] = 1;
- QVector<double> Z(fs*1), za(fs*1), san(fs*1), x(fs*1); // initialize
- for(int n=0; n<7; n++)
- {
- double counter = 0;
- for(int i=n*fs*Tb; i<fs*Tb*(n+1); i++)
- {
- double t = (double)i/fs;
- if(bit[n] == 0)
- {
- za[i] = A1*sin(2*M_PI*fn*t);
- san[i] = A2*sin(2*M_PI*fn*t);
- counter = count + za[i]*san[i];
- }
- if(bit[n] == 1)
- {
- za[i] = A2*sin(2*M_PI*fn*t);
- san[i] = A2*sin(2*M_PI*fn*t);
- counter[i] = count + za[i]*san[i];
- }
- //x[i] = za[i]*san[i]; x(t)
- };
- }
- for(int s = 0; s<fs*1; s++)
- {
- Z[s] = (double)s/fs;
- }
- // create graph and assign data to it:
- ui->customPlot->addGraph();
- ui->customPlot->graph(0)->setData(Z, counter);
- // give the axes some labels:
- ui->customPlot->xAxis->setLabel("x");
- ui->customPlot->yAxis->setLabel("y");
- // set axes ranges, so we see all data:
- ui->customPlot->xAxis->setRange(-0.01, 1); //N/2
- ui->customPlot->yAxis->setRange(-0.1, 4);
- ui->customPlot->replot();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement