Both the arrays contain 1750 characters each and the difference needs to be stored in third array.

## All 10 Replies

Before expecting any comments from us, please show us what you have done yourself. Did you think about it atall? If yes.. what are your thoughts? If no... think about it first.

Also what exactly do you mean by difference? Do you mean the ASCII number difference... or do you mean the third array is an array of bools. so the third array would be thirdArray[x] = 0 if firstArray[x] and secondArray[x] are the same and thirdArray[x] = 1 if firstArray[x] and secondArray[x] are different.

There are all kinds of things you can do for the "difference" but you need to give us more info and proof that you've even attempted the problem before you get help from us

Yes what does difference mean in your case ?

difference1 : 4 - 3 = 1
difference2 : {a,b,c} - {a,d,f} = {b,c}

is repitition of 125 bitsx100 for 100 aircraft tracks as latitude longitude heading spees etc each one varying from other also has 8 messages of 12 ASCII characters each at the end of both the arrays ,currently i am generating this data randomly and my purpose is to compress the amount of data that would be transmitted.
I have chosen to transmit the radar data which i have described earlier ,differentially.

So basically you need the Arithmetic difference of both arrays, something like this:

``````int* getDiff(int *arr1, int *arr2)
{
int maxCount = 1750; //From your 1st Post
int *result = new [maxCount];
for(int i=0 ; i<maxCount ; i++ )
result[i]=arr1[i]-arr2[i];
return result;
}``````

So basically you need the Arithmetic difference of both arrays, something like this:

``````int* getDiff(int *arr1, int *arr2)
{
int maxCount = 1750; //From your 1st Post
int *result = new [maxCount];
for(int i=0 ; i<maxCount ; i++ )
result[i]=arr1[i]-arr2[i];
return result;
}``````

Ouch, thats pretty bad. I would have just used stl,

``````#include <algorithm>
#include <functional>
#include <vector>
using namespace std;
int main(){
//std::vector is better, just using arrays for demonstration
const int SZ = 5;
int a1[SZ] = {1,2,3,4,5};
int a2[SZ] = {5,4,3,2,1};
int res[SZ] = {0};
std::transform(a1,a1+SZ,a2,res,std::minus<int>());

}``````

So basically you need the Arithmetic difference of both arrays, something like this:

``````int* getDiff(int *arr1, int *arr2)
{
int maxCount = 1750; //From your 1st Post
int *result = new [maxCount];
for(int i=0 ; i<maxCount ; i++ )
result[i]=arr1[i]-arr2[i];
return result;
}

#include<iostream>
#include"DLP_Functions1.h"
#include<stdlib.h>
#include<iomanip>
double latitude,longitude;
long sequence_number= 0;
unsigned char radar_picture_array;              // SAME ARRAY BEING USED FOR TX RX
int main()
{

}
{
static int tx_frame_number = 0;
if(sequence_number ==0)
{
unsigned char m1="MessageCont1";
unsigned char m2="MessageCont2";
unsigned char m3="MessageCont3";
unsigned char m4="MessageCont4";
unsigned char m5="MessageCont5";
unsigned char m6="MessageCont6";
unsigned char m7="MessageCont7";
unsigned char m8="MessageCont8";

for (int j=0;j<=99;j++)
{
type=(rand()+tx_frame_number)%250;
id =(rand()+tx_frame_number*1000000)%9999;
latitude=(rand()+tx_frame_number*1000000)%18099;
longitude=(rand()+tx_frame_number*1000000)%36099;
altitude=(rand()+tx_frame_number*1000000)%65536;
speed=(rand()+tx_frame_number*1000000)%2048;

//////////static bit level encoding to make "radar_picture_array" from target parameters//////////////////

if(j==99) // encoding command and control messages
{

}
}
}

}
///////////////////////////////////////FUNCTION DEFINITIONS//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////function "value_to_array" definition////////////////

void value_to_array (unsigned char* ch,int from,int to,int value)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting={128,64,32,16,8,4,2,1};
unsigned char clearing={127,191,223,239,247,251,253,254};
for(int x=to;x>=from;x--)
{
bytenum=x/8;
bitnum =x%8;
b=value&a;
if(b==a)
ch[bytenum]|= setting[bitnum];
else
ch[bytenum]&= clearing[bitnum];
a=a<<1;
}
}

///////////////////////////function "array_to_array" definition////////////////////
////////////////// this function can pick only 4 bytes at a time///////////////////

void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting={128,64,32,16,8,4,2,1};
unsigned char clearing={127,191,223,239,247,251,253,254};
unsigned long value=0;

for(int x=from2;x<=to2;x++)
{
value*=2;
bytenum=x/8;
bitnum=x%8;
b=ch2[bytenum]&setting[bitnum];
if(b!=0)
value+=1;
}

for(int x=to1;x>=from1;x--)
{
bytenum=x/8;
bitnum =x%8;
b=value&a;
if(b==a)
ch1[bytenum]|= setting[bitnum];
else
ch1[bytenum]&= clearing[bitnum];
a=a<<1;
}
}
//DLP_Functions1.h as follows
void value_to_array (unsigned char* ch,int from,int to,int value);  // maps a value onto an array
void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2);   // copies part of array to another array
``````

end quote.

