function varargout = DSP_mark(varargin)
% DSP_MARK MATLAB code for DSP_mark.fig
% DSP_MARK, by itself, creates a new DSP_MARK or raises the existing
% singleton*.
%
% H = DSP_MARK returns the handle to a new DSP_MARK or the handle to
% the existing singleton*.
%
% DSP_MARK('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in DSP_MARK.M with the given input arguments.
%
% DSP_MARK('Property','Value',...) creates a new DSP_MARK or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before DSP_mark_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to DSP_mark_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 DSP_mark
% Last Modified by GUIDE v2.5 20-Apr-2023 21:46:39
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @DSP_mark_OpeningFcn, ...
'gui_OutputFcn', @DSP_mark_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 DSP_mark is made visible.
function DSP_mark_OpeningFcn(hObject,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 DSP_mark (see VARARGIN)
% Choose default command line output for DSP_mark
handles.output = hObject;
handles.axes1 = findobj(gcf, 'Tag', 'axes1');
handles.axes2 = findobj(gcf, 'Tag', 'axes2');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes DSP_mark wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = DSP_mark_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 GUIDA)
%--------------------------读取原始音频-------------------------%
cla reset;
FILE1='Rihanna - Take A Bow.wav';
[y,Fs]=audioread(FILE1);%音频信号y,采样率fs,采样精度bits
y_fft=fft(y,Fs);
% y_fft_f=2*sqrt(y_fft.*conj(y_fft));
axes(handles.axes1);
plot(y);
grid on;axis tight;
title('原始音频信号的时域波形');
xlabel('time(s)');ylabel('幅度');
axes(handles.axes2);
plot(abs(y_fft));
grid on;axis tight;
title('原始音频信号的频域波形');
xlabel('f(Hz)');ylabel('幅度');
player = audioplayer(y, Fs);
play(player);%播放原始语音
% --- 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)
%--------------------------读取水印音频-------------------------%
cla reset;
FILE1='Rihanna - Take A Bow.wav';
[y,~]=audioread(FILE1);%音频信号y,采样率fs,采样精度bits
%用db4小波对原始音频信号进行3级小波分解
y = y(:); % 将矩阵转换为列向量
[c,l]=wavedec(y,3,'db4');%3级小波分解,低频部分为相似,高频部分为细节
%提取3级小波分解的低频系数和高频系数
ca3=appcoef(c,l,'db4',3);%提取三级小波分解的最低频分
%cd3=detcoef(c,l,3);%提取三级小波分解的次低频分
%cd2=detcoef(c,l,2);
%cd1=detcoef(c,l,1);
x=ca3;%提取三级小波分解的最低频部分
%找到插入位置,检测特征点
s=max(abs(x))*0.2;
i= abs(x)>s;
lx=length(x(i));
%读取水印音频
FILE2='test_new.wav';
[mark,Fs]=audioread(FILE2);
mark=mark(1:lx);
mark_fft=fft(mark);
% mark_fft_f=2*sqrt(mark_fft.*conj(mark_fft));
axes(handles.axes1);
plot(mark);
grid on;axis tight;
title('水印音频信号的时域波形');
xlabel('time(s)');ylabel('幅度');
axes(handles.axes2)
plot(abs(mark_fft));
grid on;axis tight;
title('水印音频信号的频域波形');
xlabel('f(Hz)');ylabel('幅度');
sound(mark,Fs);
% --- 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)
%--------------------------水印嵌入-------------------------%
cla reset;
FILE1='Rihanna - Take A Bow.wav';
[y,~]=audioread(FILE1);%音频信号y,采样率fs,采样精度bits
%用db4小波对原始音频信号进行3级小波分解
y = y(:); % 将矩阵转换为列向量
[c,l]=wavedec(y,3,'db4');%3级小波分解,低频部分为相似,高频部分为细节
%提取3级小波分解的低频系数和高频系数
ca3=appcoef(c,l,'db4',3);%提取三级小波分解的最低频分
cd3=detcoef(c,l,3);%提取三级小波分解的次低频分
cd2=detcoef(c,l,2);
cd1=detcoef(c,l,1);
x=ca3;%提取三级小波分解的最低频部分
%找到插入位置,检测特征点
s=max(abs(x))*0.2;
i=find(abs(x)>s);
lx=length(x(i));
%读取水印音频
FILE2='test_new.wav';
[mark,Fs]=audioread(FILE2);
mark=mark(1:lx);
%水印信号嵌入
ss=mark(1:lx);
rr=ss*0.02;
x(i)=x(i).*(1+rr');
%小波重构,生成加入了水印信号的音频信号
c1=[x',cd3',cd2',cd1'];
s1=waverec(c1,l,'db4');
%把加入了水印的原始音频信号作为final1.wav保存
FILE3='final1.wav';
% 归一化音频数据
s1 = s1 / max(abs(s1));
audiowrite(FILE3,s1,Fs,'BitsPerSample',16,...
'Comment','This is my new audio file.');
[y1,Fs]=audioread(FILE3);
y1_fft=fft(y1,Fs);
% y1_fft_f=2*sqrt(y1_fft.*conj(y1_fft));
axes(handles.axes1);
plot(y1);
grid on;axis tight;
title('嵌入水印后的原始音频信号的时域波形');
xlabel('time(s)');ylabel('幅度');
axes(handles.axes2);
plot(abs(y1_fft));
grid on;axis tight;
title('嵌入水印后的原始音频信号的频域波形');
xlabel('f(Hz)');ylabel('幅度');
ly1=length(y1);
y1=y1(1:0.5*ly1);
sound(y1,Fs);
% --- Executes on button press in pushbutton4.
matlab
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)
%--------------------------水印提取-------------------------%
cla reset;
FILE1='Rihanna - Take A Bow.wav';
[y,~]=audioread(FILE1);%音频信号y,采样率fs,采样精度bits
%用db4小波对原始音频信号进行3级小波分解
y = y(:); % 将矩阵转换为列向量
[c,l]=wavedec(y,3,'db4');%3级小波分解,低频部分为相似,高频部分为细节
%提取3级小波分解的低频系数和高频系数
ca3=appcoef(c,l,'db4',3);%提取三级小波分解的最低频分
%cd3=detcoef(c,l,3);%提取三级小波分解的次低频分
%cd2=detcoef(c,l,2);
%cd1=detcoef(c,l,1);
x=ca3;%提取三级小波分解的最低频部分
%找到插入位置,检测特征点
s=max(abs(x))*0.2;
i=find(abs(x)>s);
%lx=length(i);
%读取含有水印的原始音频
FILE3='final1.wav';
[y1,Fs]=audioread(FILE3);
%用db4小波对含有水印的原始音频信号进行3级小波分解
[c1,l1]=wavedec(y1,3,'db4');
%提取3级小波分解的低频系数和高频系数
ca31=appcoef(c1,l1,'db4',3);
%cd31=detcoef(c1,l1,3);
%cd21=detcoef(c1,l1,2);
%cd11=detcoef(c1,l1,1);
x1=ca31;
%水印信号提取
z(i)=x1(i)-x(i);
s2=z(i)./x(i)';
s2=s2/0.02;
%把提取的水印信号作为final2.wav保存
FILE4='final2.wav';
% 归一化
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
本代码是一个由我个人开发的matlab代码,GUI实现了音频水印的嵌入、提取和处理功能,使用了傅里叶_Audio-watermark-processing-GUI.zip (8个子文件)
Audio-watermark-processing-GUI-main
final4.wav 193KB
DSP_mark.m 12KB
DSP_mark.fig 33KB
test_new.wav 1.68MB
final1.wav 6.55MB
final2.wav 193KB
final3.wav 6.55MB
Rihanna - Take A Bow.wav 6.55MB
共 8 条
- 1
资源评论
2401_87496566
- 粉丝: 990
- 资源: 5149
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功