patternjavaMinor
Simulating image transfer over noisy channel with a repetition code
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:
The parameters for the simulation are:
I ended up organizing the project with these classes:
Now that you have a little bit of background, here's my problem: the simulation is really slow!
I've tried with 15 images
.
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
Stringof bits and applying the error based on some error model
- SingleError - implements the single error model, meaning that we have a bit error if
exponenttimes we generate a random number which is
- RepetitionCoder - applies the repetition code by taking the bit String
, generating achar[stringLength*repetitions]array and filling it with the generated repetitions (010with3 repetitionswill turn to000111000)
- RepetitionDecoder - decodes the bit String
by splitting it everyrepetitionscharacters and applying a majority vote to each substring. The majority vote returns the most frequent character from the substring (001will have0as result of the mjority vote)
- Converter - utility class that contains methods to convert a byte[]
to a bitStringand 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.4GHSolution
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.