How can I shift signal in time in C++? [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a signal x(t). I must shift it a/2 and -a/2 and then take the sum of these two shifted signals. How can I write shift of x(t) in time in C++?

For time series data a shift in time is just an offset of n samples, so to sum data which is shifted by +/-a/2 samples:
for (i = a/2; i < N - a/2; ++i)
{
y[i] = x[i - a/2] + x[i + a/2];
}

Related

Shifting binary number in c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 months ago.
Improve this question
For example I want to do:
I have 1 it is 00000001 in binary.
and when I shift like 1<<3 I'll take 8 it is 00001000.
So, I need that I take 00001111 after 1<<3.
I wish you understand if something wrong add unclear ask about it please.
I want to do shorter this part:
for(int i=1;h>0;h--,i*=2) hr+=i;
As I understand, you want
std::uint32_t my_shift(std::uint32_t n, std::uint32_t lshift)
{
return (n << lshift) | ((1 << lshift) - 1);
// original shifted | 0b0001111 (lshift 1)
}
You can directly iterate hr:
for(int hr=1; h>0; h--, hr=2*hr+1)

Computing a formula using do/while statements [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
who knows how to calculate the sum using the do/while operator using the formula below?
I would be grateful for any help.
Your formula can be translated like this:
double i = 1;
double sum = 0;
do{
sum += (1/i + 18*i);
i--;
} while (i < 16);
I'm not really sure that using a do while is the best option, it would probably be better with a for loop like so:
double sum = 0;
for (double i = 1; i < 16; ++i){
sum += (1/i + 18*i);
}

How to loop over defined name pattern [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have around 500 signals with the naming pattern
"Dem_AllEventsStatusByte._101"
"Dem_AllEventsStatusByte._102"
"Dem_AllEventsStatusByte._103"
...
"Dem_AllEventsStatusByte._490"
I want to loop over all of them.
I tried the following code but when i=10 then my signal name is like " Dem_AllEventsStatusByte._1010" which is false it should be 110 at the end.
for (i=1; i<=3;i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._10%d", i);
How to loop over 490 signals of same name pattern? please help! Thank you
You probably want something this:
for (i = 1; i <= 490 - 100; i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._%d", i + 100);
or maybe this:
for (i = 101; i <= 490; i++)
{
SPrint(signal, "Dem_AllEventsStatusByte._%d", i);

Converting cpp_int to binary string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can i convert boost cpp_int (>1000 bits) to it's binary representation in string (e.g. "1011....11001") ?
I have tried convert it by std::bitset, but it does not work on higher numbers
Edit - solution:
This contains a solution for this question:
Instead of int -> cpp_int
std::string toBinary(boost::multiprecision::cpp_int n)
{
std::string r;
while(n != 0)
{
r = (n % 2 == 0 ? "0":"1") + r;
n /= 2;
}
return r;
}

Increment a alpha numerical string abcd1234 upto abcd2000 in c or c++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Increment a alpha numerical string "abcd1234" upto "abcd2000"
output:
abcd1234
abcd1235
.
.
.
abcd2000
Simply:
for (int a = 1234; a <= 2000; ++a)
{
std::cout << "abcd" << a;
}
In C,
for (int i=1234; i<= 2000;i++)
printf("abcd%d\n",i);