Saturday, January 12, 2013

Low pass filter solution

Problem: periodic noise in data (see blue curve below).
Sampling frequency: 40 Hz
Expected signal frequency: 10 Hz

Solution: low-pass filter (Butterworth)
Matlab already provides the framework for filter design (Butterworth filter in Matlab).
For explicit algorithms see http://www-users.cs.york.ac.uk/~fisher/mkfilter/
(specifically http://www-users.cs.york.ac.uk/~fisher/mkfilter/trad.html)
Explanation for how filters work: http://www.electronics-tutorials.ws/filter/filter_8.html
Matlab filter usage: http://faculty.smu.edu/hgray/software/matlabfilterinstructions.pdf
Briefly:
  • the higher the order, the sharper the cutoff (see link above, 'how filters work')
  • Nyquist frequency is equal to half of sampling frequency
  • cannot apply filter to frequencies above Nyquist
Matlab code:
Input is a 1D array of current measurements labeled "f". Output is array "filt".
 f = f.*1E9; %convert to nA  
 time=(1:length(f)).*(1.0/40); % 40 Hz sampling rate  
 datahandle=plot(time,f);  
 xlabel('Time, s');  
 ylabel('Current, nA');  
 hold on;  
 sampling = 40; % sampling frequency = 40 Hz  
 nyquist = sampling/2; % nyquist frequency is half of the sampling frequency  
 cutoff = 15; % cutoff frequency = 15 Hz  
 n = 3; %filter order (higher is sharper cutoff)  
 Wn = cutoff/nyquist; % normalized cutoff frequency  
 [b,a]=butter(n,Wn); % get Butterworth coefficients  
 filt=filter(b,a,f); % apply filter to data  
 plot(time,filt,'Color','Red');  
 legend('Raw','Filtered');  


Results:
1) No signal present. Expect a flat line in raw data.
Clearly measurement has periodic noise. Filter removes the noise very well. Note the ripple in the the beginning of the filtered data.
Zoom:

2) Signal is present around t = 1s.

The spike in the beginning is an artifact of the algorithm. A quick solution is to insert fake data (repeated first value of the input array) in the beginning of the input array, apply the filter, and then remove the same amount of data from the beginning of the filtered array.
Matlab code:
 f = f.*1E9; %convert to nA
time=(1:length(f)).*(1.0/40); % 40 Hz sampling rate
datahandle=plot(time,f,'Linewidth',2);
xlabel('Time, s');
ylabel('Current, nA');
hold on;
sampling = 40; % sampling frequency = 40 Hz
nyquist = sampling/2; % nyquist frequency is half of the sampling frequency
cutoff = 15; % cutoff frequency = 15 Hz
n = 3; %filter order (higher is sharper cutoff)
Wn = cutoff/nyquist; % normalized cutoff frequency
[b,a]=butter(n,Wn); % get Butterworth coefficients
pad_length = round(length(f)*0.1); % 10% of original data length
f = [ones(pad_length,1).*f(1); f]; %insert fake data in the beginning of the array
filt=filter(b,a,f); % apply filter to data
filt=filt(pad_length+1:length(filt)); %remove the fake data
plot(time,filt,'Color','Red','Linewidth',2);
legend('Raw','Filtered'); 


Results:
1) No signal present. The spike in the beginning is reduced.
2) Signal present around t = 1s. 



2000 Pontiac firebird front turn signal light bulb replacement

Vehicle: 2000 Pontiac Firebird Formula
Symptoms: when signaling a turn, the blinker inside the car on the dashboard does not blink, but remains solid all the time.
Problem: the turn signal light bulb is out
Light bulb part: 3157NA (amber color). Light bulb reference: http://ls1tech.com/forums/appearance-detailing/1398916-official-4th-gen-f-body-light-bulb-list.html
Procedure:
1. Unscrew two bolts on the bottom of the car on the side where you're trying to replace the light bulb. The socket is a metric 10 I believe. Then plastic flap will be able to swing freely.
2. Insert your hand in the opening and twist the light bulb (with wires) from the housing. The wire is long enough to extend light bulb to the opening.
3. Remove light bulb.
Reverse the procedure to install the light bulb. No need to get under the vehicle for this repair.

O'Reilly Auto Parts did not have LED versions of the bulb, only regular.
The cost was around $6 for a pair of light bulbs.