阅读 40

【语音隐写】基于matlab GUI DWT音频数字水印【含Matlab源码 712期】

一、简介

小波变换原理
小波变换是一种信号的时间一尺度(时间一频率)分析方法,一种窗口大小固定不变形状可改变,时间窗和频率窗都可以改变的时频局部化分析方法。它具有多分辨率分析( Multi-resolution Analysis)的特点,且在时频两域都具有表征信号局部特征的能力。
小波分析方法在低频部分具有较高的频率分辨率和较低的时间分辨率,在高频部分具有较高的时间分辦率和较低的频率分辦率,所以被誉为“数学显微镜”。正是这种特性,使小波变换具有对信号的自适应性。
小波分析被看成调和分析这一数学领域半个世纪以来的工作结晶,已经广泛地应用于信号处理、图像处理、量子场论、地震勘探、语音识别与合成、音乐、雷达、CT成像、彩色复印、流体湍流、天体识别、机器视觉、机械故障诊断与监控、分形以及数字电视等科技领域。
原则上讲,传统上使用傅里叶分析的地方,都可以用小波分析取代。小波分析优于傅里叶变换的地方是在时域和频域同时具有良好的局部化性质。
在这里插入图片描述
这样小波变換对不同的频率在时域上的取样步长是调节性的:在低频时,小波变换的时间分辨率较低,而频率分辦率较高;在高频时,小波变换的时间分辨率较高,而類率分辨率较低。这正符合低频信号变化缓慢而高频信号变化迅速的特点。
这便是它优于经典傅里叶变换与短时傅里叶变换的地方。

二、源代码

function varargout = main(varargin)
% MAIN MATLAB code for main.fig
%      MAIN, by itself, creates a new MAIN or raises the existing
%      singleton*.
%
%      H = MAIN returns the handle to a new MAIN or the handle to
%      the existing singleton*.
%
%      MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MAIN.M with the given input arguments.
%
%      MAIN('Property','Value',...) creates a new MAIN or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before main_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to main_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 main

% Last Modified by GUIDE v2.5 05-Apr-2021 22:33:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @main_OpeningFcn, ...
                   'gui_OutputFcn',  @main_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 main is made visible.
function main_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 main (see VARARGIN)

% Choose default command line output for main
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = main_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;


% --- 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)
%% 选择音频
[file1,pathname]=uigetfile('*.wav','请选择要识别的样本');%跳出对话框
fname=fullfile(pathname,file1);
[X,fs,bits]=wavread(fname); %读入音频文件
    sound(X,fs); %播放声音
handles.axes1 
subplot(2,2,1); 
plot(X);     %显示音频文件波形
title('原始音频信号'); 
handles.X=X;
handles.fs=fs;
guidata(hObject, handles);
% --- 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)
%% 选择水印
[file1,pathname]=uigetfile('*.bmp','请选择要识别的样本');%跳出对话框
fname=fullfile(pathname,file1);
key=35;
%Arnold置换次数,作为密钥
Orignalmark=double(imread(fname));  %读入64*64的水印图片
[wrow,wcol]=size(Orignalmark);  
if wrow~=wcol 
    error('wrow~=wcol error');
end
%--- 测试密钥key是否超出范围---------
n=check_arnold(wrow);
if (key+1)>n
    error('arnold key error');
end


subplot(2,2,2); hold on
imshow(Orignalmark),title('原始图像');
handles.Orignalmark=Orignalmark;
handles.n=n;
guidata(hObject, handles);
% --- 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)
%% 嵌入水印
%水印嵌入--------------------------------------------------
X=handles.X;%读取音频
Orignalmark=handles.Orignalmark;%读取水印图像
fs=handles.fs;%频率
[wrow,wcol]=size(Orignalmark); 
key=35;
Arnoldw=arnold(Orignalmark,wrow,key); %对水印图像进行Arnold转化
[c,l]=wavedec(X,2,'db4'); %用db4小波对读入的声音文件进行2级小波分解 
ca2=appcoef(c,l,'db4',2); %提取2级小波分解的低频系数和高频系数 
cd2=detcoef(c,l,2); 
cd1=detcoef(c,l,1); 
lca=length(ca2);  %低频长度
blocksize=fix(lca/(wrow*wcol)); %每块的大小
water_vector=reshape(Arnoldw,1,wrow*wcol);  %将置乱后的水印转化为一维的
wlength=wrow*wcol;  %水印的长度
a=0.25;  %量化步长
j=1;
for i=1:wlength
    Block=ca2(j:j+blocksize-1);
    [U,S,V]=svd(double(Block)); 
    cc=floor(S(1,1)/a);  
    if(Arnoldw(i)==1)           %嵌入奇数倍
        if(mod(cc,2)==0)
            cc=cc+1;
        end
        S(1,1)=a*cc;
    end
    if(Arnoldw(i)==0)            %嵌入偶数倍
        if(mod(cc,2)==1)  
            cc=cc+1;
        end
        S(1,1)=a*cc;
    end
    Blockw=U*S*V';          %SVD 逆变换还原 
    ca2(j:j+blocksize-1)=Blockw; 
    j=j+blocksize;
end
c1=[ca2',cd2',cd1']';
MarkedX=waverec(c1,l,'db4');%b为量化嵌入水印后的音频数据 
subplot(2,2,3); 
plot(MarkedX);
title('嵌入水印后音频'); 
sound(MarkedX,fs);
handles.MarkedX=MarkedX;
handles.key=key;
guidata(hObject, handles);

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%水印嵌入--------------------------------------------------
[c,l]=wavedec(X,2,'db4'); %用db4小波对读入的声音文件进行2级小波分解 
ca2=appcoef(c,l,'db4',2); %提取2级小波分解的低频系数和高频系数 
cd2=detcoef(c,l,2); 
cd1=detcoef(c,l,1); 
lca=length(ca2);  %低频长度
blocksize=fix(lca/(wrow*wcol)); %每块的大小
water_vector=reshape(Arnoldw,1,wrow*wcol);  %将置乱后的水印转化为一维的
wlength=wrow*wcol;  %水印的长度
a=0.25;  %量化步长
j=1;
for i=1:wlength
    Block=ca2(j:j+blocksize-1);
    [U,S,V]=svd(double(Block)); 
    cc=floor(S(1,1)/a);  
    if(Arnoldw(i)==1)           %嵌入奇数倍
        if(mod(cc,2)==0)
            cc=cc+1;
        end
        S(1,1)=a*cc;
    end
    if(Arnoldw(i)==0)            %嵌入偶数倍
        if(mod(cc,2)==1)  
            cc=cc+1;
        end
        S(1,1)=a*cc;
    end
    Blockw=U*S*V';          %SVD 逆变换还原 
    ca2(j:j+blocksize-1)=Blockw; 
    j=j+blocksize;
end
复制代码

三、运行结果

在这里插入图片描述

四、备注

版本:2014a

文章分类
人工智能
文章标签