0% found this document useful (0 votes)
49 views10 pages

All All: %PROBLEM 2.1

This document contains MATLAB code for analyzing biomedical signals as part of a homework assignment. It loads eye position data, calculates the average, and plots the raw and averaged data. It then generates random noise, applies averaging and autocorrelation functions to the noise, and plots the results. Finally, it generates impulse responses for first-order filters with different time constants, convolves the filters with the random noise, and plots the autocorrelation of the output signals.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views10 pages

All All: %PROBLEM 2.1

This document contains MATLAB code for analyzing biomedical signals as part of a homework assignment. It loads eye position data, calculates the average, and plots the raw and averaged data. It then generates random noise, applies averaging and autocorrelation functions to the noise, and plots the results. Finally, it generates impulse responses for first-order filters with different time constants, convolves the filters with the random noise, and plots the autocorrelation of the output signals.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Bio-Medical Signal Processing – HW 2

Ravindranath Shrivastava

%PROBLEM 2.1

close all;
clear all;

%Load Data from MAT file


load ensemble_data;
eyedata=data';

%Load Size of the data matrix


[m n] = size(eyedata);

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;

%Load Data from MAT file


N = 512; %size of the array
noise = randn(N,1);

subplot(2,1,1), plot(noise);
xlabel('samples');
ylabel('amplitude');

%Averaging of the data

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');

%Auto Corelation Part


[c,l] = xcorr(noise,N,'coeff');
[C,L] = xcov(noise,N,'coeff');
[acf,lags,bounds] = autocorr(noise,N-1);

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');

% Calculate autocorrela-tion, normalized


% Plot the autocorrelation functions
[cor, lags] = xcorr(noise,'coeff');
figure;
plot(lags(1,:),cor(:,1),'k'); % Plot using ‘lags’ vector
axis([-50 50 -.5 1.1]); % Define axes scale
ylabel('Rxx'); % Labels
xlabel('Lags(N)');

Output:
%PROBLEM 2.4

clc;
close all;
clear all;

N = 512; %size of the array


noise = randn(N,1);

subplot(2,1,1), plot(noise);
xlabel('samples');
ylabel('amplitude');

%Averaging of the data

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');

% %Auto Corelation Part


% [c,l] = xcorr(noise,N,'coeff');
% [C,L] = xcov(noise,N,'coeff');
% [acf,lags,bounds] = autocorr(noise,N-1);
%
% 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');

% Calculate autocorrela-tion, normalized


% Plot the autocorrelation functions
hn = [1/3 1/3 1/3];
out = conv(hn,noise);
[cor, lags] = xcorr(out,'coeff');
figure;
plot(lags(1,:),cor(:,1),'k'); % Plot using ‘lags’ vector
axis([-50 50 -.5 1.1]); % Define axes scale
ylabel('Rxx'); % Labels
xlabel('Lags(N)');

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');

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');

tau = 0.2; %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');
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');

You might also like