Sie sind auf Seite 1von 2

%% ADM (Adaptive Delta Modulation) system.

clc;
clear all;

%% To read the .wav files and select 1 of them to transmit


% You can replace the below sound profiles by any other sound profiles you
have.

% If you wanna use these same files, please download it from


http://www.mathworks.in/matlabcentral/fileexchange/24538-simple-fdm-
simulation/all_files

[x, Fs] = wavread('ali-university-story.wav');


sound(x, Fs);
[y, s] = wavread('beep-8.wav'); % Beep denotes the separation between 2
different files
sound(y,s);
[x, Fs] = wavread('birth-of-a-star-story.wav');
sound(x, Fs);
sound(y,s); % Beep denotes the separation between 2 different files
[x, Fs] = wavread('board-game-story.wav');
sound(x, Fs);
sound(y,s); % Beep denotes the separation between 2 different files

in = input('Enter the audio index which you need to TEST ADM code on = ');
if(in == 1)
[x, Fs] = wavread('ali-university-story.wav');
elseif in == 2
[x, Fs] = wavread('birth-of-a-star-story.wav');
elseif in == 3
[x, Fs] = wavread('board-game-story.wav');
end

%% Initializations made here for further use of them


T=1/Fs; nmax=length(x); t=[0:nmax-1]*T; % T = Time period ; %
Sampling frequency = 1/ T
Vmin=-0.1; Vmax=0.1; N=2; % N = 2 Because DM uses 1
bit quantiser
delta_min=(Vmax-Vmin)/(2*N); % Width of the quantization
interval = To avoid granular noise
delta(1) = delta_min;
[B,A] = fir1(50,10000/(Fs/2),'low');
lowpass = @(S) filter(B,A,S);

%% User controlled channel


% You can make use of any other noise channels, just search in MATLAB help
n_snr= input('Enter 1 if you need to add AWGN CHANNEL NOISE else enter 0 ');
if (n_snr == 1)
snr= input ('Enter signal to noise ratio = '); % SNR value
end

%% ADM Transmitter system %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


for n=1:nmax
if n == 1
d(1) = x(1);
dq(1)= delta(1)*sign(d(1));
mq(1)=dq(1);

else
d(n) = x(n)-mq(n-1);
dq(n)= sign(d(n));
delta(n) = delta(n-1)*(1.5^(dq(n)*dq(n-1))); % Width of the
quantization interval = To avoid slope overload distortion
eq2(n) = delta(n)*dq(n); % step- size control
mq(n) = mq(n-1)+eq2(n);
end
end
%% Channel noise AWGN %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if (n_snr == 1)
s = awgn(dq,snr);
end

%% ADM Receiver system %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


if n_snr == 1
Yn = s.*delta;
Xn(1) = Yn(1);
for k=2:length(x),
Xn(k) = Yn(k)+Xn(k-1);
end
else Yn = dq.*delta;
Xn(1) = Yn(1);
for k=2:length(x),
Xn(k) = Yn(k)+Xn(k-1);
end
end

%% Received information in the receiver


xn = lowpass(Xn);
sound(xn, Fs);

%% Plots of signals to observe what's happening


figure;
subplot(221), plot(t,x,'k-'), title('input signal (black)'), subplot(222),
stairs(t,xn,'r-'), title('received signal (red)'),
subplot(223), stairs(t,d,'k-'), title('transmitted side error signal
(black)'),
for n= 1:nmax
err(n) = x(n) - xn(n);
end
subplot(224), plot(t,err,'r-'), title('receiver side error signal (red)'),
figure, stairs(t,dq,'b-'), title('Quantiser output / Transmitted signal'),

%% Error power
sum_of_squared_error1=err*err' % (1 cross nmax) * (nmax cross 1)
= 1 cross 1

Das könnte Ihnen auch gefallen