function effectOfCode(inputfile,uploadfile,E_dividedByN0, filename)
%The first function to be called in this slide
%this function shows the effect of many error-correcting codes on a picture
%Inputs defined by the user from the webdemo page:
%inputfile is a file to be chosen
%uploadfile is a file to be uploaded
%E_dividedByN0 the the value of the SNR in dB
if(  strcmp(inputfile,'OwnFile'))
    Im = imread (uploadfile);
else
    Im=imread(inputfile);
end

imageDimensions = size(Im);
inue_js_animationNumberOfFrames=0;


SNR=E_dividedByN0;
sigma_ch=1/sqrt(2*power(10,SNR/10));
B=dec2bin(Im,8);
strBinaryVector=reshape(B.',1,[]);
intRepeated =strVecToIntVec(strBinaryVector);
ModulatedVector=modulation(intRepeated);
VerrauschtesSignal = awgn_channel(ModulatedVector,sigma_ch) ;

K=demodulation(VerrauschtesSignal);
R = reshape (K', 8, [])';
S2 = bin2dec(int2str(R));
S4 = uint8(reshape(S2,imageDimensions));

new_filename = [filename '_' num2str(inue_js_animationNumberOfFrames)];
imwrite (S4,new_filename,'png');
inue_js_animationNumberOfFrames=inue_js_animationNumberOfFrames+1;




SNR=E_dividedByN0+10*log10(1/2);
sigma_ch=1/sqrt(2*power(10,SNR/10));
B=dec2bin(Im,8);
strBinaryVector=reshape(B.',1,[]);
w1=repmat(strBinaryVector,2,1);
strRepeated=w1(:);
strRepeated=strRepeated';

intRepeated =strVecToIntVec(strRepeated);
ModulatedVector=modulation(intRepeated);
VerrauschtesSignal = awgn_channel(ModulatedVector,sigma_ch) ;

K = correction1(VerrauschtesSignal,2,'soft');
R = reshape (K', 8, [])';
S2 = bin2dec(int2str(R));
S4 = uint8(reshape(S2,imageDimensions));

new_filename = [filename '_' num2str(inue_js_animationNumberOfFrames)];

 new_filename
inue_js_animationNumberOfFrames
imwrite (S4,new_filename,'png');
inue_js_animationNumberOfFrames=inue_js_animationNumberOfFrames+1;
inue_js_animationNumberOfFrames













%code2
%  SNR=E_dividedByN0+10*log10(1/2);
% sigma_ch=1/sqrt(2*power(10,SNR/10));
B=dec2bin(Im,8);
strBinaryVector=reshape(B.',1,[]);
intRepeated =strVecToIntVec(strBinaryVector);
w1=code2(intRepeated);

%intRepeated =strVecToIntVec(w1);
ModulatedVector=modulation(w1);
VerrauschtesSignal = awgn_channel(ModulatedVector,sigma_ch) ;

%DemodulatedSignal=demodulation(VerrauschtesSignal);
K = correction2(VerrauschtesSignal,'soft');
R = reshape (K', 8, [])';
S2 = bin2dec(int2str(R));
S4 = uint8(reshape(S2,imageDimensions));
disp ('size of S4 is ')
size (S4)

new_filename = [filename '_' num2str(inue_js_animationNumberOfFrames)];
imwrite (S4,new_filename,'png');
new_filename
inue_js_animationNumberOfFrames
disp(7)
inue_js_animationNumberOfFrames=inue_js_animationNumberOfFrames+1;






%code3
%  SNR=E_dividedByN0+10*log10(1/2);
% sigma_ch=1/sqrt(2*power(10,SNR/10));
B=dec2bin(Im,8);
strBinaryVector=reshape(B.',1,[]);
intRepeated =strVecToIntVec(strBinaryVector);
w1=code3(intRepeated);

%intRepeated =strVecToIntVec(w1);
ModulatedVector=modulation(w1);
VerrauschtesSignal = awgn_channel(ModulatedVector,sigma_ch) ;

%DemodulatedSignal=demodulation(VerrauschtesSignal);
K = correction3(VerrauschtesSignal,'soft');
R = reshape (K', 8, [])';
S2 = bin2dec(int2str(R));
S4 = uint8(reshape(S2,imageDimensions));
disp ('size of S4 is ')
size (S4)
new_filename = [filename '_' num2str(inue_js_animationNumberOfFrames)];
imwrite (S4,new_filename,'png');
new_filename
inue_js_animationNumberOfFrames
disp(8)
inue_js_animationNumberOfFrames=inue_js_animationNumberOfFrames+1;
%code4
%  SNR=E_dividedByN0+10*log10(1/2);
% sigma_ch=1/sqrt(2*power(10,SNR/10));
B=dec2bin(Im,8);
strBinaryVector=reshape(B.',1,[]);
intRepeated =strVecToIntVec(strBinaryVector);
w1=code4(intRepeated);


ModulatedVector=modulation(w1);
VerrauschtesSignal = awgn_channel(ModulatedVector,sigma_ch) ;

%DemodulatedSignal=demodulation(VerrauschtesSignal);
K = correction4(VerrauschtesSignal,'soft');
R = reshape (K', 8, [])';
S2 = bin2dec(int2str(R));
S4 = uint8(reshape(S2,imageDimensions));

new_filename = [filename '_' num2str(inue_js_animationNumberOfFrames)];
imwrite (S4,new_filename,'png');
new_filename
inue_js_animationNumberOfFrames
disp(9)


end