Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. //Sebastian Bolewicz grupa 37A
  2.  
  3. #include "mainwindow.h"
  4. #include "ui_mainwindow.h"
  5. #include <math.h>
  6. #include <cmath>
  7. #include <bitset>
  8.  
  9.  
  10. MainWindow::MainWindow(QWidget *parent) :
  11. QMainWindow(parent),
  12. ui(new Ui::MainWindow)
  13. {
  14.     ui->setupUi(this);
  15.     MainWindow::makePlot();
  16. }
  17.  
  18. MainWindow::~MainWindow()
  19. {
  20.     delete ui;
  21. }
  22.  
  23. void MainWindow::makePlot()
  24. {
  25.     //
  26.     //Lab5
  27.     //Demodulacja sygnału za(t)
  28.     int A1 = 1, A2 = 2, fn = 14; //N = 2; Tb = 1/7
  29.     double Tb = 1.0/7.0;
  30.     double fs = 2000;
  31.     //double counter;
  32.     std::bitset<7> bit;
  33.  
  34.     bit[0] = 1;
  35.     bit[1] = 1;
  36.     bit[2] = 0;
  37.     bit[3] = 0;
  38.     bit[4] = 0;
  39.     bit[5] = 1;
  40.     bit[6] = 1;
  41.     QVector<double> Z(fs*1), za(fs*1), san(fs*1), x(fs*1); // initialize
  42.  
  43.     for(int n=0; n<7; n++)
  44.     {
  45.         double counter = 0;
  46.         for(int i=n*fs*Tb; i<fs*Tb*(n+1); i++)
  47.         {
  48.             double t = (double)i/fs;
  49.  
  50.             if(bit[n] == 0)
  51.             {
  52.                 za[i] = A1*sin(2*M_PI*fn*t);
  53.                 san[i] = A2*sin(2*M_PI*fn*t);
  54.                 counter = count + za[i]*san[i];
  55.             }
  56.             if(bit[n] == 1)
  57.             {
  58.                 za[i] = A2*sin(2*M_PI*fn*t);
  59.                 san[i] = A2*sin(2*M_PI*fn*t);
  60.                 counter[i] = count + za[i]*san[i];
  61.  
  62.             }
  63.             //x[i] = za[i]*san[i]; x(t)
  64.         };
  65.     }
  66.  
  67.     for(int s = 0; s<fs*1; s++)
  68.     {
  69.         Z[s] = (double)s/fs;
  70.     }
  71.  
  72.  
  73.     // create graph and assign data to it:
  74.     ui->customPlot->addGraph();
  75.     ui->customPlot->graph(0)->setData(Z, counter);
  76.     // give the axes some labels:
  77.     ui->customPlot->xAxis->setLabel("x");
  78.     ui->customPlot->yAxis->setLabel("y");
  79.     // set axes ranges, so we see all data:
  80.     ui->customPlot->xAxis->setRange(-0.01, 1); //N/2
  81.     ui->customPlot->yAxis->setRange(-0.1, 4);
  82.     ui->customPlot->replot();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement