📄 delta_jayant.m
字号:
%*******************************************************
% Acest program..
%*******************************************************
clc; clear;clf;
file = 'sound.wav';
file = 'speech.wav';
[ys,fs,nbits]=wavread(file);
[m,m1] = size(ys);
if (m1 == 2), % stereo
y1=ys(:,1); y2=ys(:,2);
ym=(y1+y2)/2;
else
ym = ys;
end;
N=length(ym);
ts=1/fs;
t=0:ts:(N-1)*ts;
%subplot(211), plot(t,y1,t,y2,'r'); subplot(212), stairs(t,y1); hold on; stairs(t,y2,'r');
%wavplay(y1); pause; wavplay(y2);
%wavplay(yt);
% defineste vectorii scurti:
n = N;
x = ym(1:n); % intrarea;
t = t(1:n);
p = 1.5;
q0=0.01;
q=q0;
y=zeros(n,1); % vectorul de iesire, aproximat/refacut local;
b_new = -1; % valoarea bitului nou;
b_old = -1; % valoarea bitului vechi;
% modulatie uniforma
b=[-1];
for k = 2:n,
if x(k) > y(k-1), b_new = 1; else b_new = -1; end;
b = [b b_new];
% reconstructie:
if b_new == b_old, q = q * p; else q = q / p; end;
y(k) = y(k-1) + q * b_new;
b_old = b_new;
end;
[dt,dy]=stairs(t,y);
[dt,dx]=stairs(t,x);
subplot(211), plot(dt,dx,'b',dt,dy,'r-');
subplot(212), stairs(b(n-50:n));
file_input_size = n * nbits / 8 ; % mono channal;
file_output_size = n / 8 ; % mono channal;
compression_ratio = file_input_size / file_output_size
% semnalul refacut dupa compresie:
wavwrite(y,fs,nbits,'compressed_jayant.wav');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -