HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavaMinor

Simulating image transfer over noisy channel with a repetition code

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
imagewithsimulatingnoisyrepetitioncodechannelovertransfer

Problem

I need to write a software in JAVA which allows me to simulate the transfer of some images over a noisy channel while adding redundancy with a repetition code
.
Before going into code details and issues, here are some requirements:

  • read files from a directory containing images



  • for each file, apply a repetition code (with n repetitions, user input)



  • for each file, send the result of the repetition code on a simulated channel with a given error probability. This means reading each bit and flipping it if we have an error



  • for each file, decode the file received from the channel and save it back as image



The parameters for the simulation are:

  • Files' folder



  • Number of repetitions



  • Error probability (as coefficient^exponent)



  • Output folder



I ended up organizing the project with these classes:

  • NoisyChannel - simulates the channel by reading a String of bits and applying the error based on some error model



  • SingleError - implements the single error model, meaning that we have a bit error if exponent times we generate a random number which is



  • RepetitionCoder - applies the repetition code by taking the bit String, generating a char[stringLength*repetitions] array and filling it with the generated repetitions (010 with 3 repetitions will turn to 000111000)



  • RepetitionDecoder - decodes the bit String by splitting it every repetitions characters and applying a majority vote to each substring. The majority vote returns the most frequent character from the substring (001 will have 0 as result of the mjority vote)



  • Converter - utility class that contains methods to convert a byte[] to a bit String and the other way around



Now that you have a little bit of background, here's my problem: the simulation is really slow!

I've tried with
15 images with a size of 2.2MB each (so roughly 30MB of data) and 5 repetitions and it took around 8 minute to complete, which is way too high for me (running on an i5-4670 3.4GH

Solution

Using String is probably the main issue - you want to keep all data as bytes instead of converting it back and fort. Also, if you are only flipping bits and not dropping/adding them you might work directly on bytes: prepare a one byte mask ( from 8 calls to SingleError.isError()) for every byte of input and just XOR them.

Context

StackExchange Code Review Q#114036, answer score: 4

Revisions (0)

No revisions yet.