Translation of Matlab & Simulink models to SpecC specification Models

by

 

Involves translation of Matlab/Simulink models to Spec C specification models.

stdlsbdec.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%DATA RECOVERY USING STANDARD LSB ALGORITHM %%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc;
clear all;
close all;
warning off;

%%%%%%%%%%%%%%%%%%%%%%%%%%%READING THE AUDIO FILE%%%%%%%%%%%%%%%%%%%%%%%%%
recovered_watermark = [];
[x, Fs, N] = wavread('rec1.wav');
[y,fs,n]=wavread('sss.wav');
plot(y)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%GIVING ATTACKS%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%Add Brumm%%%%%%%%%
% for i=1:length(x)
% a(i)=sin(2*pi*i*55)*2500;
% x(i)=x(i)+a(i);
% end

%%%%%%%%%%Add Dyn Noise%%%%%%%
% a=randn(size(x));
% for i=1:length(x)
%     x(i)=x(i)+a(i)*sqrt(x(i)*(20/100)+1);
% end

%%%%%%%%%Add Sinus%%%%%%%%%
% for i=1:length(x)
% a(i)=sin(2*pi*i*3000)*120;
% x(i)=x(i)+a(i);
% end

%%%%%%%%%%Amplify%%%%%%%%%%
% for i=1:length(x)
%     x(i)=x(i)*(50/100);
% end

%%%%%%%%%Copy Sample%%%%%%%%
% for i=1:length(x)
%     z=i*floor(sqrt(10000+2000));
%     if z<6000 & z>0
%       x(i)=x(z);
%     elseif z<(6000+2000) & z>6000
%         x(i)=x(z-6000);
%     elseif z<(10000+2000) & z>(6000+2000)
%         x(i)=x(z-2000);
%     else
%         x(i)=x(i);
%     end
% end

%%%%%%%%%%Cut Sample%%%%%%%%
% for i=1:(length(x)-30000)
%     z=i*sqrt(1000-7);
%     x(i)=x(z+7);
% end

%%%%%%%%%%%%Echo%%%%%%%%%%%%
% for i=1:(length(x)-300)
%     x(i)=(x(i)+x(i+300))/2;
% end

%%%%%%%%%%%Exchange%%%%%%%%%
% for i=2:length(x)
%     z=i*sqrt(2);
%     if z==0
%         x(i)=x(i+1);
%     else
%         x(i)=x(i-1);
%     end
% end

%%%%%%%%%Flipp Sample%%%%%%%
% for i= 1:length(x)
%     z=i*floor(sqrt(10000+2000));
%     if z<2000 & z>0
%         x(i)=x(z+6000);
%     elseif z>2000 &z<(6000)
%         x(i)=x(z);
%     elseif z<(6000+2000) & z>6000
%         x(i)=x(z-6000);
%     elseif z<10000 & z<(6000+2000)
%         x(i)=x(z);
%     else
%         x(i)=x(i);
%     end
% end

%%%%%%%%%%%Invert%%%%%%%%%%%
% for i =1:length(x)
%     x(i)=-x(i);
% end

%%%%%%%%%%Noise Max%%%%%%%%%
% for i = 1:length(x)
%     x(i)=x(i)+1365*300;
% end

%%%%%%%%%%Nothing%%%%%%%%%%%
% for i=1:length(x)
%     x(i)=x(i);
% end

%%%%%%%%%RC-Highpass%%%%%%%%
% B=exp((-2*pi*150)/22050);
% A0=(1+B)/2;
% A1=-(1+B)/2;
% y(1)=x(1);
% for i=2:length(x)
%     x(i)=A0*x(i)+B*y(i-1)+A1*x(i-1);
%     y(i)=x(i);
% end

%%%%%%%%%RC-Lowpass%%%%%%%%%
% B=exp((-2*pi*15000)/22050);
% A=1-B;
% for i=2:length(x)
%     x(i)=A*x(i)+B*x(i-1);
% end

%%%%%%%%%%%Smooth1%%%%%%%%%%
% for i=2:(length(x)-1)
%     if (x(i)<x(i+1) & x(i-1)>x(i))
%     x(i)=(x(i-1)+x(i+1))/2;
%     elseif (x(i)>x(i+1) & x(i-1)<x(i))
%            x(i)=(x(i-1)+x(i+1))/2;
%         else
%             x(i)=x(i);
%         end
% end

