Commit 59eed6ec by smanrung23

Full Project Watermarking

parents
[a, b] = uigetfile({'*.wav'}, 'Audio asli');
audioasli = strcat(b, a);
audioasli = audioread(audioasli);
[c, d] = uigetfile({'*.wav'}, 'Audio watermark');
audiowatermark = strcat(d, c);
audiowatermark = audioread(audiowatermark);
a = 0;
N = length(audiowatermark);
for n = 1 : N-1
if audioasli(n) == audiowatermark(n)
continue
end
a = a + (audioasli(n)^2)/(audioasli(n)-audiowatermark(n))^2;
end
SNR = 10*log10(a);
disp([' SNR= ',num2str(SNR),' dB']);
\ No newline at end of file
File added
This diff is collapsed. Click to expand it.
File added
function varargout = Extraction(varargin)
% EXTRACTION MATLAB code for Extraction.fig
% EXTRACTION, by itself, creates a new EXTRACTION or raises the existing
% singleton*.
%
% H = EXTRACTION returns the handle to a new EXTRACTION or the handle to
% the existing singleton*.
%
% EXTRACTION('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EXTRACTION.M with the given input arguments.
%
% EXTRACTION('Property','Value',...) creates a new EXTRACTION or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Extraction_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Extraction_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Extraction
% Last Modified by GUIDE v2.5 09-Jun-2021 11:08:15
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Extraction_OpeningFcn, ...
'gui_OutputFcn', @Extraction_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Extraction is made visible.
function Extraction_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Extraction (see VARARGIN)
% Choose default command line output for Extraction
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Extraction wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Extraction_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%----------------------------------------------------------------------------------------------%
% Browse audio berwatermark
function Browse_Audiowatermark(hObject, eventdata, handles)
%persiapan file audio
[filename, pathname] = uigetfile({'*.wav'});
fullpathname = fullfile (pathname, filename);
[X, Fs] = audioread(fullpathname); %Fs adalah sampling
%check apakah user menekan cancel pada dialog
if isequal(filename,0) || isequal(pathname,0)
uiwait(msgbox ('User menekan Cancel','failed','modal') )
hold on;
else
uiwait(msgbox('Audio sudah dipilih','sucess','modal'));
hold off;
X = X (:,1)
N = length(X);
t = (0:N-1)/Fs;
%plot
axes(handles.axes1);
plot(t,X)
grid on
xlabel('Time (s)')
ylabel('Amplitudo')
end
handles.output = hObject;
handles.fullpathname = fullpathname;
handles.Fs = Fs;
handles.X = X;
guidata(hObject, handles);
%----------------------------------------------------------------------------------------------%
%------------------------------------------Fungsi Ekstraksi------------------------------------------------------------------------------------------%
function pushbutton2_Callback(hObject, eventdata, handles)
%Membagi matriks x ke dalam frame
if isfield(handles, 'fullpathname')
koresponden_Un1 = csvread('koresponden_Un1.csv');
koresponden_Vn1 = csvread('koresponden_Vn1.csv');
koresponden_Un2 = csvread('koresponden_Un2.csv');
koresponden_Vn2 = csvread('koresponden_Vn2.csv');
X = handles.X;
frame_size = 32; % jumlah sample per frames
temp = 0;
for i = 1 : length(X)/32
frames(i, 1:32) = X(temp + 1 : temp + frame_size);
temp = temp + frame_size;
end
%----------------------------------------------------------------------------------------------%
wintype = 'hamming';
winlen = 32;
winamp = [0.5,1]*(1/winlen);
%----------------------------------------------------------------------------------------------%
%Menghitung nilai STE perframe
temp = 0;
[a, b] = size(frames);
for i = 1 : a
energy_frames(i,:) = energy(frames(i,:),wintype,winamp(2),winlen);
temp = temp + frame_size;
end
ste = sum(energy_frames.');
ste = ste';
%----------------------------------------------------------------------------------------------%
%Menghitung nilai ZCC perframe
temp = 0;
for i = 1 : a
zcc_frames(i,:) = zerocross(frames(i,:),wintype,winamp(1),winlen);
temp = temp + frame_size;
end
zc = sum(zcc_frames.');
zc = zc';
%----------------------------------------------------------------------------------------------%
%Memisahkan Frame bersuara dengan Tidak Bersuara
ste_batas = max(ste)/8; %Tracehold ditentukan
zcc_batas = max(zc)/2; %Tracehold ditentukan
temp1 = 1;
temp2 = 1;
ste_index2 = []; %memberikan index frame bersuara tidak bersuara
voice_frame = []; %kumpulan frame bersuara
unvoice_frame = []; %kumpulan frame tidak bersuara
for i = 1 : length(ste)
if ste(i) >= ste_batas
if zc(i) <= zcc_batas
ste_index2 (i,1) = 1;
voice_frame(temp1,:) = frames(i,:);
temp1 = temp1 + 1;
else
ste_index2(i,1) = 0;
unvoice_frame(temp2, :) = frames(i,:);
temp2 = temp2 + 1;
end
else
ste_index2(i,1) = 0;
unvoice_frame(temp2, :) = frames(i,:);
temp2 = temp2 + 1;
end
end
%----------------------------------------------------------------------------------------------%
%Ekstrak watermark dari file audio
watermark1 = [];
watermark2 = [];
for i = 1 : length(koresponden_Un1)
x = voice_frame(i,1:16);
y = koresponden_Un1(i,1:16);
z = koresponden_Vn1(i,1:16);
%----------------------------------------------------------------------------------------------%
%mengoleksi hasil extract
B = extract_function(y,z,x); %fungsi ekstrak Watermark Bit
watermark1(i,:) = B;
x = voice_frame(i,17:32);
y = koresponden_Un2(i,1:16);
z = koresponden_Vn2(i,1:16);
%----------------------------------------------------------------------------------------------%
%mengoleksi hasil extract
B = extract_function(y,z,x); %fungsi ekstrak Watermark Bit
watermark2(i,:) = B;
end
%----------------------------------------------------------------------------------------------%
%Hasil ekstrak
ekstrak1 = reshape(watermark1', 24,[]);
for i = 1 : size(ekstrak1, 1)
for j = 1 : size(ekstrak1, 2)
if ekstrak1(i,j) == 0
ekstrak1(i,j) = -255;
else
ekstrak1 (i,j) = 255;
end
end
end
ekstrak2 = reshape(watermark2', 24,[]);
for i = 1 : size(ekstrak2, 1)
for j = 1 : size(ekstrak2, 2)
if ekstrak2(i,j) == 0
ekstrak2(i,j) = -255;
else
ekstrak2 (i,j) = 255;
end
end
end
%----------------------------------------------------------------------------------------------%
%Hasil ekstrak watermark 1
imwrite(ekstrak1, 'Watermark_hasil_ekstrak1.png');
handles.output = hObject;
handles.ekstrak1 = ekstrak1;
guidata(hObject, handles);
axes(handles.axes2);
imshow(ekstrak1);
%----------------------------------------------------------------------------------------------%
%Hasil ekstrak watermark 2
imwrite(ekstrak2, 'Watermark_hasil_ekstrak2.png');
handles.output = hObject;
handles.ekstrak2 = ekstrak2;
guidata(hObject, handles);
axes(handles.axes3);
imshow(ekstrak2);
%----------------------------------------------------------------------------------------------%
end
%----------------------------------------------------------------------------------------------%
%----------------------------------------------------------------------------------------------%
function pushbutton3_Callback(hObject, eventdata, handles)
%Fungsi Menyimpan Watermark1 hasil ekstraksi
[filename, pathname] = uiputfile('*.png');
Name = fullfile(pathname, filename);
hChildAxes2 = get(handles.axes2, 'Children');
W = get(hChildAxes2(1), 'CData');
imwrite(W, Name, 'png');
%----------------------------------------------------------------------------------------------%
function pushbutton4_Callback(hObject, eventdata, handles)
%Fungsi Menyimpan Watermark2 hasil ekstraksi
[filename, pathname] = uiputfile('*.png');
Name = fullfile(pathname, filename);
hChildAxes3 = get(handles.axes3, 'Children');
Z = get(hChildAxes3(1), 'CData');
imwrite(Z, Name, 'png');
%----------------------------------------------------------------------------------------------%
File added
function varargout = Home(varargin)
% HOME MATLAB code for Home.fig
% HOME, by itself, creates a new HOME or raises the existing
% singleton*.
%
% H = HOME returns the handle to a new HOME or the handle to
% the existing singleton*.
%
% HOME('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HOME.M with the given input arguments.
%
% HOME('Property','Value',...) creates a new HOME or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Home_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Home_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Home
% Last Modified by GUIDE v2.5 27-Mar-2021 14:09:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Home_OpeningFcn, ...
'gui_OutputFcn', @Home_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Home is made visible.
function Home_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Home (see VARARGIN)
% Choose default command line output for Home
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Home wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Home_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
% str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% set (handles.text5, 'String', 'Winda Mariana'); %
% msgbox('ini button') //ini menampilkan message box %
strGui2 = ('E:\KULIAH\semester6\TA 2\Code_TA-02\Embedding.fig'); %Set your GUI file's location
open (strGui2); %Open the new GUI
closereq; %Close the actual GUI
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
strGui3 = ('E:\KULIAH\semester6\TA 2\Code_TA-02\Extraction.fig'); %Set your GUI file's location
open (strGui3); %Open the new GUI
closereq; %Close the actual GUI
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
closereq();
function [U1,Y,V1] = embeed_function(voice_frame, Gambar)
%----------------------------------------------------------------------------------------------%
%Fungsi DCT
DCT = dct(voice_frame);
A = zeros(4,4);
temp = 1;
for i = 1 : 4
for j = 1 : 4
A(i,j) = DCT(1, temp);
temp = temp + 1;
end
end
%----------------------------------------------------------------------------------------------%
%Fungsi SVD
[U,S,V] = svd(A);
%----------------------------------------------------------------------------------------------%
%Embeed Watermark
B = Gambar;
index_b = 1;
W = zeros(4,4);
for i = 1 : 4
for j = 1 : 4
if i ~= j
W(i,j) = B (index_b);
index_b = index_b + 1;
end
end
end
%Pemberian nilai alpha
alpha = 0.0001;
Sn = S + W * alpha; % hasil Embeed
[U1,S,V1] = svd(Sn); %SVD Sn U1 dan V1 akan digunakan pada proses ektraksi
%----------------------------------------------------------------------------------------------%
%Invers SVD
invers_Sn = U * Sn * V' ;
%mengubah ke matkis 1 x 16 sebelum di invers dct
Y = [];
temp = 1;
for i = 1 : 4
for j = 1 : 4
Y(temp) = invers_Sn(i,j);
temp = temp + 1;
end
end
%----------------------------------------------------------------------------------------------%
%Invers DCT
invers_dct_Sn = idct(invers_Sn);
Y = idct(Y);
function En = energy(x,wintype,winamp,winlen)
error(nargchk(1,4,nargin,'struct'));
win = (winamp*(window(str2func(wintype),winlen))).';
% enery calculation
x2 = x.^2;
En = winconv(x2,wintype,win,winlen);
\ No newline at end of file
function Ye = extract_function (U1,V1,Y)
%----------------------------------------------------------------------------------------------%
%Fungsi DCT
DCTE = dct(Y);
B = zeros(4 , 4);
temp = 1;
for i = 1 : 4
for j = 1 : 4
B(i,j) = DCTE(1, temp);
temp = temp + 1;
end
end
%----------------------------------------------------------------------------------------------%
%Fungsi SVD
[Ue,Se,Ve] = svd(B);
Ue1 = reshape(U1', [4 4]);
Ve1 = reshape(V1', [4 4]);
%----------------------------------------------------------------------------------------------%
%Ekstrak Watermark
alpha = 0.00001;
DW = Ue1 * Se * Ve1';
We = DW / alpha;
GambarE = [];
temp = 1;
for i = 1 : 4
for j = 1 : 4
if j ~= i
GambarE(temp) = We(i,j);
temp = temp + 1;
end
end
end
GambarE = abs(GambarE);
Ye = [];
for i = 1 : 12
if GambarE(i) < 0.5
Ye(i) = 0 ;
else
Ye(i) = 1 ;
end
end
function y = sgn(x)
y = (x>=0) + (-1)*(x<0);
\ No newline at end of file
function y = winconv(x,varargin)
error(nargchk(1,4,nargin,'struct'));
len = length(varargin);
switch len
case 0
wintype = 'rectwin';
A = 1;
L = length(x);
case 1
if ischar(varargin{1})
wintype = lower(varargin{1});
A = 1;
L = length(x);
end
case 2
if ischar(varargin{1}) && isreal(varargin{2})
wintype = lower(varargin{1});
A = varargin{2};
L = length(x);
end
case 3
if ischar(varargin{1}) && isreal(varargin{2}) &&...
isreal(varargin{3})
wintype = lower(varargin{1});
A = varargin{2};
L = varargin{3};
end
end
% generate the window
w1 = (window(str2func(wintype),L)).'; A = A(:).';
w = A.*w1;
% perform the convolution using FFT
NFFT = 2^(nextpow2(length(x)+L));
X = fft(x,NFFT); W = fft(w,NFFT);
Y = X.*W;
y = ifft(Y,NFFT);
\ No newline at end of file
function zc = zerocross(x,wintype,winamp,winlen)
%ENERGY Short-time energy computation.
% y = ZEROCROSS(X,WINTYPE,WINAMP,WINLEN) computes the short-time enery of
% the sequence X.
%
error(nargchk(1,4,nargin,'struct'));
% generate x[n] and x[n-1]
x1 = x;
x2 = [0, x(1:end-1)];
% generate the first difference
firstDiff = sgn(x1)-sgn(x2);
% magnitude only
absFirstDiff = abs(firstDiff);
% lowpass filtering with window
zc = winconv(absFirstDiff,wintype,winamp,winlen);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment