dm_demo.m

来自「By using a MATLAB program, design a Delt」· M 代码 · 共 60 行

M
60
字号
%Sample demo for Delta modulation

close all
clear
% signal sampling
fs=1/2000;
tn=0:fs:1/25;
%Example1 ****************************
s=.5*sin(2*pi*50*tn);

% Delta modulation-demodulation
StepSize=1/15;
%encoder
cn=dm_encoder(s, StepSize);
%decoder
[Sn]=dm_decoder(StepSize,fs, cn);
%lowpass filter
Sa=lpf(100, .1, Sn);

%plot the input and accumulator output 
subplot(3,1,1):plot(s,'r');
grid on
title('DM (red:input signal, green:decoder output, blue: LPF output)');
ylabel('amplitude');
subplot(3,1,2):plot(Sn,'g');
grid on
ylabel('amplitude');
subplot(3,1,3):plot(Sa,'b');
grid on 
xlabel('index, n');
ylabel('amplitude');

%example2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure
[s,fs]=wavread('bye441');  %read .wav file
% Delta modulation-demodulation
StepSize=1/15;
%encoder
cn=dm_encoder(s, StepSize);
%decoder
[Sn]=dm_decoder(StepSize,fs, cn);
%lowpass filter
Sa=lpf(100, .1, Sn);

%plot the input and accumulator output 
subplot(3,1,1):plot(s,'r');
grid on
title('DM (red:input signal, green:decoder output, blue: LPF output)');
ylabel('amplitude');
subplot(3,1,2):plot(Sn,'g');
grid on
ylabel('amplitude');
subplot(3,1,3):plot(Sa,'b');
grid on 
xlabel('index, n');
ylabel('amplitude');

sound(Sa,fs);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?