Problem Statement:
Write a program to implement Pulse Code Modulation Technique to transfer the data to other computer.
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
int encodesum[20];
private:
Ui::MainWindow *ui;
int L;
int x[512],y[512],nm[512];
long z[512];
int output[512];
long double sampledPoints[512];
int A;
int t;
int T;
float f;
private slots:
void drawWave();
void quantizeWave();
void encodeWave();
void sampleWave();
void enabletheButton();
void createFile();
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include <QApplication>
#include "tcpserver.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
//QCoreApplication b(argc, argv);
return a.exec();
// return b.exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<math.h>
#include<iostream>
#include<QFile>
#include<QTextStream>
#include <QMessageBox>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->SButton->setEnabled(false);
ui->QButton->setEnabled(false);
ui->EButton->setEnabled(false);
ui->pushButton->setEnabled(false);
ui->lineEdit->setEnabled(false);
connect(ui->display,SIGNAL(clicked()),this,SLOT(drawWave()));
connect(ui->QButton,SIGNAL(clicked()),this,SLOT(quantizeWave()));
connect(ui->SButton,SIGNAL(clicked()),this,SLOT(sampleWave()));
connect(ui->EButton,SIGNAL(clicked()),this,SLOT(encodeWave()));
connect(ui->time,SIGNAL(textEdited(QString)),this ,SLOT(enabletheButton()));
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(createFile()));
}
void MainWindow::enabletheButton()
{
ui->display->setEnabled(true);
}
void MainWindow::createFile()
{
QTextStream out(stdout);
QString filename=ui->lineEdit->text();
QFile file(filename);
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
{
out<<"File is created successfully!!";
QMessageBox msgBox;
msgBox.setText("File is created successfully");
msgBox.exec();
}
else
{
QMessageBox msgBox;
msgBox.setText("File is not created !!!!");
msgBox.exec();
}
QTextStream writeTo(&file);
for(int i=0;i<(T*32);i++)
{
writeTo<<output[i];
}
}
void MainWindow::drawWave()
{
QImage q(500,500,QImage::Format_ARGB32);
QRgb b=qRgb(255,255,255);
QRgb c=qRgb(192,168,153);
t=0;
A=ui->amli->text().toInt();
T=ui->time->text().toInt();
L=T+50;
f=1.0/L;
for(int i=10;i<500;i++)
{
q.setPixel(i,268,b);
}
for(int i=0;i<500;i++)
{
q.setPixel(8,i,b);
}
for(t=0;t<=L;t++)
{
int k=0;
int K=A;
x[t]=K*sin(2*(22.0/7)*f*t);
y[t]=300-x[t];
k=y[t]-30;
q.setPixel(int(t+8),k,c);
}
ui->PrintLabel->setPixmap(QPixmap::fromImage(q));
ui->SButton->setEnabled(true);
ui->display->setEnabled(false);
}
void MainWindow::quantizeWave()
{
QImage q(500,500,QImage::Format_ARGB32);
QRgb bcolor=qRgb(255,255,255);
QRgb g=qRgb(192,168,153);
for(int i=10;i<500;i++)
{
q.setPixel(i,268,bcolor);
}
for(int i=0;i<500;i++)
{
q.setPixel(8,i,bcolor);
}
for(t=0;t<=T;t++)
{
int k=250;
int l=0;
l=z[t]+10;
while (k<=268) {
q.setPixel(l,k,g);
k++;
}
}
ui->PrintLabel->setPixmap(QPixmap::fromImage(q));
ui->EButton->setEnabled(true);
}
void MainWindow::sampleWave()
{
int b,size,m;
b=ui->sample->text().toInt();
m=pow(2,b-1);
size=A/m;
int p,n,k;
cout<<"\n Sample Points::\n";
for(t=0;t<=T;t++)
{
if(x[t]>=0)
{
p=0;
n=size;
for(k=0;k<m;k++)
{
if(x[t]>=p&&x[t]<=n)
{
z[t]=k+m;
break;
}
p=n;
n=n+size;
}
else
{
p=-1;
n=-size;
for(k=0;k<m;k++)
{
if(x[t]<=p&&x[t]>=n)
{
z[t]=m-k-1;
break;
}
p=n;
n=n-size;
}
}
cout<<z[t]<<"\n";
}
QImage q(500,500,QImage::Format_ARGB32);
QRgb bcolor=qRgb(255,255,255);
QRgb ccolor=qRgb(192,168,153);
for(int i=10;i<500;i++)
{
q.setPixel(i,268,bcolor);
}
for(int i=0;i<500;i++)
{
q.setPixel(8,i,bcolor);
}
for(t=0;t<=T;t++)
{
int k=250;
int l=z[t]+10;
q.setPixel(l,k,ccolor);
}
ui->PrintLabel->setPixmap(QPixmap::fromImage(q));
ui->QButton->setEnabled(true);
}
void MainWindow::encodeWave()
{
int var=0;
int cdigit,kactual;
// ui->textEdit->setText(QString::number(sum)+"\t");
for(int j=0;j<=T;j++)
{
//cout<<"\n"<<z[j];
for(cdigit=32;cdigit>=0;cdigit--)
{
kactual=z[j] >> cdigit;
if(kactual & 1)
{
//cout<<"1";
output[var]=1;
var++;
}
else
{
output[var]=0;
var++;
//cout<<"0";
}
}
}
for(int i=0;i<(T*32);i++)
{
cout<<output[i];
}
QMessageBox msgBox;
msgBox.setText("The encoding is completed now please create file and save the encoded data.");
msgBox.exec();
ui->pushButton->setEnabled(true);
ui->lineEdit->setEnabled(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
OUTPUT
Write a program to implement Pulse Code Modulation Technique to transfer the data to other computer.
PROGRAM
#ifndef MAINWINDOW_H#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
int encodesum[20];
private:
Ui::MainWindow *ui;
int L;
int x[512],y[512],nm[512];
long z[512];
int output[512];
long double sampledPoints[512];
int A;
int t;
int T;
float f;
private slots:
void drawWave();
void quantizeWave();
void encodeWave();
void sampleWave();
void enabletheButton();
void createFile();
};
#endif // MAINWINDOW_H
#include "mainwindow.h"
#include <QApplication>
#include "tcpserver.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
//QCoreApplication b(argc, argv);
return a.exec();
// return b.exec();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<math.h>
#include<iostream>
#include<QFile>
#include<QTextStream>
#include <QMessageBox>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->SButton->setEnabled(false);
ui->QButton->setEnabled(false);
ui->EButton->setEnabled(false);
ui->pushButton->setEnabled(false);
ui->lineEdit->setEnabled(false);
connect(ui->display,SIGNAL(clicked()),this,SLOT(drawWave()));
connect(ui->QButton,SIGNAL(clicked()),this,SLOT(quantizeWave()));
connect(ui->SButton,SIGNAL(clicked()),this,SLOT(sampleWave()));
connect(ui->EButton,SIGNAL(clicked()),this,SLOT(encodeWave()));
connect(ui->time,SIGNAL(textEdited(QString)),this ,SLOT(enabletheButton()));
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(createFile()));
}
void MainWindow::enabletheButton()
{
ui->display->setEnabled(true);
}
void MainWindow::createFile()
{
QTextStream out(stdout);
QString filename=ui->lineEdit->text();
QFile file(filename);
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
{
out<<"File is created successfully!!";
QMessageBox msgBox;
msgBox.setText("File is created successfully");
msgBox.exec();
}
else
{
QMessageBox msgBox;
msgBox.setText("File is not created !!!!");
msgBox.exec();
}
QTextStream writeTo(&file);
for(int i=0;i<(T*32);i++)
{
writeTo<<output[i];
}
}
void MainWindow::drawWave()
{
QImage q(500,500,QImage::Format_ARGB32);
QRgb b=qRgb(255,255,255);
QRgb c=qRgb(192,168,153);
t=0;
A=ui->amli->text().toInt();
T=ui->time->text().toInt();
L=T+50;
f=1.0/L;
for(int i=10;i<500;i++)
{
q.setPixel(i,268,b);
}
for(int i=0;i<500;i++)
{
q.setPixel(8,i,b);
}
for(t=0;t<=L;t++)
{
int k=0;
int K=A;
x[t]=K*sin(2*(22.0/7)*f*t);
y[t]=300-x[t];
k=y[t]-30;
q.setPixel(int(t+8),k,c);
}
ui->PrintLabel->setPixmap(QPixmap::fromImage(q));
ui->SButton->setEnabled(true);
ui->display->setEnabled(false);
}
void MainWindow::quantizeWave()
{
QImage q(500,500,QImage::Format_ARGB32);
QRgb bcolor=qRgb(255,255,255);
QRgb g=qRgb(192,168,153);
for(int i=10;i<500;i++)
{
q.setPixel(i,268,bcolor);
}
for(int i=0;i<500;i++)
{
q.setPixel(8,i,bcolor);
}
for(t=0;t<=T;t++)
{
int k=250;
int l=0;
l=z[t]+10;
while (k<=268) {
q.setPixel(l,k,g);
k++;
}
}
ui->PrintLabel->setPixmap(QPixmap::fromImage(q));
ui->EButton->setEnabled(true);
}
void MainWindow::sampleWave()
{
int b,size,m;
b=ui->sample->text().toInt();
m=pow(2,b-1);
size=A/m;
int p,n,k;
cout<<"\n Sample Points::\n";
for(t=0;t<=T;t++)
{
if(x[t]>=0)
{
p=0;
n=size;
for(k=0;k<m;k++)
{
if(x[t]>=p&&x[t]<=n)
{
z[t]=k+m;
break;
}
p=n;
n=n+size;
}
else
{
p=-1;
n=-size;
for(k=0;k<m;k++)
{
if(x[t]<=p&&x[t]>=n)
{
z[t]=m-k-1;
break;
}
p=n;
n=n-size;
}
}
cout<<z[t]<<"\n";
}
QImage q(500,500,QImage::Format_ARGB32);
QRgb bcolor=qRgb(255,255,255);
QRgb ccolor=qRgb(192,168,153);
for(int i=10;i<500;i++)
{
q.setPixel(i,268,bcolor);
}
for(int i=0;i<500;i++)
{
q.setPixel(8,i,bcolor);
}
for(t=0;t<=T;t++)
{
int k=250;
int l=z[t]+10;
q.setPixel(l,k,ccolor);
}
ui->PrintLabel->setPixmap(QPixmap::fromImage(q));
ui->QButton->setEnabled(true);
}
void MainWindow::encodeWave()
{
int var=0;
int cdigit,kactual;
// ui->textEdit->setText(QString::number(sum)+"\t");
for(int j=0;j<=T;j++)
{
//cout<<"\n"<<z[j];
for(cdigit=32;cdigit>=0;cdigit--)
{
kactual=z[j] >> cdigit;
if(kactual & 1)
{
//cout<<"1";
output[var]=1;
var++;
}
else
{
output[var]=0;
var++;
//cout<<"0";
}
}
}
for(int i=0;i<(T*32);i++)
{
cout<<output[i];
}
QMessageBox msgBox;
msgBox.setText("The encoding is completed now please create file and save the encoded data.");
msgBox.exec();
ui->pushButton->setEnabled(true);
ui->lineEdit->setEnabled(true);
}
MainWindow::~MainWindow()
{
delete ui;
}
OUTPUT
No comments:
Post a Comment