I have a problem with the output of the soft demapper function (demodulate_soft_bits) when using 16-QAM and 64-QAM modulation.
here is a portion of the code (64-QAM):
cvec comple;
Modulator_2D qam;
ivec cont_d = "0:1:63";
vec qam_r = "-7 -7 -7 -7 -7 -7 -7 -7 -5 -5 -5 -5 -5 -5 -5 -5 -3 -3 -3 -3 -3 -3 -3 -3 -1 -1 -1 -1 -1 -1 -1 -1 1 1 1 1 1 1 1 1 3 3 3 3 3 3 3 3 5 5 5 5 5 5 5 5 7 7 7 7 7 7 7 7";
vec qam_i = "-7 -5 -3 -1 1 3 5 7 -7 -5 -3 -1 1 3 5 7 -7 -5 -3 -1 1 3 5 7 -7 -5 -3 -1 1 3 5 7 -7 -5 -3 -1 1 3 5 7 -7 -5 -3 -1 1 3 5 7 -7 -5 -3 -1 1 3 5 7 -7 -5 -3 -1 1 3 5 7";
comple.set_length(qam_i.length(),false);
for(int i=0; i<qam_i.length(); i++)
comple(i) = std::complex<double>(qam_r(i)/sqrt((double)42),qam_i(i)/sqrt((double)42));
qam.set(comple, cont_d);
temp = qam.demodulate_soft_bits( symb_recus,channel,1);
symb_recus is the output of a realistic 4x4 MIMO channel
channel is the channel gain
At the output I got a random values which doesn't correspond to the hard output and I got also a succession of 0
exp :
temp : [6.80 3.33 1.64 -14.27 -7.06 -3.51 0 0 0 0 0 0 -3.47 .....]
Hard output : [ 0 1 0 1 1 1 1 1 0 0 1 1 0 ... ]
can you please help me
Related
I have the following file stored in a string vector.
ratingsTiny.txt...
Jesse
-3 5 -3 0 -1 -1 0 0 5
Shakea
5 0 5 0 5 0 0 0 1
Batool
5 -5 0 0 0 0 0 -3 -5
Muhammad
0 0 0 -5 0 -3 0 0 0
Maria
5 0 5 0 0 0 0 1 0
Alex
5 0 0 5 0 5 5 1 0
Riley
-5 3 -5 0 -1 0 0 0 3
My goal is extract the numbers, preferably column wise, to add them together and get an average rating for each column among the 7 users.
My closest attempt is below, but I can only print the first column and I can't figure out how to iterate through the entirety of the rows to get the rest of the integers.
Any help is very much appreciated.
ourvector<string> ratings;
for (int i = 1; i < ratings.size(); i += 2){
int num = atoi(ratings[i].c_str());
intRatings.push_back(num);
cout << num << endl;
}
I've been trying to implement quick sort and have been having a lot of problems. I even copied a lot of implementations and accepted answers from the net and they ALL crash on odd sized array/vector if you run it enough times (each time I run I run quick sort against random numbers to be sorted... rather than pretend my code works just cuz it can sort one particular set of numbers).
Here is my code and also prints to help debug the error.
template <typename T>
void quickSortMidPivot(vector<T>&vec, size_t left, size_t right)
{
mcount++;
if(right - left < 1)
return;
//crash all the time
//if(left >= right)
// return;
size_t l = left;
size_t r = right;
T pivot = vec[left + ((right-left)/2)];
cout << endl << "PivotValue:" << pivot << endl;
while (l <= r)
{
while (vec[l] < pivot)
l++;
while (vec[r] > pivot)
r--;
if (l <= r) {
cout << endl << "swap:" << vec[l] << "&" << vec[r] << endl;
std::swap(vec[l], vec[r]);
l++;
r--;
for (int i =left; i<=right; i++)
cout << vec[i] << " ";
}
}
cout << endl << "left:" << left << " r:" << r << endl;
cout << "l:" << l << " right:" << right << endl;
if(left < r)
quickSortMidPivot(vec, left, r);
if(l < right)
quickSortMidPivot(vec, l, right);
}
//in main
quickSortMidPivot(dsVector, 0, dsVector.size() - 1);
mcount is a global just so that I can count number of recursive calls. Help figure out most effective implementation...
Here is some debug info.
When run on even sized vector.
Test values are (PRE-SORTING):
8 4 6 5 2 4 1 2
PivotValue:5
swap:8&2
2 4 6 5 2 4 1 8
swap:6&1
2 4 1 5 2 4 6 8
swap:5&4
2 4 1 4 2 5 6 8
left:0 r:4
l:5 right:7
PivotValue:1
swap:2&1
1 4 2 4 2
left:0 r:0
l:1 right:4
PivotValue:2
swap:4&2
2 2 4 4
swap:2&2
2 2 4 4
left:1 r:1
l:3 right:4
PivotValue:4
swap:4&4
4 4
left:3 r:3
l:4 right:4
PivotValue:6
swap:6&6
5 6 8
left:5 r:5
l:7 right:7
# Recursions:5 0
Data Sorted.
Sorted test values are (POST-SORTING):
1 2 2 4 4 5 6 8
Here is case with odd sized array (9). Works 90% of time.
Test values are (PRE-SORTING):
7 7 5 6 5 8 9 5 8
PivotValue:5
swap:7&5
5 7 5 6 5 8 9 7 8
swap:7&5
5 5 5 6 7 8 9 7 8
swap:5&5
5 5 5 6 7 8 9 7 8
left:0 r:1
l:3 right:8
PivotValue:5
swap:5&5
5 5
left:0 r:0
l:1 right:1
PivotValue:8
swap:8&8
6 7 8 9 7 8
swap:9&7
6 7 8 7 9 8
left:3 r:6
l:7 right:8
PivotValue:7
swap:7&7
6 7 8 7
left:3 r:4
l:5 right:6
PivotValue:6
swap:6&6
6 7
left:3 r:2
l:4 right:4
PivotValue:8
swap:8&7
7 8
left:5 r:5
l:6 right:6
PivotValue:9
swap:9&8
8 9
left:7 r:7
l:8 right:8
# Recursions:7 0
Data Sorted.
Sorted test values are (POST-SORTING):
5 5 5 6 7 7 8 8 9
Here is print output for when odd sized (9) vector input causes crash.
Test values are (PRE-SORTING):
8 3 2 3 9 3 8 1 5
PivotValue:9
swap:9&5
8 3 2 3 5 3 8 1 9
left:0 r:7
l:8 right:8
PivotValue:3
swap:8&1
1 3 2 3 5 3 8 8
swap:3&3
1 3 2 3 5 3 8 8
swap:3&3
1 3 2 3 5 3 8 8
left:0 r:2
l:4 right:7
PivotValue:3
swap:3&2
1 2 3
left:0 r:1
l:2 right:2
PivotValue:1
swap:1&1
1 2
swap:2&0
1 0
swap:3&0
1 0
swap:3&1
1 0
swap:5&0
1 0
swap:3&1
1 0
swap:8&0
1 0
swap:8&0
1 0
swap:9&0
1 0
swap:7274596&0
1 0
swap:666050571&0
1 0
swap:369110150&0
1 0
swap:1&0
1 0
swap:1&0
1 0
swap:110&0
1 0
swap:649273354&0
1 0
swap:134229126&0
1 0
swap:3764640&0
1 0
swap:2293216&0
1 0
swap:8&0
1 0
swap:2&0
1 0
swap:649273354&0
1 0
swap:134229127&0
1 0
swap:3764672&0
1 0
swap:3764608&0
1 0
swap:3&0
1 0
swap:649273354&0
1 0
swap:134229127&0
1 0
swap:3764704&0
1 0
swap:3764640&0
1 0
swap:2&0
1 0
swap:649273354&0
1 0
swap:134229127&0
1 0
swap:3764736&0
1 0
swap:3764672&0
1 0
swap:3&0
1 0
swap:649273354&0
1 0
swap:134229127&0
1 0
swap:3764768&0
1 0
swap:3764704&0
1 0
swap:9&0
1 0
swap:649273354&0
1 0
swap:134229127&0
1 0
swap:3764800&0
1 0
swap:3764736&0
1 0
swap:3&0
1 0
swap:6619252&0
1 0
swap:649273354&0
1 0
swap:134229127&0
1 0
swap:3764832&0
1 0
swap:3764768&0
1 0
swap:8&0
1 0
swap:666050571&0
1 0
swap:402664583&0
1 0
swap:3765152&0
1 0
swap:3764800&0
1 0
swap:1&0
1 0
swap:900931609&0
1 0
swap:268446854&0
1 0
swap:2046&0
1 0
swap:2046&0
1 0
swap:649273354&0
1 0
swap:134229140&0
1 0
swap:2293216&0
1 0
swap:3764832&0
1 0
swap:5&0
1 0
swap:11399&0
1 0
swap:3735896&0
1 0
swap:3735896&0
1 0
swap:548610060&1
1 0
swap:50342980&0
1 0
swap:6356944&-1
1 0
swap:3735800&-2
1 0
swap:3735648&0
1 0
swap:3735648&-1
1 0
swap:3768320&0
1 0
swap:32768&1
1 0
I need to build a bar gragh that illustrate a distribution of pseudorandom numbers that determined by linear congruential method
Xn+1 = (a * Xn + c) mod m
U = X/m
on the interval [0,1]
For example:
Interval Frequency
[0;0,1] 0,05
[0,1;0,2] 0,15
[0,2;0,3] 0,1
[0,3;0,4] 0,12
[0,4;0,5] 0,1
[0,5;0,6] 0,15
[0,6;0,7] 0,05
[0,7;0,8] 0,08
[0,8;0,9] 0,16
[0,9;1,0] 0,4
I used such a method:
float mas[10] = {0,0,0,0,0,0,0,0,0,0};
void metod1()
{
int x=-2, m=437, a=33, c=61;
float u;
for(int i=0;i<m;i++){
x=(a*x + c) % m;
u=(float)x/(float)m;
int r;
r = ceil(u*10);
mas[r] = mas[r] + 1;
}
for(i=0;i<10;i++) cout<<"["<<(float)i/10<<";"<<(float)(i+1)/10<<"]"<<" | "<<mas[i]<<"\n-----------------"<<endl;
return;
}
If you know another officient methods for this problem, that are not straitforward, i would appreciate it.
Your code currently has a much larger problem the efficiency. Assuming you've defined mas as something like int mas[10];, it has undefined behavior.
To see the problem, let's modify your code to print out the values of r that it generates:
void metod1() {
int mas[11] = { };
int x = -2, m = 437, a = 33, c = 61;
float u;
for (int i = 0; i < m; i++) {
x = (a*x + c) % m;
u = (float)x / (float)m;
int r;
r = ceil(u * 10);
//mas[r] = mas[r] + 1;
std::cout << r << '\t';
}
// for (i = 0; i < 10; i++) cout << "[" << (float)i / 10 << ";" << (float)(i + 1) / 10 << "]" << " | " << mas[i] << "\n-----------------" << endl;
return;
}
Then let's look at the results:
0 -2 -7 -4 -7 -7 -6 0 -6 -1
-5 -6 -1 -9 -7 -2 -7 -3 0 -6
0 -8 -5 -6 -8 -6 -7 0 -2 -6
-7 -6 -2 -4 -9 0 -4 -5 -1 -2
-5 0 -2 -1 -4 -8 -5 -2 -8 -5
-9 -4 -5 -7 -9 -8 -3 -9 -9 -9
-3 -4 -5 -3 -9 -6 -5 -3 -1 0
-5 -5 -6 -7 -9 -5 -4 -1 -5 -1
-9 -2 0 -9 -6 -7 -5 -5 -3 -3
-9 -3 0 -4 -1 -1 0 -8 -4 -4
-2 -7 0 -6 -6 -8 -4 -8 -2 -8
-8 -2 -4 -7 -1 -6 -1 -3 -7 -3
-5 -9 -8 -5 -8 -7 -4 -1 -8 -7
-7 -2 -9 -5 -3 0 2 8 8 2
6 8 7 1 5 2 8 4 1 5
10 1 3 6 4 10 5 6 6 10
[more elided]
It doesn't look like you've planned for the fact that you'll be producing negative numbers, and if you fail to do so, the result is undefined behavior when you index outside the bounds of mas.
Here's an example text I'm trying to format:
(9 12 19 38 0 -39 -20 -13 -10)
(7 9 14 29 0 -30 -15 -10 -8)
(4 6 9 19 0 -20 -10 -7 -5)
(2 3 4 9 0 -10 -5 -4 -3)
(0 0 0 0 0 0 0 0 0)
(-3 -4 -5 -10 0 9 4 3 2)
(-5 -7 -10 -20 0 19 9 6 4)
(-8 -10 -15 -30 0 29 14 9 7)
(-10 -13 -20 -39 0 38 19 12 9)
I would like each column to align on digits, (i.e. if there's a minus sign, add extra space).
If I do it like so: C-uM-xalign-regexpRET\([[:digit:]]+\)RETRETRETy
I get this:
(9 12 19 38 0 -3 -2 -1 -1)
(7 9 14 29 0 -3 -1 -1 -8)
(4 6 9 19 0 -2 -1 -7 -5)
(2 3 4 9 0 -1 -5 -4 -3)
(0 0 0 0 0 0 0 0 0 )
(-3 -4 -5 -1 0 9 4 3 2 )
(-5 -7 -1 -2 0 19 9 6 4 )
(-8 -1 -1 -3 0 29 14 9 7 )
(-1 -1 -2 -3 0 38 19 12 9 )
which is very close, but not what I want.
And if I try to modify the expression to include the minus sign, like so: \(-?[[:digit:]]+\)
Then I get this:
(9 1 1 3 0 - - - -)
(7 9 1 2 0 - - - -)
(4 6 9 1 0 - - - -)
(2 3 4 9 0 - - - -)
(0 0 0 0 0 0 0 0 0)
(- - - - 0 9 4 3 2)
(- - - - 0 1 9 6 4)
(- - - - 0 2 1 9 7)
(- - - - 0 3 1 1 9)
Is this a bug, or is there something I don't know?
The text matched by the designated group (usually group 1) is expanded or shrunk, so non-whitespace characters in the group are subject to deletion, as you saw. Unless, that is, justification is enabled, which is indicated by supplying a negative group number to align-regexp:
C-uM-xalign-regexpRET\(\s-*-?\)[0-9]+RET-1RETRETy
If you want, you can align the columns on the ones digits of each number by including the digits in the match group:
C-uM-xalign-regexpRET\(\s-*-?[0-9]+\)RET-1RETRETy
In either case, an extra space will be inserted after each opening parenthesis. I don't see any way to keep align-regexp from doing this, but if you do it often you could wrap it in a command that does the align-regexp, then replaces the regexp "^( " with "(" everywhere in the original region.
I have some questions on manipulating on a file ;
a.) I am a bit confused about get and put pointer in c++. Do I show correct position of get pointer and put pointer.
MyFile . seekg ( 0 , ios :: beg ) ;
MyFile . seekp ( -10 , ios :: end ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
__________________________________________________________________
^ ^
^ ^
^ ^
get Pointer put pointer
Myfile . get ( character ) ;
MyFile . write ( SomeString, 4 ) ;
MyFile . flush ( ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
__________________________________________________________________
^ ^
^ ^
^ ^
get Pointer put pointer
i.) Are Seekg and seekp always guarentee that get an put pointer always shows correct position ?
ii.) If you know more about this topic, can you show/give me some point(s) I should be careful when I use them, ( if there is )
b.) Is
FileIN . seekg ( 1, ifstream :: cur ) ;
equal to
FileIN . seekg ( 1, ios :: cur ) ;
Platform : linux
File format : binary
a) It's wrong. File streams maintain one file pointer, for both input and output. Both seekg and seekp do the same thing. The reason there are two different functions is that the interface of iostreams is generic, it can be used for devices which do have separate put and get pointers.
Quote from the standard [filebuf]:
In particular:
— If the file is not open for reading the input sequence cannot be read.
— If the file is not open for writing the output sequence cannot be written.
— A joint file position is maintained for both the input sequence and the output sequence.
b) Yes, they are the same.
EDIT:
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
_____________________________________________________________________
^ file-pointer
MyFile . seekg ( 0 , ios :: beg ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
_____________________________________________________________________
^ file-pointer
MyFile . seekp ( -10 , ios :: end ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
_____________________________________________________________________
^ file-pointer
Myfile . get ( character ) ;
// you must sync/flush if your last operation was input and you switch to output,
// or your last operation was output and you switch to input.
MyFile . sync ( ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
_____________________________________________________________________
^ file-pointer
MyFile . write ( SomeString, 4 ) ;
MyFile . flush ( ) ;
index :0 1 2 3 4 5 6 7 8 9 10 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0
_____________________________________________________________________
^ file-pointer