Code covered by the BSD License

# Envelope Detector

### Yogesh K Soniwal (view profile)

17 Oct 2013 (Updated )

Inputs: Fc, Fm, Ka. Output: Optimum Time Constant

EnvelopeDetection(Fm,Fc,Ka)
function [TauOptimum] = EnvelopeDetection(Fm,Fc,Ka)
%% Inputs
% Fm = Message Signal Frequency
% Fc = Carrier Frequency
% Ka = Sensitivity Factor

%% Output
% TauOptimum = Optimum value of tau

%% Example
% [TauOptimum] = EnvelopeDetection(2000,40000,0.5)

tau_min =1/Fc;              %Lower bound of time constant
tau_max =1/Fm;              %Upper bound of time constant
Tc = 10^(-6);               %Sampling time of tau
tau = tau_min:Tc:tau_max;
num_tau=length(tau);
Ts=tau_min/100;             %Sampling time

t = 0:Ts:2*tau_max;
num_pts=length(t);
Envelope_Signal  =  1 + Ka*cos(2*pi*Fm*t);
Modulated_Signal =  Envelope_Signal.*cos(2*pi*Fc*t);

% Output Signal will be same as AM Signal at the first time instance. For
% each time instance it decays to get signal for next time instance.
% If value of the signal is less than Modulated signal at a time then on
% next time instant output takes value of Mudulated signal of previous
% time instance
for i=1:num_tau    %Simulation for all values of tau starts here
output_signal(1,1)=1+Ka;
for n=1:num_pts-1
if output_signal(1,n)<Modulated_Signal(1,n)
output_signal(1,n+1)= Modulated_Signal(1,n);
else
output_signal(1,n+1)=output_signal(1,n)*exp(-Ts/tau(1,i));
end
end
mse(1,i)=(norm((output_signal-Envelope_Signal).^2))/num_pts;%MSE Calculation
end

[~,TauOptimum]=min(mse);

output_signal(1,1)=1+Ka;
for n=1:num_pts-1
if output_signal(1,n)<Modulated_Signal(1,n)
output_signal(1,n+1)=Modulated_Signal(1,n+1);
else
output_signal(1,n+1)=output_signal(1,n)*exp(-Ts/tau(1,TauOptimum));
end
end

%% Plots
plot(tau,mse);
grid;xlabel('\tau (sec.)');ylabel('MSE');
title('MSE as a function of \tau');

figure;
% Modulated signal and output signal for optimum value of Tau
plot(t,Modulated_Signal);
hold on
plot(t,output_signal,'g','linewidth',2.0);
title('AM waveform and envelope detector output for \tau_o')
xlabel('Time(sec.)');ylabel('Amplitude');
end