But i have a question...
now what i am currently trying to do is to transmit difference of radar_picture_array and radar_picture_array_old_transmitted which will be filled/mapped with values,strings once first radar_picture_array will be transmitted completely,also at reciever side radar_picture_array_recieved will be added to radar_picture_array_recieved_old to recover the original array that was transmitted.

But i have a question...
now what i am currently trying to do is to transmit difference of radar_picture_array and radar_picture_array_old_transmitted which will be filled/mapped with values,strings once first radar_picture_array will be transmitted completely,also at reciever side radar_picture_array_recieved will be added to radar_picture_array_recieved_old to recover the original array that was transmitted.

And what is your question??? You just explained what you are doing but no question in it?

``````#include<iostream>
#include"DLP_Functions1.h"
#include<stdlib.h>
#include<iomanip>
double latitude,longitude;
long sequence_number= 0;
int main()
{

}
{
static int tx_frame_number = 0;
if(sequence_number ==0)
{
unsigned char m1="MessageCont1";
unsigned char m2="MessageCont2";
unsigned char m3="MessageCont3";
unsigned char m4="MessageCont4";
unsigned char m5="MessageCont5";
unsigned char m6="MessageCont6";
unsigned char m7="MessageCont7";
unsigned char m8="MessageCont8";

for (int j=0;j<=99;j++)
{
type=(rand()+tx_frame_number)%250;
id =(rand()+tx_frame_number*1000000)%9999;
latitude=(rand()+tx_frame_number*1000000)%18099;
longitude=(rand()+tx_frame_number*1000000)%36099;
altitude=(rand()+tx_frame_number*1000000)%65536;
speed=(rand()+tx_frame_number*1000000)%2048;

//////////static bit level encoding to make "radar_picture_array" from target parameters//////////////////

if(j==99) // encoding command and control messages
{

}
}
}

}
///////////////////////////////////////FUNCTION DEFINITIONS//////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////

///////////////////////////function "value_to_array" definition////////////////

void value_to_array (unsigned char* ch,int from,int to,int value)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting={128,64,32,16,8,4,2,1};
unsigned char clearing={127,191,223,239,247,251,253,254};
for(int x=to;x>=from;x--)
{
bytenum=x/8;
bitnum =x%8;
b=value&a;
if(b==a)
ch[bytenum]|= setting[bitnum];
else
ch[bytenum]&= clearing[bitnum];
a=a<<1;
}
}

///////////////////////////function "array_to_array" definition////////////////////
////////////////// this function can pick only 4 bytes at a time///////////////////

void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2)
{
unsigned long a=1,b=0;
unsigned long bytenum,bitnum;
unsigned char setting={128,64,32,16,8,4,2,1};
unsigned char clearing={127,191,223,239,247,251,253,254};
unsigned long value=0;

for(int x=from2;x<=to2;x++)
{
value*=2;
bytenum=x/8;
bitnum=x%8;
b=ch2[bytenum]&setting[bitnum];
if(b!=0)
value+=1;
}

for(int x=to1;x>=from1;x--)
{
bytenum=x/8;
bitnum =x%8;
b=value&a;
if(b==a)
ch1[bytenum]|= setting[bitnum];
else
ch1[bytenum]&= clearing[bitnum];
a=a<<1;
}
}
//DLP_Functions1.h as follows
void value_to_array (unsigned char* ch,int from,int to,int value); // maps a value onto an array
void array_to_array (unsigned char* ch1,int from1,int to1,unsigned char* ch2,int from2,int to2); // copies part of array to another array``````

Question1. How to take difference of the arrays i mentioned above and once difference is taken then putting it into diff array
Questio2. Data is currently being generated randomly,but differential compression is more effective on sequential data what i mean to say is that aircraft perimeter like altitude cant change from 50,000 ft to 2000 ft in 4 sec because 4 sec is refresh time required in my case so
i have generated data randomly and sequential variations in MATLAB but need to translate in C++
HOPE U UNDERSTAND]

``````function data=generate_data(number_of_targets,readings)
data=[];
for n=1:number_of_targets
ttype=round(rand*3);
trackid=[round(rand*255) round(rand*255) round(rand*255) round(rand*255) round(rand*255) round(rand*255) round(rand*255)];
lat=((-1)^(round(rand*3)))*round(rand*90);
lon=((-1)^(round(rand*3)))*round(rand*180);
alt=round(rand*65535);
speed=round(rand*2000);
tgt=[ttype trackid lat lon alt heading speed];
data=[data;tgt];
end
for m=1:number_of_targets
latinc=(((-1)^(round(rand*3)))*round(rand*5))/100;
loninc=(((-1)^(round(rand*3)))*round(rand*5))/100;
altinc=(((-1)^(round(rand*3)))*round(rand*1000));
speedinc=(((-1)^(round(rand*3)))*round(rand*350));
data(m,1,n)=data(m,1,n-1);%ttype remains same
data(m,2:8,n)=data(m,2:8,n-1);%tid remains same
lat=data(m,9,n-1)+latinc;
if lat<=90 && lat>=-90
data(m,9,n)=lat;
else
data(m,9,n)=data(m,9,n-1);
end
lon=data(m,10,n-1)+loninc;
if lon<=180 && lon>=-180
data(m,10,n)=lon;
else
data(m,10,n)=data(m,10,n-1);
end
alt=data(m,11,n-1)+altinc;
if alt<=65535
data(m,11,n)=alt;
else
data(m,11,n)=data(m,11,n-1);
end