How to Calculate Gaussian Distribution , mean, Median, Auto Corelation, Standard Deviation, Time Average of Signals Using Matlab


TASK 1
clear all
close all

%% TASK 1
% Generate random noise using Gaussian distribution for [10 100 1000 and
% 10000] samples and calculate mean and standard devation

% Signal 1 for 10-samples
signal1=randn(1,10);
ms(1)=mean(signal1);  % mean
stds(1)=std(signal1); % standard deviation

% Signal 2 for 100-samples
signal2=randn(1,100);
ms(2)=mean(signal2);  % mean
stds(2)=std(signal2); % standard deviation

% Signal 3 for 1000-samples
signal3=randn(1,1000);
ms(3)=mean(signal3);  % mean
stds(3)=std(signal3); % standard deviation

% Signal 4 for 10000-samples
signal4=randn(1,10000);
ms(4)=mean(signal4);  % mean
stds(4)=std(signal4); % standard deviation

display(sprintf('sample mean of 4 random signals are \n[%1.4f %1.4f %1.4f %1.4f] and \nstandard deviation in signals are \n[%1.4f %1.4f %1.4f %1.4f]',ms,stds))


%% TASK 2
% Plot Auto-correlation of all the 4 realizations and comment on your                                        TASK 2

ACR1=Auto_Cor(signal1);
ACR2=Auto_Cor(signal2);
ACR3=Auto_Cor(signal3);
ACR4=Auto_Cor(signal4);

subplot(2,2,1)
plot(ACR1);
title('Signal1 Autocorrelation plot');
xlabel('Lag');
ylabel('Normalized output');

subplot(2,2,2)
plot(ACR2);
title('Signal2 Autocorrelation plot');
xlabel('Lag');
ylabel('Normalized output');

subplot(2,2,3)
plot(ACR3);
title('Signal3 Autocorrelation plot');
xlabel('Lag');
ylabel('Normalized output');

subplot(2,2,4)
plot(ACR4);
title('Signal4 Autocorrelation plot');
xlabel('Lag');
ylabel('Normalized output');

%% TASK 3
% Comment on the mean ergodicity of the signals

erg1=ergo_check(signal1);
erg2=ergo_check(signal2);
erg3=ergo_check(signal3);
erg4=ergo_check(signal4);

figure
subplot(2,2,1)
plot(erg1);
title('signal1 moving average');
subplot(2,2,2)
plot(erg2);
title('signal2 moving average');
subplot(2,2,3)
plot(erg3);
title('signal3 moving average');
subplot(2,2,4)
plot(erg4);
title('signal4 moving average');

%% Comments


display(sprintf('moving average of 4 random signals are \n[%1.4f %1.4f %1.4f %1.4f]',erg1(end),erg2(end),erg3(end),erg4(end)))
display(sprintf('Increasing number of samples in the realization shows that the signal \nbecome more random and its
TIME AVERAGE
TASK 3
M=500;
T=250;
t1=0:4*T+1
for n=1:M
        random_variable=a + (b-a).*rand(1,1);
Xt=sqrt(2)*cos(2*pi*0.004*t1+random_variable);
Xwt = awgn(Xt,1);
end
Rt=TA(Xwt,T);
plot(Rt);


function [ Rt ] = TA( X ,T)


for td=-T:T
    Rt(td+T+1)=0;
    for t=T:3*T+1
        Rt(td+T+1)=Rt(td+T+1)+(X(t)*X(t+td+1));
    end
    Rt(td+T+1)=Rt(td+T+1)/(2*T);
end
end


MATLAB CODE
x =linspace(pi,-pi);
t=1:100;
f=500;
fx=3*cos(f*2*pi*t+x)
% Signal 3 for 1000-samples
w=randn(1,100);  % mean
stds(3)=std(w); % standard deviation
ft=fx+w
subplot(2,2,4)
plot(fx)
title('COS');
subplot(2,2,3)
plot(w);
title('w(t)');
subplot(2,2,2)
plot(ft)
title('x(t)');
m=mean(ft);
subplot(2,2,1)
plot(m,t)
z=autocorr(ft)
plot(z)



Comments

Popular Posts