Signal Averaging & Conversion
Signal Averaging and Signal Conversion
The mat file contains 3 columns of data:
· The first column in the file (EEG1) is the signal obtained for an
electroretinogram, ERG (differential voltage, from right(+) to left(-) lower
eye lids, in micro-Volts)
· The second column (EEG2) is the activity of the visual cortex or Visual
Evoked Potential, VEP (Fz(-) to Cz(+), also in micro-Volts)
· The third column (STIM) is the stimulus trigger signal. A non-zero value
for the trigger signal means that a stimulus was delivered at that time, and
signifies time=0 for that sweep.
There are a total of m = 261 stimulus presentations, or sweeps. Fs= 2000 Hz.
The two signals EEG1 and EEG2 are measured in micro-Volts, which means
multiply them with 10^-6 to translate to Volts.
Write a MATLAB code that will allow you to:
1) Observe improvements in signal quality as you average more sweeps i.e.
signal obtained from each stimulus. For example, start with averaging
EEG1 and EEG2 signals in response to the first 2 sweeps These represent the response at two separate points in the visual pathway
(Retinal level and Visual cortex level). As you average more, and the
response is revealed, you will notice differences in peak times which are
representative of the conduction time along the visual pathway (Cortical
responses have later peak times or latencies due to this being further
down the visual path. Make two separate plots (Subplots on one figure) of
the averaged electroretinogram and visual cortex signals. Next average 10
sweeps, 20, 50, 100 and maximum available sweeps. For each sweep
count, create a separate figure with subplots showing the ERG and VEP
at those sweep levels. Explain what you observe.
2) Next, calculate the error introduced from ADC (Analog to Digital
a. Start with an ADC range of 0.01 V (±0.005V) and a 13-bit
resolution. How many possible values does this ADC give you?
b. For each point, calculate the output of the ADC (in a decimal
representation of Binary) and the corresponding digitized value for
the given input signal (in Volts).
c. Calculate Quantization error, which is the difference between the
analog input signal at each point and the digitized value at that
d. Make a plot using different colors showing the original analog
signal, the digitized signal and the quantization error for both EEG1
and EEG2 in different subplots.
3) If you were to repeat the same measurements for 10-bit, 12-bit, 14-bit and
16-bit resolutions, how many possible values do these ADC give you?
What is the resolution in each case? Repeat the plot created in part 2d for
each ADCs with bits 10-16, creating a separate Figure for each case.
What happens you use an ADC less than 10 bits? Is there a way around
this (something you could do to the input signal? Try multiplying your
averaged EEG signal by a factor of 10 and rerun the code? How does this
affect the plot?
global sig %Declared global for the function files to access the variable
globalpos %Declared global for the function files to access the variable
sig=[EEG1 EEG2]; %sig has two colomns: the first one is EEG1 and the second one is EEG2
%Change the second parameter in the swplot function if you want to change the averaging window
swplot(2,10); %Look at function comments for description
fprintf(‘To continue to ADC part, Press Enter.\n’);
sig2=sig(pos(1):pos(2),:); %Edit the indices in pos (here 1 and 2) if you want another part of signal to be processed
bitadc(index); %Look at function comments for description
delta=5000/((2^(bit-1))-1); %bit-1 is used instead of bit because the first bit represents the sign
adc_decimal=round(sig2/delta); %adc value in decimals
dgtl=adc_decimal*delta; %digitalised signal in microvolts
q_error=sig2-dgtl; %quantisation error in microvolts
dgtl=adc_decimal*delta*(10^-6); %digitalised signal converted to volts
subplot(3,1,1);plot(sig2);title([‘Original Analog Sig, bit size:’ num2str(bit)]);
subplot(3,1,2);plot(dgtl);title([‘Digitalised Sig, bit size:’ num2str(bit)]);
subplot(3,1,3);plot(q_error);title([‘Quantisation error, bit size:’ num2str(bit)]);
functionswplot(n,win_size) %n is the number of sweeps while win_size represents the averaging window
avg=filter(ones(win_size,1)/win_size,1,sig_); %averaging filter
subplot(2,1,1);plot(avg(:,1));title([‘Sweeps no:’ num2str(n) ‘,ERG’]);
subplot(2,1,2);plot(avg(:,2));title([‘Sweeps no:’ num2str(n) ‘,VEP’]);