一个音频水印的小例子

clc; clear all;close all;
x = ‘classical.00000.wav’;
y = ‘昆.bmp’;
%%%%%----编码–交织
w=imread(y);
w1=w(; %降维

%%%%%%%%确定嵌入位置
[a,fs]=audioread(x);

%对音频分帧
win=256;
signal = enframe(a,win);
%dwt
for i = 1:length(signal(:,1))
[c,l] = wavedec(signal(i,:),3,‘haar’);
ca3(i,:)= appcoef(c,l,‘haar’,3); %3阶低频系数
cd3(i,:) = detcoef(c,l,3); %3阶高频系数
cd2(i,:) = detcoef(c,l,2); %2阶高频系数
cd1(i,:) = detcoef(c,l,1); %1阶高频系数
end

[m,n] = size(ca3); %查看矩阵A的大小
%%%离散余弦变换
for i =1:m
cc(i,:) = dct(ca3(i,:));
end
q=0.5;
vv1=[];
for i=1:length(w1)
[S1,V1,D1]=svd(cc(i,:));
vv1=[vv1,V1(1)];
V1(1)=V1(1)+w1(i)q;
cc(i,:)=S1
V1D1’;
end
%%进行逆离散余弦变换
for i = 1:m
CC(i,:) = idct(cc(i,:));
end
%%% 进行逆离散小波变换
for i=1:m
c1(i,:)=[CC(i,:),cd3(i,:),cd2(i,:),cd1(i,:)];
b(i,:)=waverec(c1(i,:),l,‘haar’);
end
%%% 恢复分帧的信号
[m1,n1] = size(b);
B = reshape(b’,[1,m1
n1]);
a = a’;
b1 = [B,a(1,length(B)+1:length(a))];

% figure(1)
% subplot 311;plot(a);
% subplot 312;plot(b1);
% subplot 313;plot(b1-a);
snrvalue=snr(a,b1)
%%%%%%%%---------------------------
b1 = awgn(b1,5); %%噪声干扰
signal = enframe(b1,win); %进行分帧
[m,n]=size(signal); %求出帧数
%%%将分帧后的数据进行离散小波变换
for i = 1:m
[C,l] = wavedec(signal(i,:),3,‘haar’);
s(i,:)= appcoef(C,l,‘haar’,3); %3阶低频系数
end
[m,n] = size(s);
%%%读取图片水印
w_source=imread(y);
w1=w_source(;
%%%离散余弦变换
for i =1:m
s1(i,:) = dct(s(i,:));
end
vv2=[];
for i=1:length(w1)
[S2,V2,D2]=svd(s1(i,:));
vv2=[vv2,V2(1)];
ww2(i)=(vv2(i)-vv1(i))/q;
end
ww3=reshape(ww2,[256,1]);
for i=1:256
if ww3(i)>0.5
ww3(i)=1;
else
ww3(i)=0;
end
end
www=reshape(ww3,16,16);
nc_value=nc(w_source,www)
ber_value=ber(w_source,www)

figure(2)
subplot 211;imshow(w_source);
subplot 212;imshow(www);

你可能感兴趣的:(matlab,音视频,matlab,开发语言)