1

I have created a Hamming code encoder to process a signal, up to here all good.

I'm having issues to implement a "noise" into an output in the Test-bench. For the noise, I want to apply up to 3 bits. I have to corrupt the 8-bit output by adding each of the 3 bits (from the noise signal) at random positions.

As an example: noise=111 and output=00000000. When the noise is injected into the 8-bit word, it'd look like this: 01000101/11100000/00101010. I've been trying rand() functions but I've had no luck.

I'd appreciate any sort of guidance here as I'm new to VHDL.

I've been trying (as a teste) to create a random integer (range 0 to 7) named x. And trying to apply 1 bit at position "x".

so output(x)<='1'. And somehow the position 0 and 7 also gets altered, as well as x position. When new output words come in, the output saves the previous (x) position value. When all 0 to 7 integers have happened then I get "11111111".

Pablo B.
  • 11
  • 2
  • 2
    The fist question with random numbers is always: do you need them just in a test-bench or for real, in hardware. – Oldfart Jan 03 '20 at 19:49
  • As an error statement "I've been trying rand() functions but I've had no luck" lacking a [mcve] your problem can't be solved here it's not specific. "I also find it difficult to find relevant info online. If someone could recommend me any other forums to gather more information." This is definitely [off-topic](https://stackoverflow.com/help/on-topic) on [Stackoverflow](https://meta.stackoverflow.com/questions/254393/what-exactly-is-a-recommendation-question). –  Jan 03 '20 at 21:37
  • As @Oldfart says, the main thing you need to state is whether this is just for testing in simulation, or you actually need to generate pseudorandom numbers in hardware. Assuming you don't have any complicated requirements regarding the noise distribution, then either option is very straightforward (but the best implementation will be completely different in each case). – Harry Jan 03 '20 at 22:18
  • @Oldfart you are right. The noise will be implemented in the test-bench. – Pablo B. Jan 04 '20 at 09:53
  • Your edit adding the last two paragraphs still doesn't provide a [mcve] and *so output(x)<'1'* appears to imply `output(x) <= '1'`;` instead of a relation between an element of output and the enumeration values '1'.' –  Jan 05 '20 at 02:56
  • When changing the position of the random bit, you most likely forgot to restore the starting value that was overwritten by the noise! Do that or use the xor of the answer, never changing the original value – B. Go Jan 05 '20 at 23:36

1 Answers1

1

I don't know anything about VHDL, but algorithmically this sounds straightforward assuming you have a random number generator.

  1. Generate an integer in the range 0 to 3, place that many 1's in your noise word, and pad the remainder of the word with 0's.

  2. Shuffle the bits of the noise word.

  3. XOR the noise word with the output word.

pjs
  • 18,696
  • 4
  • 27
  • 56
  • Given that the OP has now clarified that their requirement is for simulation only, this approach is valid. Unless the number of simulation trials were very large, I would probably take a lazier approach to steps 1 and 2 (e.g. just generate 8-bit random numbers until I get one that happens to have 3 set bits). Nonetheless, this answer could be completed by linking, for example, to here: https://stackoverflow.com/a/53353673/4220282. This shows how to generate uniform random integers in a VHDL testbench. – Harry Jan 04 '20 at 11:53