%%%%%%%%%%Smooth2%%%%%%%%%%
% for i=2:(length(x)-1)
%     if (x(i)<x(i+1) & x(i-1)<x(i))
%     x(i)=(x(i-1)+x(i+1))/2;
%     elseif (x(i)>x(i+1) & x(i-1)>x(i))
%            x(i)=(x(i-1)+x(i+1))/2;
%         else
%             x(i)=x(i);
%         end
% end

%%%%%%%%%%%Stat1%%%%%%%%%%%
% for i=1:(length(x)-1)
%          x(i)=(x(i)+x(i+1))/2;
%   end

%%%%%%%%%%%Stat2%%%%%%%%%%%
% for i=2:(length(x)-1)
%      x(i)=(x(i-1)+3*x(i)+x(i+1))/5;
%  end

%%%%%%%%%Zero Cross%%%%%%%%
% for i=1:length(x)
% if x(i)<=1000
%     x(i)=0;
% else
%     x(i)=x(i);
% end
% end

%%%%%%%%%Zero Length%%%%%%%
% for i=1:length(x)
% if x(i)==0
%     for j=(i+1):(i+10)
%     x(j)=0;
%     end
% else
%     x(i)=x(i);
% end
% end

%%%%%%%%Zero Removes%%%%%%%
% for i=1:(length(x)-1)
% if x(i)==0
%     x(i)=x(i+1);
% else
%     x(i)=x(i);
% end
% end

figure,plot(x);

%%%%%%%%%%%%%%%%%%%%%%%%%%READING THE TEXT FILE%%%%%%%%%%%%%%%%%%%%%%%%%%%

fid=fopen('text.txt','r');
F=fread(fid);
str=char(F');
fclose(fid);

%%%%%%%%%%%%%%%%%%%%%%%CHARACTER TO BINARY CONVERSION%%%%%%%%%%%%%%%%%%%%%

wm=double(str);
wm1=dec2bin(wm);
wm2=wm1';
wm3=wm2(:);
binseq=wm3';
l=length(binseq);

%%%%%%%%%%%%%%%%%%%%%%%RECOVERY OF WATERMARK FROM LSB%%%%%%%%%%%%%%%%%%%%%

no_samples = length(x) - 32*9;
pattern = randint(1,l,no_samples,0);
for i = 1:l
    sample = x(pattern(i),1);
    sample = (sample+1)*(2^15);
    sample = dec2bin(sample,16);
    recovered_watermark = [recovered_watermark sample(length(sample))];
end

%%%%%%%%%%%%%%%%%%%%%%%WRITING DATA INTO THE TEXT FILE%%%%%%%%%%%%%%%%%%%%

j=1;
for i=1:length(recovered_watermark)/7
    samp=recovered_watermark(j:j+6);
    j=j+7;
    rw=bin2dec(samp);
    rw1(i)=char(rw);
end
fid=fopen('abc.txt','w');
fwrite(fid,rw1,'char');
fclose(fid);
disp('RECOVERED WATERMARK:')
disp(rw1)

%%%%%%%%%%%%%%%%%%%%%PARAMETERS ANALYSED FOR PERFORMANCE%%%%%%%%%%%%%%%%%%

%%%%%%%%%Bit Differece%%%%%%%%
bitdiff=sum(binseq-recovered_watermark);
disp('Bit Difference:')
disp(bitdiff)

%%%%%%%%%%%Bit Rate%%%%%%%%%%%
s=0;
for i=1:l
    if binseq(i)==recovered_watermark(i)
        s=s;
    else
        s=s+1;
    end
end
BR=(100/l)*(s);
disp('Bit Rate:')
disp(BR)

%%%%%%%%%Correlation%%%%%%%%%%%
h=0;
for i=1:l
    if binseq(i)==recovered_watermark(i)
        h=h+1;
    else
        h=h-1;
    end
end
cor=(1/l)*h;
disp('Correlation:')
disp(cor)

%%%%%%Signal To Noise Ratio%%%%%
a=0;
b=0;
for i= 1:length(y)
    a=a+y(i)*y(i);
    b=b+(y(i)-x(i))*(y(i)-x(i));
end
snr= 10*log(a/b);
disp('Signal To Noise Ratio:')
disp(snr)

Contact us