All All: %PROBLEM 2.1
All All: %PROBLEM 2.1
Ravindranath Shrivastava
%PROBLEM 2.1
close all;
clear all;
Ts = .005;
t = (1:n)*Ts;
% Plot ensemble data superimposed
subplot(2,1,1), plot(t,eyedata,'k');
xlabel('Time (sec)');
ylabel('Eye Position');
avg = mean(eyedata);
subplot(2,1,2), plot(t,avg,'k');
xlabel('Time (sec)');
ylabel('Eye Position');
Output:
%PROBLEM 2.3
clc;
close all;
clear all;
subplot(2,1,1), plot(noise);
xlabel('samples');
ylabel('amplitude');
for j = 3:N
noise(j,:) = (noise(j,:) + noise(j-1,:) + noise(j-2,:))/3;
end
subplot(2,1,2), plot(noise);
xlabel('samples');
ylabel('amplitude');
figure;
subplot(311);
stem(l(N+1:end),c(N+1:end)); title('xcorr');
subplot(312)
stem(lags,acf); title('autocorr');
subplot(313)
stem(L(N-1:end),C(N-1:end)); title('xcov');
Output:
%PROBLEM 2.4
clc;
close all;
clear all;
subplot(2,1,1), plot(noise);
xlabel('samples');
ylabel('amplitude');
for j = 3:N
noise(j,:) = (noise(j,:) + noise(j-1,:) + noise(j-2,:))/3;
end
subplot(2,1,2), plot(noise);
xlabel('samples');
ylabel('amplitude');
Outputs:
%PROBLEM 2.6
clc;
close all;
clear all;
%Impluse Response of a first order filter
npts = 512; % Size of arrays
fs=200;
noise = randn(npts,1); % Generate noise
figure;
plot((1:npts)/fs,noise); % Plot autocorrelation function
xlabel('time - sec');
ylabel('amplitude');
L = 2000;
fs = 200; %Sampling Frequency
tau = 1; %Time Constant
for i = 1:L+1
n = i-L/2 ;
hn(i) = exp((-n/fs)/tau);
end
m = max(hn);
for i = 1:L+1
n = i-L/2 ;
hn(i) = hn(i)/m;
end
figure;
plot((1:L+1)/fs,hn); % Plot autocorrelation function
xlabel('time - sec');
ylabel('amplitude');
%mid = fix(size(cor)/2);
figure;
plot(lags,cor); % Plot autocorrelation function
xlabel('Lags (n)');
ylabel('Rxx');
figure;
plot((1:L+1)/fs,hn); % Plot autocorrelation function
xlabel('time - sec');
ylabel('amplitude');
out = conv(hn,noise); % Output - noise after filtering
[cor, lags] = xcorr(out,'coeff'); %Calculate autocorrelation
% with zero lag normalized
to 1
%mid = fix(size(cor)/2);
figure;
plot(lags,cor); % Plot autocorrelation function
xlabel('Lags (n)');
ylabel('Rxx');