Quantization erorr in audio steganography
이전 댓글 표시
if true
%Initialization
clc, clear all;
%Waveread
[x,fs,nbits]=wavread('one.wav');
%sound(x,fs)
%Analog-to-Digital Conversion
y=((2^(nbits-1)*x(:,1))); %change the samples into decimal
%store the sign
for i=1:length(y)
if y(i)<0
z(i)=1;
else
z(i)=0;
end
if y(i)<0
y(i)=-1*y(i);
end
end
y=dec2bin(y);
z=dec2bin(z);
%Steganography
data=fileread('data.txt');
temp_message=dec2bin(double(data),8);%secret message
%form row vector of secret message
message=[];
for v=1:size(temp_message,1)
message=[message temp_message(v,:)];
end
str = dec2bin(length(message),16);
if length(message)<length(y)
%embed message length in first 16 samples
for a=1:length(str)
y(a,nbits-1)=str(a);
end
%embed secret message from 17th sample
b=1;
for j=17:length(message)+16
if b<length(message)+1
y(j,nbits-1)=message(b);
b=b+1;
end
end
%Digital-to-Analaog Conversion
b=bin2dec(y);
%check the sign
for i=1:length(y)
if z(i)=='1'
b(i)=-1*b(i);
end
end
a=b/(2^(nbits-1));
%Analysis
wavplay(a,fs)
%save the sound contained secret message
wavwrite(a,fs,nbits,'stego_message.wav');
%plotting
subplot(1,2,1),plot(x(:,1));
title('Before Steganography');
xlabel('Sample Number');
ylabel('Amplitude');
subplot(1,2,2),plot(a);
title('After Steganography');
xlabel('Sample Number');
ylabel('Amplitude');
else
disp('error')
end
end
i am getting error while i am writing when my message length is 6464 than it doesn't show any error when i increase the length it show error "data clipped during write to file" and also my graph change please help me i don't want the change in graph please help me some one
채택된 답변
추가 답변 (3개)
Muhammad fayyaz
2014년 6월 11일
0 개 추천
댓글 수: 8
Geoff Hayes
2014년 6월 11일
Muhammad - you can attach your audio file and text file to any comment you make. Just use the paperclip icon.
Please also describe your problem in more detail. Did you modify the code as described in my above answer?
Muhammad fayyaz
2014년 6월 11일
Geoff Hayes
2014년 6월 11일
Put a breakpoint at the line just before the above plot is created. In the command window type
min(x) % the minimum value of the original audio data
max(x) % the maximum value of the original audio data
min(a) % the minimum value of the audio data with secret message
max(a) % the maximum value of the audio data with secret message
What do you notice?
Muhammad fayyaz
2014년 6월 12일
Muhammad fayyaz
2014년 6월 12일
Geoff Hayes
2014년 6월 12일
You can do the following: since you are modifying the 15th bit of the 16-bit string, i.e. x in 11111111111111x1, then a change from a one to a zero is really the addition of 2 to whatever the number that 16-bit binary string represents.
Since you allow negative integers, then your range for the audio data which is composed of 16-bit signed integers is -32768 to 32767. Which is then promptly converted to positive integers by taking the absolute value of the data.
We can't go outside of this range (now 0 to 32768) when we modify the 15th bit. Since we are adding at most 2 to the 16-bit binary string, then our range on the audio data - prior to the insertion of the secret text and prior to the absolute value - must be -32766 to 32765. That way, when the 15th bit is modified (and so add the 2) we will still be in the range of -32768 to 32767 (once converted back to positive and negative integers).
There is one of two things you can do - when you do the analog-to-digital conversion
%Analog-to-Digital Conversion
y=((2^(nbits-1)*x(:,1))); %change the samples into decimal
you can either subtract two from all positive integers in y and add two to all negative integers of y to force the audio data to the range -32766 to 32765 or you can modify just those integers that - when two is added to them - cannot fall outside the just mentioned range
%Analog-to-Digital Conversion
y=((2^(nbits-1)*x(:,1))); %change the samples into decimal
y(y==32767 | y==32766) = 32765;
y(y==-32768 | y==-32767) = -32766;
So the above forces all positive integers that are 32767 or 32766 to 32765, and all negative integers that are -32768 or -32767 to -32766. That way when 2 is added to the absolute value of any of these integers, we will, once converted back to positive and negative values, still be in the range of -32768 to 32767.
I tried the above and was able to avoid the *Warning: Data clipped during write to <file:stego_message.wav*> message and both sub-plots looked identical.
NOTE that the above is valid so long as you always modify the 15th bit. If you were to modify another bit, then a similar adjustment would have to be made.
Try it nd see what happens.
Muhammad fayyaz
2014년 6월 12일
Geoff Hayes
2014년 6월 12일
Using ylim(-1 1) will change the limits on the plot only and not affect the data that is saved to the audio file - so that is why you will still observe the clipping warning/error.
Muhammad fayyaz
2014년 6월 12일
0 개 추천
댓글 수: 1
Geoff Hayes
2014년 6월 12일
Muhammad - the intent of this site is to ask for help with MATLAB, not to ask someone to do your work for you. Good luck with your project!
Muhammad fayyaz
2014년 6월 12일
카테고리
도움말 센터 및 File Exchange에서 Audio I/O and Waveform Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
