Sciencemadness Discussion Board

Building a polarimeter

 Pages:  1  2  

smaerd - 22-5-2014 at 12:51

Be careful with the math hahaa. I have read in many places it is nearly impossible to calculate the actual capacitance needed to stabilize transimpedance op-amps like this. A lot of it boils down to trial and error, redesign, etc.

I also should mention there is a capacitance from the audio jack across the diode as well. We'll see.

aga - 22-5-2014 at 12:58

it's not the capacitance : it's the sheer Gain you're expecting from that op-amp

If i were not drunk, i'd search the net for op-amp examples and calculators.
Then i'd look up the optical device tech data.

Then i'd see if my op-amp gain Had to be in the millions, and if so, there's no way it would be stable, ever.

That's why multi-stage amplifiers exist.

Amplify a bit, pass it on to the next stage.

No amount of capacitor fiddling will do.

[Edited on 22-5-2014 by aga]

aga - 22-5-2014 at 13:16

To be totally fair, ths is like me expecting 100ml Pure Sulpuric Acid from a 40ml beaker containing wood ash and water.

Your device Will work, but that circuit will not.

Give me a day or two and i will look up the tech specs on your detector and op-amp and see if i can find a solution.

Feel free to Nag if i do not deliver on time.

smaerd - 22-5-2014 at 14:30

Thanks Aga. I was kind of thinking the same thing, but so many of these example circuits use 10Mohm, and even gigaohms. I was looking at that and scratching my head after I had read up on signal noise. I believe the LTC 1050 has a max gain of 20db also. So I am sure I have been wayyyyy over-loading it. This would also explain the clean signal with the extra capacitance.

I think I will try a transimpedance(current->voltage) which leads to a classic non-inverting voltage amplifier. I believe with 440kOhm resistance I was seeing 0-0.125V signals. So a R1/R2 = 40ish (or 20ish to be safe) should be fine. Again that's two stages with pretty big gain and most people say that to put the noisiest/largest gain stage as the first one. We'll see. I'll attempt it using two LTC1050's. It just makes the most sense right now.

[Edited on 22-5-2014 by smaerd]

Update- Ran my first trial with a dual stage amplification. Not bad. I mean very noisey but this seems like it will be easier to hone in on. As it is noise, not wild oscillation(okay some oscillation but it looks like there are two wave-forms not an infinite sweep).

Think the next step is actual shielding(not laying down foil), and transferring to prototype board after a few more simple tests. Then fine tuning capacitors/resistors as best I can. Also, Aga I took your advice. Drank a few beers for science. Well, the first one was to shield the motor :P, the second was well just incase I cut the can wrong, etc.

two stage amplification first attempt.png - 27kB

[Edited on 23-5-2014 by smaerd]

[Edited on 23-5-2014 by smaerd]

aga - 23-5-2014 at 07:38

I just started looking at th circuit and the BPW21 specs.

It's wired the wrong way round in theose circuits you posted.

Seems it's light sensitivity alters it's reverse bias current, not foward bias.

Also seems odd to be tying the + of the op amp to -5v, but i guess that's typo.

A quick google for 'BPW21 circuit' comes up with a bunch of images of circuits to do wxactly what you want.

[Edited on 23-5-2014 by aga]

smaerd - 23-5-2014 at 07:40

Are you sure? I just started getting great data.

The gain is nearly perfect(~0-~2.0V), the oscillations are gone. Just some stray noise. Need to fine tune this and see where this can be coming from. Motor is shielded. Should shield the audio jack plug next to see if that will improve anything. I don't know if I need an RF choke or not. Not sure if the analog pins have a common ground with the digital on the leonardo, I'll have to check to be sure. I'm thinking that a teeny tiny bit more tuning with capacitance and this thing can go onto some perf board!

so close dual stage.png - 23kB

[Edited on 23-5-2014 by smaerd]

[Edited on 23-5-2014 by smaerd]

[Edited on 23-5-2014 by smaerd]

aga - 23-5-2014 at 07:44

'Course i'm not sure.

Hey ! if it's working, it's working !


smaerd - 23-5-2014 at 07:59

Should I try to put some capacitors between my stages on the supply rails? Maybe it's voltage ripple from the varying two stages?

aga - 23-5-2014 at 08:09

Smoothing the supply as close to the devices as possible is aways a good idea.

As there 's a ADC converter somehere, you'll probably be getting some variation in how accurate that is, which will introduce some more noise in the data..

[Edited on 23-5-2014 by aga]

smaerd - 23-5-2014 at 09:23

Forgot all about the ADC... Well I've shielded damn near everything I can think of. I need to take this to perf-board. Alot of this could be induced by stray capacitance of the ridiculous jumper wires I am using. Or capacitance of the spinning audio-jack(worst case scenario) I am using this type,
.

Honestly every connection has 2-3 inches more wire then is necessary. Also there is the capacitance of the bread-board itself, and resistor prongs. It's also a lot harder to shield a bread-board(can't wrap it in foil without risking shorts). The PWM motor driver bread-board running with 12V is maybe 3 inches away from the detector board as well. Tried shielding it but it's a tangly mess. Need to put that on perf board as well and shield it. Once it's on perf, I should be able to tune it. I'll wire wrap the capacitors until I get where I need to be.

Well one thing I did realize with this project is, the mechanics/code and circuit could be used to build a UV or at least a VIS spectrophotometer(~200$ spectrophotometer that isn't a black box). Rather then rotate a polarizing element, rotate a grating element. So once I figure this out that may be an interesting follow up project. Or maybe someone else will take the lead using the same kind of idea. I'll definitely be making it all public domain once finished.

[Edited on 23-5-2014 by smaerd]

unionised - 23-5-2014 at 09:42

This is probably a stupid question, but can you easily see the light that gets through the cell?
If so then measuring it should be simple enough.

smaerd - 23-5-2014 at 09:52

It's not a stupid question but I am not sure what you mean if I see the light? Yes the light is visible on the detector to me and to the detector, but I try not too peak while the thing is running. I have not tested it with a cell yet. I am currently working on an algorithm to position the analyzing polarizer to a minimum. Then as soon as that is done, I will be able too implement the pre-written measure command to take a measurement(series of measurements), and observe the data. Which the soft-ware will then give the appropriate information useful for chemical analysis. So essentially once this noise is gone. An hour of programming and tidying up and this should be a completed project. Wellll, I still need to buy a cell and build a little mount for it, for testing but that will happen when the time comes... Or I'll come up with plans to build one for an affordable price...

Also long over-due are the instrument photographs. Had to borrow someone elses camera as mine stopped working. As you can see the laser circuit is currently disconnected from the arduino board for now and running off two triple AA's. Kind of a nuissance but I am trying to eliminate all the variables I can while working out this portion of the circuit.

Edit - Please don't judge too harshly on the choice of beer. It was what was in the fridge :P

one.JPG - 133kB two.JPG - 146kB three.JPG - 140kB four.JPG - 85kB

[Edited on 23-5-2014 by smaerd]

[Edited on 23-5-2014 by smaerd]

aga - 23-5-2014 at 13:37

Cool !

Yes, at the Gain you want, those wires are not Jumpers, they're Antennae !

The circuit is fairly simple, and you'll save yourself a load of bother by using some veroboard from now on.

I got some polarised film today, so i'll have a crack at a back-scatter type of polarimeter soon.

[Edited on 23-5-2014 by aga]

smaerd - 23-5-2014 at 14:12

Awesome! Never heard of a back scatter polarimeter. I'd love to hear about your progress/design. Edit - Oh wow! http://pubs.acs.org/doi/abs/10.1021/ac951169b

Polarimetry in Capillary Dimensions
Darryl J. Bornhop * and Joseph Hankins
Anal. Chem., 1996, 68 (10), pp 1677–1684

Yea I just read an article by bob pease "What is all this common ground noise anyways?". Was pretty enlightening. I also remember from my physics course about what Mr. Faraday and Mr. Maxwell said pertaining to loops of wire in the presence of changing magnetic fields :P. I also realized how bread-boards are almost perfect for creating those loops... I'll have to read up on good lay-outs to avoid this when I transfer the thing to perf. board. Also the effect of the photodiode and the circuit desperately wanting to pull current from all over has been a bit mind-blowing to me. I'd love to see the thermodynamic or E&M theory explaining this more fully.

[Edited on 23-5-2014 by smaerd]

aga - 23-5-2014 at 23:42

Te idea i had was simply to put a polarised filter in front of the laser, and a rotating polarised filter in front of the detector.

This is a bit of an addition to the Ramen thing i've been working on (and getting nowhere fast).

Here's an aciiart representation of what i'm trying to do :-

SAMPLE
/ \
(L E N S)
|
\ ------<------ Fixed Pol. Filter ----- LASER
mirror

(L E N S)
\ /
Rotating Pol Filter
\ /
Detector

I used to have a great camera and loads of software tools to manipulate images.
Now i have Windows 8, and so have absolutely nothing useful anymore.

The Mirror is a shard of broken mirror, as small as it can be to deflect Only the laser beam, glued to some stiff wire.
The idea is to try to avoid as much glass as possible (i.e. no splitter) and also reduce the amount of Rayleigh lght directly in the beam.

[Edited on 24-5-2014 by aga]

smaerd - 24-5-2014 at 09:59

Very interesting. I assume a mirror will be behind the sample? I'm a little confused by the optical diagram but hell it's ASCII hahaha. Think I get the jist. Well I fine tuned my code and found the actual number of pulses per revolution. Made a mathematical error in my early theoretical calculations that unfortunately stuck with me until now.

Anyways the harmonic regression is now 'dead-on'. So I can move forward a bit. By tonight I will hopefully have the majority of the soft-ware written. The analysis for the measurement of the sample will likely require a fourrier transform which is something I kind of over-looked until now that it's almost on the to do list.

fine tuned algorithm.png - 27kB

[Edited on 24-5-2014 by smaerd]

aga - 24-5-2014 at 11:44

Brilliant !

It is exciting to see you making progress so fast

FFT algorithms are out there on the net by the dozen.
FFt = Fast Fourier Transform. No point using the slow one ...

Here's one in C++ (duno what language you're writing in) :-
http://www.drdobbs.com/cpp/a-simple-and-efficient-fft-implem...

One thing about FFT is that the sample rate for a given resolution via an FFT needs to be the 'Nyquist Number' above the resolution required.

It's 2.
Work out your sample rate, divide by two and that's your resolution.

Sorry about the Ascii art, which unfortunately lost the spaces i put in.
No, there's no mirror.
Hopefully the refected or re-emitted light will also show some polarisation shift.
i can't immediately see if passing light through a substance, relfect it, then pass it through Again would cancel the polarisation shift, or double it.
Will see if i get time to try it tomorrow.

[Edited on 24-5-2014 by aga]

smaerd - 24-5-2014 at 19:08

Ooo that looks highly adaptable aga. I am using JAVA simply because it's a quick development language. Not quick performance-wise, but I've had no issues yet.

Well happy to update. I worked out the orienting algorithm, and the measuring algorithm(which was cake). Now I can officially say, noise aside, I have constructed an automatic polarimeter!

To do list:
- Obtain a sample cell
- To transfer circuits to perf board and shield (should handle the noise)
- Fine tune some of the algorithms once I have non-noise results
- Have the soft-ware to plot the results(already have it set up have just been lazy), and find maxima's.
- Test with some known compounds and get some real results.

It's been a long journey! I would apologize for spamming the crap out of this thread with noisey data and my thoughts but, I'm not exactly sorry.

The following image is a 180* rotation of the analyzer to find/interpolate the nearest minimum intensity value on the analyzer to rotate too.
first measurement orientation algorithm.png - 20kB

The following image is what happens once the minimum is found and the measurement button is pressed. The analyzer rotates generally about 90* away from the darkest point(with the sample in instrument) to obtain a 'semiconstant' angular velocity. Once it hits the minimum the data collection begins. Once it goes 360.0* from the minimum the data collection ceases. With nothing in the sample compartment, clearly two peaks are the result. Notice they are ~ equal in height now that the laser is aligned.
first measurement of nothing.png - 18kB

Interestingly the noise on the second peak is more severe. I believe this may be attributed to the antennae effect. The longer the gain circuit operates, the more it wants to induct/pull from the fields in the air. We'll see.

Start(orienting) to finish(measurement) it takes around 1 minute. It might be fun to write some kinetic experiment handling in the soft-ware. A fun test would be to do the classic mutorotation of glucose? Or maybe it's sucrose I forget, my brain is fried. Then compare results. Would be really nice not having to touch a thing either.

Drinking a beer to celebrate. Well actually to tone down the ridiculous concentration of caffiene and theobromine coarsing through my body. Irregardless, very happy!

@Aga - Thanks for following this with me. I'd love to see your back-scatter polarimeter set up. It's an interesting concept. I will have to think about whether the polarization will increase or not after reflection. Probably be more fun to experiment with it though. Never know what you might find.

[Edited on 25-5-2014 by smaerd]

[Edited on 25-5-2014 by smaerd]

smaerd - 29-5-2014 at 14:10

A little upset. Went from bread board to perfboard in hopes of getting a cleaner signal. Instead I somehow have an incredibly awful one. I'm not sure what is going wrong just yet. A little worried I may have somehow fried one of my op-amps while soldering. Might save troubleshooting until tomarrow as this has been a real disappointment and I've triple checked the circuit.

rawrrr.png - 40kB

Edit- I cleaned up the signal a little bit, but there is no or very small amplification. No longer are they clean sinuisoids, and the noise is just as bad if not worse than before. Ughhh, might of been better on bread-board.


Bought some DIP 8 sockets. I definitely fried ANOTHER op-amp hahahaha, this time by soldering. Ordered some different ones that should be good performance-wise. So it will be back to bread-boarding then protoboarding in 4 or so days... Soon as this circuit is done though, the instrument is finished. So painful to be so close and be stuck waiting.

[Edited on 30-5-2014 by smaerd]

aga - 30-5-2014 at 14:32

Unlikely that you fried your chips unles you heated them with a blow-torch !

Got a photo of the board ?

smaerd - 31-5-2014 at 09:20

Well I was using a 100-120 watt iron, with a copper tip(original tip burned out so I replaced it with some 12 AWG solid core copper wire). Definitely burnt and melted some of the PCB along the way :(. Try not to judge too harshly by my poor soldering job this was the second circuit I've ever put on protoboard. I tried to heat the PCB more then the pin and apply little blobs of solder but it didn't work as well as I'd of liked it too. The iron I have isn't made for these kinds of tight connections either. I think the solder I am using might be bogus as well, it's "cold heat" solder... Not even sure where I got it from.

Would you prefer to have connections labeled because it looks pretty confusing to me?

The conglomerate of soldered wires leading to the negative supply is something I was doing to test whether the issue was related too my power supply/decoupling portion of the circuit(rebuilt it on another part of the board). Power supply was functioning fine. I tested around kind of quickly with a multimeter around the op-amp stages and I believe it was the transimpedance stage that appeared wonky. Was a few days ago so I can't remember exactly what seemed wrong with it(needed a break from it).

Also on the back of the board you'll notice some scratch marks between lines going to the IC. I did that with a razor because there appeared to be a small short in a few areas. I unfortunately do not have desoldering whick or a desoldering sucker thinking about improvising one, but might just go with soldering in sockets then putting in the chips. The LTC1050 has this pin called "EXT CLOCK INPUT" or something. I have no idea what it does and can't find technical information about it, but I think I may have shorted it at one point with this circuit as well. The last time I did that on bread board it fried the IC(goo leaked out of it?).



DSCN0977.JPG - 101kB DSCN0978.JPG - 112kB DSCN0979.JPG - 87kB

[Edited on 31-5-2014 by smaerd]

[Edited on 31-5-2014 by smaerd]

[Edited on 31-5-2014 by smaerd]

aga - 31-5-2014 at 09:52

Not bad at all !

A good iron is a key tool in building stuff like this.
Personally i prefer a 50W iron. A lot of people say 25W is better.

Any stray solder joins were made by you and the soldering iron.
Easiest way to remove them is by you and the iron again - clean the tip and melt the stray join onto the iron, or swipe it away.
A solder sucker is also very useful at times.

Datasheet for the LTC1050 is here :-
http://cds.linear.com/docs/en/datasheet/1050fb.pdf

As stated on page 7, "When the LTC1050 operates without using an external clock, Pin 5 should be left floating".
So you leave it unconnected.
The sample PCB layout on page 6 shows the pin as unused (unconnected).

This chip uses a sample-and-hold technique, and needs a clock in order to work.
It has it's own built-in clock, running at 2.5khz.

Pin 5 is there in case you disagree with the designers, and want to clock it at a different frequency,
in which case you must supply your own oscillator, and shove the signal into pin 5.

I got an Arduino Uno kit today, so if you need any programming help, i can test here and send you code.
Doh. 'Sketches' then. All looks like programming to me ...

Quote:
using a 100-120 watt iron, with a copper tip(original tip burned out so I replaced it with some 12 AWG solid core copper

So yes, a Blow Torch then !

[Edited on 31-5-2014 by aga]

smaerd - 31-5-2014 at 10:31

Thanks for letting me know about that pin. I mean I assumed that was it's function, just wasn't sure how it would respond to say 5V essentially D.C. being thrown at it or if it would need resetting :D. Just going to start fresh instead. The LTC1050's are great little op-amps but I thought about it and a lot of the performance I need could be handled with some cheaper more ubiquitous components. The non-inverting voltage gain stage, really didn't need to be an LTC1050, at all... Think a TL082 will do fine there. We'll see how the parts I spec'd out will do. Originally I wasn't fluent enough to actually decide on the chips, now I'm more confident in my decisions.

Yea pretty much a blow-torch hahaha. Thing can melt solder in 2-3 seconds which is way too much for a PCB or a sensitive IC. I'm going to go buy a cheapy 50watt I think just for future projects, not everything I do has to be improvised. Guess it's how I was raised. Wish I would of known about those DIP-8 sockets for protoboarding before doing this, live and learn.

Nice let me know how you like the Uno. I'm using a Leonardo. I'm okay on programming, well it was my first time doing anything with a microcontroller but I kind of have the hang of it. Spent many years writing code growing up, so that helped, and also helped with writing the front-end. Kind of crazy how you never really forget that kind of stuff. Arduino's are nice, as they are kind of higher-level("sketches") but there is access to the lower level stuff if you really want to dive into it. I definitely use the lower level digital read commands for speed (not that it's necessary but it makes me feel safer). Still need to implement my ADC stabilizing stuff for accurate readings but the circuit comes first before fiddling there. I was actually considering switching to a rasberry pi or beagle bone black just so I could really rip my motor and get all the data I wanted quickly. Even store said data, rather then relying on it passing through the serial pipe. Ultimately though, this will work fine.

If you plan on doing serial communication and get lost let me know. Big hint for me was downloading the arduino source-code and seeing how they handled everything (gotta love open-source, no need to break out the decompiler :P). I have some pretty decent integer passing algorithms and things(not that it's a difficult problem to solve, break them into 2 byte chunks and just pass them down). I can get you the source code I have to build off of, that's what community is for. It's in JAVA though, which I know most real programmers find horrendous, but the idea's are the same. I haven't cleaned up my code much yet, that's kind of a finishing touch type of thing. Function comes first.

[Edited on 31-5-2014 by smaerd]

[Edited on 31-5-2014 by smaerd]

aga - 1-6-2014 at 00:26

Arduino is quite nice, in that it's very quick easy to get something started.
I can see now how they became so popular.

How i thought you'd do this project would be to use a stepper motor to control the rotation of the polarised filter.

First Calibrate, which would be to step around to the Least light intensity with no sample present, which would be the 0 point.
Then add the sample, go one step, measure, send data. Repeat for all steps in a full revolution.

A simple averaging ADC technique is to take a multiple of 2 samples each time, add that to an accumulator, then shift the resulting accumulator right N times to perform an ultra fast division.

i.e.
zero accumulator variables,
sample,
add ADC reading to accumulator,
repeat the sample/add 8 times
shift acumulator Right three times (=divide by 8)

You can refine that by storing each sample, and discard any results that are Way off, but that usually isn't necessary.

My preference is for Assembler, as you get to control exactly What is going on, and When.

The part i have never been any good at is getting the data into a form that the User can understand, especially in Windows.
If you could post an example of getting data from the arduino to a windows PC and display it, that would be really helpful.

smaerd - 6-6-2014 at 08:43

Really sorry for taking so long on this. A lot of crazy things have been happening in my life. One was pretty bad but the other really good, give and take. Anyways, here is some source code for how I am handling serial passing.

Heres the threaded method I am using which checks for incoming serial data.
Quote:

public synchronized void serialEvent(SerialPortEvent oEvent) {
if(oEvent.getEventType() == SerialPortEvent.DATA_AVAILABLE){
try {
while (input.available() > 0) {
stillRecieving = true;
lowByte = input.read() & 0xff;
highByte = input.read() & 0xff;
transferredInt = (int) (highByte << 8 | lowByte);

if(IncomingData){//Data is being transferred quickly over serial
if(transferredInt >= 0 && transferredInt < 1024){//Data was sent
//recievedData.add(transferredInt);
dataHandler.addNewIntensityMeasure(transferredInt);
} else {//Instrument command was sent, not data (Initialize, measure, etc)
handleInstrumentMessages(transferredInt);
}
} else {//Instrument command was sent, not data (Initialize, measure, etc)
handleInstrumentMessages(transferredInt);
}
}
stillRecieving = false;
} catch (Exception e) {
System.err.println(e.toString());
}
}
}


Then I have a class(DataHandler) which consists of essentially an arraylist of integers(polarimeter intensity&rotation information) and some basic methods to handle such.

Probably the most important thing in that class for what you're asking about is the method that constructs the 2-D array of information that the graph GUI library can turn into a visual element of said data(using JFreeChart). JFree Chart is an exceptional library for Java for creating all kinda of charts/graphs etc. Royalty free, and honestly, has some performance too it(haven't clocked it), but charts that struggle in LibreOffice are nothing in JFreeChart. Shouldn't have even bothered with making spreadsheets should have just worked with the soft-ware could have saved hours.

Quote:

//Changes the received data in the integer arraylist
//to a double[][] so it can be used in a chart GUI element.
public double[][] getXYDataSet(){
int dataSize = recievedData.size();
double [][] newSeries;

if(dataSize > 0){
newSeries = new double[2][dataSize];
for(int i = 0; i < dataSize; i++){
newSeries[0] = (((double)i)/((double)halfRotationPulseCount)*180.0);
newSeries[1] = recievedData.get(i);
}
}else{//If Data array has no entries return blank XYdataset
newSeries = new double [2][1];
}
return newSeries;
}


That class also handles the harmonic regression analysis. If you wanted to see how I was going any of that just ask, it's pretty easy.

This is how I am populating/updating the graph and the 'DataHandler' class.

Quote:

private void populateGraph(String label){
DefaultXYDataset ds = new DefaultXYDataset();
double [][] newSeries = dataHandler.getXYDataSet();
dataHandler.clearDataCache();

ds.addSeries(label, newSeries);

cp.removeAll();
plot = ChartFactory.createXYLineChart("Measurement",
"Angle Of Rotation(Degrees)", "Intensity(AU)", ds,
PlotOrientation.VERTICAL, true, true, false);
cp.setChart(plot);
cp.setLocation(0, 0);
cp.setBounds(0, 0, 640, 320);

add(cp);
cp.repaint();
}



Assembler is probably the most powerful programming language. Again though it's so low-level, not very fast for testing things out.

I did get the new op amps(LF356N & TL082) and am testing circuits today to see what I can make happen on bread board. I'll let you know if I can get anything decent, other-wise it's back to the drawing board.

[Edited on 6-6-2014 by smaerd]

smaerd - 10-5-2015 at 04:28

So I finally had some time to replace my old op-amps, buy some 1% resistors, etc. I never got to tell ya'll, I was able to remove the noise from the measurments! All I had to do was abandon the audiojack and limit some of the capacitance by using 22awg bare solid core wire on the bread board.

The only thing that's been stifling the project now is simply aligning the detector and sample cell. I am working on a way to do this with craft foam that I did fiberglass and bondo over. I'll let you all know if I get it to work out.

Anyways here's a screenshot for the data of an alignment run. Notice there's no stray dots. Also notice it's not a clean sinuisoid because my source and detector are not parallel. But no more noise!

latest poalrimeter.png - 64kB

edit - if anyone has any nice DIY ideas for creating a sample cell holder and photodetector holder I'd love to hear them. I'm still worried this foam idea won't work out. It's sitting on foam now and still a pain to line up.

Can't wait to put this idea to rest after two years of off and on working between semesters.

[Edited on 10-5-2015 by smaerd]

smaerd - 19-5-2015 at 08:56

So.... I finally have the signal working out, yahoo right? I fixed all of my soft-ware bugs, great. I ran my first trial. And it doesn't look as though I am even polarizing the light lol.

So I did a blank orientation run, and a blank measurement run (left and right images below)
blank1.png - 14kB blank2.png - 15kB

Looks like my motor positioning algorithm is a bit off. It looks like I've started taking measurements too late to catch the first sinuisoid at it's minima. The maxima are at about 270* and 90* (have to add the offset of ~25*). Which means physically and electronically everything is working okay, despite the imperfect sine data. (not sure why this is, things are aligned pretty well, might be too much feedback capacitance)

Then I set up to do another run this time with a sample.
I ran my orientation run (to find min & maxes of a blank cell). Notice that the intensity is quite high, near 900 counts. 87% of the maximum voltage for the microcontroller - amplification success. I'm pretty proud that I was able to work that out without anything other then a 10$ multimeter.
plzplzplz1.png - 14kB

I made a 20% w/v sucrose solution (20g per 100mL) and put it into the sample tray
plzplzplz2.png - 15kB

It's obvious the absorbance has increased, which is a good sign. It doesn't look like the angle of rotation has changed much if at all from what a blank run should be(near 280* and near 100*). Finally conquered some yucky serial transfer code. Now it's just a matter of fine tuning the microcontroller and maybe the amplification circuit.


[Edited on 19-5-2015 by smaerd]

[Edited on 19-5-2015 by smaerd]

aga - 19-5-2015 at 12:38

Incredible work smaerd !

For repeatability and sanity, align your analogue section to some definite point (without sampling in software) and leave it there - note that point.

Then adjust in software for the expected output.

Otherwise you'll be endlessly battling between what the software tells you and knowing you can tweak the gain of the op-amps etc, then going back and finding you can tweak the code again, ad infinitum.

aga - 19-5-2015 at 12:46

Quote: Originally posted by smaerd  
if anyone has any nice DIY ideas for creating a sample cell holder and photodetector holder I'd love to hear them. I'm still worried this foam idea won't work out. It's sitting on foam now and still a pain to line up.

What's required o smaerdy one ?

McGuyver at your service.

IrC - 19-5-2015 at 14:48

Quote: Originally posted by smaerd  
So I finally had some time to replace my old op-amps, buy some 1% resistors, etc. I never got to tell ya'll, I was able to remove the noise from the measurments! All I had to do was abandon the audiojack and limit some of the capacitance by using 22awg bare solid core wire on the bread board.

The only thing that's been stifling the project now is simply aligning the detector and sample cell. I am working on a way to do this with craft foam that I did fiberglass and bondo over. I'll let you all know if I get it to work out.

Anyways here's a screenshot for the data of an alignment run. Notice there's no stray dots. Also notice it's not a clean sinuisoid because my source and detector are not parallel. But no more noise!



edit - if anyone has any nice DIY ideas for creating a sample cell holder and photodetector holder I'd love to hear them. I'm still worried this foam idea won't work out. It's sitting on foam now and still a pain to line up.

Can't wait to put this idea to rest after two years of off and on working between semesters.


I have not looked at this thread in a long while and maybe I missed it in the text but what software are you using for this and is it available.

smaerd - 19-5-2015 at 16:03

@aga - I'm not tweaking the intensity signal of the photodiode in the soft-ware, I'm tweaking the motor rotation. The issue now is "clipping" of the signal (sine wave hits minimum for a long period of time) and it looks like the sine function extincts more slowly then it should. I'm thinking thats circuit only work unfortunately, but if I buy maybe 3-4 capacitors in the right range I should get better results. I might add some smoothing functions later to the data but I'm keeping it as 'raw' as possible. Then again the signal to noise ratio seems really small so it's probably unnecessary.

DSCF0032.JPG - 237kB

Here *pops the hood*. Do you see how the detector is suspended on the aluminum frame(on the right) and how on the left there's the light source. Now I've finaggled around a bit and I have a system worked out with planks of wood on screws so I can adjust the position of those things. I really want a way to align the lightsource and the detector with something more permanent rather then wood. Any ideas would be appreciated.

@Irc - The soft-ware I'm using is soft-ware I've been writing as the project has progressed. It's all JAVA, nothing too indepth and I'm sure a professional soft-ware engineer wouldn't like my approaches/structuring but it works and isn't heinously sloppy. If you need help doing things like this or want some source code to build off of, simply ask, I share code for free and no royalties or whatever.

I'm not exactly willing to pass out my code for the polarimeter yet though until I reach a stable version (IE when I'll post a complete write-up). Otherwise I might lead someone into a dark corner. In the mean time though I can give out snippets or how I approached problems :).

[Edited on 20-5-2015 by smaerd]

[Edited on 20-5-2015 by smaerd]

IrC - 19-5-2015 at 17:04

Yes I would like to have to source and I can wait until you have done your write up. Looking forward to it I like this project. I think threads about building test and measuring instruments is my favorite part of SCM.

smaerd - 20-5-2015 at 12:27

Hmmm, so I had my go with sucrose again after I totally revamped my positioning algorithm. I found out the hard way, my data is not-sinuisoidal enough to do a formal second derivative analysis :/. Kind of a bummer, so I came up with another way to handle my motor. I won't bore you with the details unless you wanna know.

Anyways the positioning algorithm appears to be working wonderfully. Picture on the left is the unoriented analyzer/motor (notice the little tail of the sine function going upwards on the right hand side?). Picture on the right is the oriented polarizer with sucrose solution (notice no tail).

blanking.png - 16kB 20 perc suc again.png - 15kB


Unfortunately... It looks like my sucrose solution is not polarizing light whatsoever. My peaks are locked in at 90* & 270*(raw data file attached). It probably is polarizing light, just minorly, which I could write a routine to detect these shifts but I want to see something more promising before I write another routine... So I am going to really up the concentration and see if I can get something drastic. 20% was nothing, let's try 60.

I'm really hoping I don't need a specialized substrate for this wavelength.

[Edited on 20-5-2015 by smaerd]

Attachment: 2015-05-20_160802.csv (306kB)
This file has been downloaded 700 times

[Edited on 20-5-2015 by smaerd]

smaerd - 20-5-2015 at 13:20

Well, I ran my experiment once more with 60% sucrose solution freshly made.

Definitely seeing polarization!

Unfortunately my motor positioning rather then having the peak be at 90* it's at 90.38 ish. So not perfect, but its getting pretty close.

Anywho, I got a value of about 109.63* for my observed peak with 60% sucrose at 650nm(I think...) 1dm pathlength and ~25*C. The value I obtained for the specific rotation is 32.08*. Which seems pretty low, but I have no idea. The point is the thing seems to be working! Edit- keep in mind those values were hand picked, not computational results, feel free to do your own analysis. Most importantly this tells me that positive rotations end up as positive phase shifts (I got lucky in choosing a motor direction).

I'm not 100% sure how to improve my results yet, or how much error is attributed to them. Insight would be wonderful. I think I can put the project down for a little bit though to give it some good thought.

Attachment: blank.csv (307kB)
This file has been downloaded 690 times

Attachment: 60 sucrose.csv (305kB)
This file has been downloaded 698 times

[Edited on 20-5-2015 by smaerd]

[Edited on 20-5-2015 by smaerd]

aga - 20-5-2015 at 13:41

Brilliant stuff smaerd.

I'm still unclear about a few things so must ask (please verify/correct if wrong).

1. In the photo, the detector is the tube to the Right with the aluminium cage around it.

2. The sample is in the large aluminium hub to the left of the larger gear wheel.

3. The light source is the grey blob top left.

4. the first polarising filter is on the rotating stuff, and immediately After the light source, and Before the sample.

5. there is a second polarising filter fixed to the light inlet to the detector.

smaerd - 20-5-2015 at 13:50

Here I'll outline whats going on. I think you're correct with what you said I just want to be clear as possible because there's a good chance any passerby would be uncertain as well. Especially after the fuss that happened in my DIY rotovap prepublication thread because I didn't take enough pictures lol.

layout.png - 725kB

[Edited on 20-5-2015 by smaerd]

[Edited on 20-5-2015 by smaerd]

aga - 20-5-2015 at 14:10

Cool. Thanks - that explains it very well.

OK.

First off, wood isn't good as a mechanical reference, so use some steel bar or aluminium plate or some other metal to bolt it all to - that will give you at least 1 axis of stability, and make alignment easier.

If you can drill/tap holes, then bolts with springs is a convenient way to make alignment easier.

Solder up the analogue section on veroboard or something. Breadboards + op-amps is just asking for random noise, feedback etc.
Also stick a 100uf capacitor + a 10nf one right next to the op-amps' supply pins.

Cut/bend a tin can to make a grounded shield around the circuit to eliminate 'other' noise sources. Use screened wire between the detector and the circuit and make the leads as short as possible.

Trim your op-amp gain to be about 80~90% of the max your arduino can handle (3v3 or 5v ?). You loose a bit of Range yet gain some repeatability, and lose the clipping.

In the software, step, wait, measure. measure. measure. measure to derive an average for each step. 8, 16, 32 are good as a sample size for each step as you can do a right shift (fast operation) to do the divide.

e.g. for averaging 16 samples:-

int i, avg;

for(avg=0, i=0;i<16;i++) avg += sample_sensor();
avg = avg >> 4;

If you do not wait, then the sample just after stepping the motor will have jitter due to the mechanical settling time required.

Normally i would use a bubble sort routine to find the median value rather than the average.

This helps to reject random noise (e.g. 1023 and 0 as readings).

aga - 20-5-2015 at 14:27

bubble sort routine that should work on arduino.

I tried posting the code but bits were interpreted as tags.

Attachment: bubblesort.txt (381B)
This file has been downloaded 683 times


smaerd - 20-5-2015 at 15:31

Yea I considered using an aluminum sheet or similar for aligning the optics but the stuff is expensive and I don't really have good tools for working with metal. Hack saw and a drill press is about all I have and it's really hard for me to get everything where it should be. I wish I had a CNC, it'd be so easy. Or a 3-D printer.

Arduino analog signal is 5V max (maybe 5.15V). I was at about 90% I'm thinking about dropping down to 75% for my gain next test. Yea I'm gonna switch over to perfboard as soon as I am happy with the signal. The op-amps are about 5 USD a piece, I can't afford to fry anymore. I can't tell if the clipping is excess capacitance, too much gain on one stage, or a physical alignment concern.

Yea my routine for measuring doesn't involve waiting. Which I know sounds dangerous but there's just no way for me to PWM a motor and get everything done I want done. I'd need a dual H-bridge type motor driver circuit and lots of hideous code, and there's more room for things to go wrong imo. I'm spinning the motor and reading at the same time and chucking it down the serial. It's a DC motor not a stepper. Think I'm looking at 13,000 or some odd measurements for a full rotation. So it'd take a long time to do a routine which involved waiting.

Thanks for the algorithm I remember doing an excercise like that years ago. I haven't dealt with much stray noise. I am getting a bit of a wonky signal when I really zoom in, but really I think it's ADC noise, it's pretty indeterminant but it hardly effects the quality of output.

I guess I'll show you the algorithm for how I am finding the minima without the elegant trig I was doing before (back before I had signal clipping). Was pretty fun to write lol. It takes advantage of the fact that the peaks (top of the signals) are pretty prestine and consistent (attached). If I can get more sinuisoidal data like before I'll show you the really nice code I wrote for it.

Thanks for the advice!

[Edited on 20-5-2015 by smaerd]

Attachment: MinimaSeekingAlgo.txt (3kB)
This file has been downloaded 635 times

[Edited on 20-5-2015 by smaerd]

[Edited on 20-5-2015 by smaerd]

aga - 21-5-2015 at 00:40

I've got a spare steppers & driver boards i can send if they'd be of help.

@1.6 degrees per step that'd give you 225 sample points with half-stepping over 180 degrees of arc, although you could always gear it down to increase the resolution.

Are you indexing the position of the motor off a hall switch or similar ?

smaerd - 21-5-2015 at 10:16

Thanks for the offer, I don't think I need to change out my motor. I'm getting pretty good positional accuracy here.

So I just tweaked my op-amp circuit. I reduced the gain on the first stage pretty significantly, and found two more balanced resistors (5% sure isn't 5%, someone at QC goofed up on the 220 K ohms I was using). Then I increased the gain of the second stage to compensate. I'm at about 4/10ths of the arduino max signal potential. Thats running on two highly used triple A batterys for the light source. Not bad. Signal looks good, that's really all I care about.

Here's a picture of my current noise situation(zoomed way in). It's acceptable to me, considering the signal is about 100x larger in magnitude.
Untitled.png - 35kB

I toyed with changing the capicatances on the op amp stages, reducing them to 100's of pico farad was a bad call. Lots of oscillations essentially pure noise. I tried 1/10th what the capictance is now, didn't really change the clipping at all. or the band shape.

Anyways the noise looks a little prettier to me than how it was before so I'm gonna keep it this way. If I had an oscilliscope I'd be able to tune this thing more, but this serves it's purpose and seems to work well.I'm leaning more towards the physical allignment being the culprit for the funky band shapes.

I also found a source for a small error in my positioning algorithm. I'm not sure how to overcome it just yet, I think I'll have to hit the drawing board.

[Edited on 21-5-2015 by smaerd]

aga - 21-5-2015 at 12:16

i simply have to have a go at this myself.

smaerd - 21-5-2015 at 14:50

Give it a shot aga it's really not a major project. The only reason why it's taken me so long is stupid mistakes like using a 100w soldering iron and melting IC's lol and lots of school and other busy life things.

I just fine tuned my firm-ware a bit and I seem to be getting acceptable results. I tightened up my alignment as best as I could so now I'm really not sure why I'm getting those funky band shapes.

I'm trying to think of some good cheap test substrates or an experiment I can perform to test this thing out. All that's really left to do is wrap up my soft-ware and firmware then maybe try an LED again with the new amplification stage. I think I abandoned the LED too soon, but I was frustrated at that point.The nice thing about an LED is that I could compare my results to literature values.

Edit - So I just tried holding one of those super bright LED's I bought a while back about 10cm from my detector. Looks like I can pull a hundred counts out of it without changing my amplification stage, not bad. I am going to try and switch back to an LED design.

LED.png - 15kB

[Edited on 21-5-2015 by smaerd]

aga - 21-5-2015 at 15:04

Never give up.

Adapt, and change.

Laser, LED, whatever - they tend to stay constant in their behaviour.

Adjust your approach instead, and conquor it you will.

smaerd - 21-5-2015 at 19:54

I was able to get a signal and everything which was great, I realize I could improve the optics of the LED and change my gain and yadda yadda yadda. Then I remembered why I was so happy with the laser diode, its so easy, its point and shoot (thanks bfesser for that suggestion it changed my entire project).

orangeLED.png - 14kB

I found a web page which stated that the greater the wavelength of light the less polarized it became by a sample. Which physically makes a good deal of sense. I believe they said at 436nm the polarization can be 2x as much as that of 589nm(http://rudolphresearch.com/products/polarimeters/polarimetry...). I'm not sure if my diode is 650nm or 680nm but regardless it explains the low specific rotation values I was seeing.

So I did some scoping around and 532nm laser diodes are very cheap, will give me a greater polarizing effect then 589nm which may be beneficial (less sample for analysis), and best of all they are in a range which my detector is very sensitive! So I may not get as much clipping or any at the lower light levels. The nice part of this design is I can interchange light sources, so if someone ever produces a 5mW 590nm laser or something I'll snatch one up. In the mean time...

No literature comparisons, but using less sample, and ease of use is good enough reason for me. Besides do I really care about the specific rotation of something, no, I want to use this thing for analysis :).

The other funny thing about this is, I can actually use this sucker as a colorimeter from about 400nm to 700nm. So yea it's not a UV-VIS or totally practical but heck I have often wanted a colorimeter anyways. I'm definitely going to modify the sample comparment area in a modular way to incorporate that functionality.
[Edited on 22-5-2015 by smaerd]

[Edited on 22-5-2015 by smaerd]

aga - 22-5-2015 at 11:56

is it ready yet ?

I've been waiting *hours* !

aga - 22-5-2015 at 12:48

No news yet ? It's been minutes !

smaerd - 22-5-2015 at 15:12

Haha Aga, sorry to disappoint. I'm waiting for a green laser diode to be shipped rather than fiddling with the LED's. I like the laser diode so much more. LED's just weren't meant for doing 10-15cm path lengths without focussing elements. I'd rather keep my poorly aligned optics as limitted in number as possible.

The project is pretty close to done though. I believe my first sample was accurate, but when I get my green laser I'm going to put this thing to the test and see if I can do a couple experiments to demonstrate it's efficacy. I'll test 5 concentrations of sucrose. Then if that looks good I'll maybe do a mutorotation of glucose experiment (if I can make the buffer for it I forget what weak acids and bases I have). Then anything from there on I'll be doing for other projects not just demonstrating "it works". In the case that it doesn't work there'll probably be more rapid fire posts in this thread lol. I really need to finish up my latest project though so I can surprise ya'll with it.

I was thinking about doing my encoder routine in quadrature just for shits and giggles. I'm just not sure if I really need 26,000 data points it would bring me from 0.02* positional resolution down to 0.01* though which sounds kinda saucey.

Either way I am already at 1/10th the encoder resolution of this instrument - http://www.vernier.com/products/sensors/chem-pol/ and mine is automatic with changeable light-sources and less than half the cost.

[Edited on 22-5-2015 by smaerd]

smaerd - 24-5-2015 at 06:16

So I built a farraday cage around my house and implemented ferrite chokes on all my lines, balanced my circuit with handfulls of gimmick capicitors, made a new ADC for the arduino. Okay those are all lies to make aga giggle.

But I did get rid of all of ADC noise. I borrowed an FFT library (JTransforms) and wrote a quicky high-pass filter into my software. Now I can finally fine tune the positioning algorithm. The second derivative tests should be reliable now. The best part of this type of filter is simply that none of my band shapes are shifted, and the amplitudes remains nearly the same. All it does is rips high frequencies out of the spectra.You'll notice that the units on the Y-axis after the inverse transform are scaled on the order of 100,000. Who cares? Absorbance units are arbitrary anyways.

Check these signals out,

FFT closeup.png - 14kB FFT.png - 16kB

[Edited on 24-5-2015 by smaerd]

By doing this I was able to get my motor positioning resolution down to a factor of 10 with an unoptimized algorithm. If I can tune this one more time I can see atleast a factor of 5-10 more resolution then my soft-ware will be complete aside from frilly things.

[Edited on 24-5-2015 by smaerd]

m1tanker78 - 24-5-2015 at 09:13

I just started reading this thread but couldn't resist jumping ahead to the last page. :D

Man, I can hear the gears of improvement (not the motor drive gear) turning all the way across the internet ocean. Seeing your graphs, it looks like you achieved smooth, constant rotation of the rotating polarizer. That's what I call a sine wave!

BTW, did you mean to say you implemented a low-pass filter or did I miss something?

smaerd - 24-5-2015 at 11:02

Oh gosh you're absolutely right m1tanker, yes I meant a low-pass filter not a high-pass filter. I used a "brick-wall" algorithm which basically goes FFT-> Remove frequencies outside of threshold(turn them to 0) ->inverse FFT . So the filter wasn't electronic it was soft-ware, because I speculated that the noise I was seeing was ADC noise. I deduced this by chucking the arduino ADC clock to 1MHz and noticing some distinct changes in the spectra/noise appearance. The brick wall is not as good as masking, but my data is essentially one sinuisoid and the rest being highfrequency noise so the brick wall is juuuust fine.

Before the FFT I was seeing 1-7* error in positioning the polarizer. Not good.

Now I'm just tuning the "peak finding" algorithm. After the FFT I was getting lots of 0.081* errors (off by ~3 motor encoder counts), then I saw some more 0.50* errors for the positioning (made a few too many assumptions in my routine). So I gotta come up with something more reliable but so far I can safely say I am at 1* accuracy at least. My goal was a consistent error of ~0.05* (1-2 counts off from predicting the peak). If I can hit that then maybe I'll try running in quadrature and getting a slightly larger gear and then I could hit 0.01*.

Also once I swap out the laser I should no longer be seeing the clipping at the bottom of the sine waves (fingers crossed).

Thanks for dropping by :).

aga - 24-5-2015 at 11:55

You've gone and done it now smaerd.

You made me build a polarimeter.



diagram.jpg - 197kBlaser.JPG - 163kBfront.JPG - 198kBmirror.JPG - 176kB

smaerd - 24-5-2015 at 12:20

Thats' amazing you did that so quickly!

What kind of detector are you using?

How are your results looking?

I think I'm stuck for the day :/. Having a hard time doing all this data handling. I'm beginning to suspect that my slightly irregular sine wave is becoming my undoing. Or I've made a blunder somewere. My second derivative analysis is less accurate then my height seeking algorithm. Which to me makes little sense.

[Edited on 24-5-2015 by smaerd]

aga - 24-5-2015 at 12:31

Decided to try building one this afternoon.

Having a stock of metals, other stuff and many tools in the shed helps enormously when experimenting with stuff - takes a lot less time.

No results yet, just some random numbers.

Got a basic CdS cell as the detector (came with the arduino kit) and only have half a polarised disc. Very short on polarised film here at the mo.

Many bungles and bodges to get this far - the slot in the cross bar at the top is there simply because i measured it wrong and there wasn't enough room for the rotating polarising disc.

Get yourself some of that sticky-backed foam strip that is used for sealing doors/windows against draughts, as i'm especially pleased with the way the test tube goes in and out with the greatest of ease.

smaerd - 24-5-2015 at 12:38

It looks like a really great start aga. If you want my amplifcation stage circuit diagram or anything else let me know :).

Yea 90% of my battle has been just setting up the physical components, so the rest should be smooth sailing for you. I really like how you used a mirror to get things into place I didn't think about that, but its a lot easier to adjust a mirror then move a mount on wood.

aga - 24-5-2015 at 12:51

The mechanical components may not be perfectly linear, so you should remember that when looking at irregularities in your data.

It may well be that your motor goes faster at some point in it's rotation and slower at another, which would also cause a non-sine trace.

Keep on battling !

You're almost there !

Attachment: My Movie-1.m4v (556kB)
This file has been downloaded 718 times

aga - 24-5-2015 at 12:56

LOL.

If you loop that video and imagine it's dispensing just 10mls of beer, the timing is spot on !

[Edited on 24-5-2015 by aga]

smaerd - 24-5-2015 at 13:34

Aga whether the motor is going faster or not should not effect the encoder timed photodiode measurement. Technically I could remove power to the motor and spin the encoder by hand and still arrive at the same measurements as long as I went in only one direction. It's also specific to the left hand side of the rising wave, whereas before I did an alignment it was on the right hand side. That's why I keep thinking it's the alignment. Like say one of my polarizers is off at by 5* then the transmittance through the polarizer is uneven, which leads to slightly more or slightly less absorbance based on the period of the polarizers rotation. I could likely fourrier transform the function to make it more symmetric but I'd really rather not mess with that, that's when data processing becomes data manipulation. Edit - I could probably derive an equation to fix it, but I'd rather not do that either.

I think I have an idea to fix this thing. I know the length the period of oscillation is supposed to be. So I can fix that as a value. Then find the two optimum locations (one on each band) either by 2nd derivative or peak height. Then bring the two optimum locations closer together based on which location change leads to the smallest change(in either peak height or second derivative) until they match what the period should be.

lol that is a nice video. I like the clicky sample holder. Mine isn't even fixed to anything yet. I just slide it infront of the beam when I want to measure a sample.

[Edited on 24-5-2015 by smaerd]

aga - 24-5-2015 at 13:46

Sounds like you're into all sorts of complicated maths to solve a Timing problem, and using readings derived form a rotating polarised filter.

Only 180* of the data will be relevant (?) so why not just stick a bit of tape on the rotating disc and use total blackout as your index to see where the motor is at ?

m1tanker78 - 24-5-2015 at 14:59

Quote: Originally posted by smaerd  

Also once I swap out the laser I should no longer be seeing the clipping at the bottom of the sine waves (fingers crossed).


Sorry smeard, I thought the graph offset was off and my brain sort of auto-completed the sine wave. I don't want to be the guy that asks a thousand questions that have already been answered or covered upthread so I'll refrain until I get through it. ;)

The important thing is that aside from tweaking, you have the hardware and logic throwing raw data at your computer. From there, it's [almost] all math!

OK, one quick question.. how do you account for the source polarization when you switch to a laser source?

smaerd - 24-5-2015 at 15:52

@Aga it's not exactly a timing problem. its an orientation problem. One you might face as well. Even if you do know where a piece of black tape is, if your waveform is nonuniform like mine is, how do you tell the peak of the measurement waveform to get the phase shift? In my case it's a bit more of a concern because I have my lower voltage inputs being clipped (black tape or clipped signal). Black tape won't solve this for me. I'm using two peaks as metaphorical black tape.

@m1tanker78, that's something I didn't consider :/. I know some lasers are polarized some aren't, some are randomly polarized etc. Now that you are bringing this to my attention which was a big over-sight on my part, I'm a little worried. Worst comes to worst I will switch to a different light source I guess. I'll have to sit down and think about how that might be effecting my results.


I think I've honed in on the source of error though. I think I'm missing some encoder counts while the motor is drifting. With the way I have the mathematics set up now, there are few other explanaitions (I hope).

m1tanker78 - 24-5-2015 at 16:23

Most if not all diode lasers emit highly polarized light (maybe green is an exception, IDK). Assuming I'm not misunderstanding the operating principle of a polarimeter, one possible solution for you would be to swap the source and detector placement. You'd avoid having to massacre the drive mechanism and could keep the stationary polarizer in place without issue. In fact, you could use either the laser rotational position and/or stationary polarizer rotational position to dial back the intensity if the source overloads the detector/amplifier.

If you want to switch back to a non-polarized light source, you just swap them back to the way you have it now.

aga - 25-5-2015 at 02:42

It was a surprise to see so little variation on the detector !

I had assumed that the laser would saturate the detector, so chose a pretty insensitive one.

Out of a range of 1024 points, i get a variation of just 10 !
Time to try a new detector & op-amps i guess.

Also need to replace a screw, as one 'dip' is the screw blocking the laser ...

Upping the amplification in software gives these results :-


firsttrace1.JPG - 181kBfirsttrace2.JPG - 161kB

smaerd - 25-5-2015 at 08:23

Nice work there Aga! I can see a sinuisoid emerging from there. I think some of your weird band shape might have to do with the way the polarizing element is rotated.

Yea also most solar cells don't have a linear response for illumination vs voltage right? So you'll probably need either a massive resistor or a TIA amplification stage like I did.


---
Also, on my front, I made some huge progress. I'm getting my reproducibility for motor positioning to be between 0.027-0.081*. So I have successfully nailed it down to ~+/-0.1*. How did I do it?

Well I examined the frequency domain near 0 Hz. I noticed I had a big peak at nearly 0 (slightly off), a smaller one (good makes a wave form), then I had a little funky ripple which was actually assymetric with the negative portion of the domain(not shown due to the half FFT transform I'm using here, but in the full FFT it's there).
Yucky.png - 32kB

So what did I do? Trimmed off the assymetric wave (the portion highlighted in blue) form via my low pass filter. What's the result? I'm now commonly off by 1 encoder pulse (which I can account for) sometimes slightly more or slightly less. Now I haven't done a sinuisoidal regression, but I doubt wave forms get much better then that with a 10bit ADC. So why the huge increase in reproducibility and precision/accuracy, well, my algorithms can finally work on the nice data, the sole problem was the nonideality data (I had to rule out everything else).

No more clipping! I believe this band is lower in frequency as it represents either laser polarization error, or imperfect alignment(maybe both).

wonderful.png - 52kB

It sort of begs the question, is it okay to do this type of data modification. I thought about it all morning because last night I stated it would be data manipulation. Here's the thing, I'm not changing the frequencies of interest in the slightest bit (well in the 11th or 12th digit yes but that is beyond the resolution of the instrument). I am simply removing a constant interferance wave-form and noise from the frequency of interest. It turns out, go figure, that my data is a clean sinuisoid after that, no surprise.

It feels good to successfully surpass a 500$ instrument :). Now it's just a matter of fine tuning a few more things.

[Edited on 25-5-2015 by smaerd]

Attachment: So Clean -20150525_121733.csv (362kB)
This file has been downloaded 816 times

[Edited on 25-5-2015 by smaerd]

morganbw - 25-5-2015 at 08:41

Quote: Originally posted by smaerd  




It sort of begs the question, is it okay to do this type of data modification. I thought about it all morning because last night I stated it would be data manipulation. Here's the thing, I'm not changing the frequencies of interest in the slightest bit (well in the 11th or 12th digit yes but that is beyond the resolution of the instrument). I am simply removing a constant interferance wave-form and noise from the frequency of interest. It turns out, go figure, that my data is a clean sinuisoid after that, no surprise.

It feels good to successfully surpass a 500$ instrument :). Now it's just a matter of fine tuning a few more things.

[Edited on 25-5-2015 by smaerd]


With a bit of understanding, which it seems you have, it is very okay.
A long time ago I hated it, thought just show me the raw data, but I mellowed
and filtering out the crap is a good thing.
I realized after years that I did not hate it, but I trusted my data transforms more that my coworkers.

You have done well.

smaerd - 25-5-2015 at 09:18

Thanks morganbw. I still get irked by smoothing data and things like that. But it's not a savitsky golay, or a rolling average or anything. I actually did a poster session where I felt inclined to say that some FT-IR data was not conclusive because I had to smooth it using a SG. When really, it was likely fine.

The design could use some improvements to make run's shorter(PID control via H-Bridge) in duration or this or that, but I'm pleased. Once I fine tune this a bit, and make a second light source, I think I'll do some quicky demonstrations then conclude this project. I decided I don't need to tune it for 0.01*. I'll leave that for someone else to do who can find a slightly bigger gear and feels like setting up the runs in encoder quadrature. It already functions for about everything that I will ever need it for. Most importantly it's inspired someone else to start making one, and hopefully a few more people once I lay everything out.

aga - 25-5-2015 at 10:13

Wonderful !

Sine doesn't get much smoother that that one.

Great job smaerd.

Edit :

Mine won't get anywhere near sine while it has just a bit less than half of the polarising film required !

[Edited on 25-5-2015 by aga]

smaerd - 25-5-2015 at 18:03

Hmm the 20% sucrose solution I made last week ran up about ~0.0* so I made a fresh 5% solution and ~0.0*.

I'm really not sure what's going on. I was pretty sure that I was seeing polarization before, but it was before I had my motor drive routine down. Guess we'll see what happens with the 532nm light source :/.

Unfortunately the one laser pointer polarimeter states that the specific rotation at 635nm is 56.3*. So, I should be seeing an observed rotation of about 11.3* at 20g/mL sucrose solution (maybe slightly less). :/ I'm wondering if my FFT filter is somehow eating this result?

m1tanker - I thought about it though, I don't think that the light source being polarized would ruin anything. All it would do is lose some intensity. The polarimeter would be measuring the polarization from that polarizer. The initial intensity of the light source isn't a concern. Unless I am underthinking something. If I am please let me know.
Actually the few laser pointer based polarimeters I've seen in literature all feature a polarizer right after the light source.

Now I am really stumped though.

[Edited on 26-5-2015 by smaerd]

aga - 25-5-2015 at 23:59

I've tried putting a bit of polarising film in front of the green laser pointers i have.

Rotating the beam or film makes no change to the laser intensity, so they (at least these) cannot be polarised.

smaerd - 26-5-2015 at 12:24

So I changed the batteries going to my laser and it changed my FFT filter conditions (greater amplitude signal due to more power). I think I'm gonna need to get this puppy on a stable power supply.

Fortunately and unfortunately this forced me to revisit my peak finding algorithm. I changed some things and made the code more understandable but also realized. This algorithm is inconsistant again since the filter settings changed. The distance between two "peak" locations can vary as much as 1*. So there are two major problems for the project.

1) Consistent peak detection of real world data. This comes first because it tells me
2) Why isn't my polarimeter detecting changes in observed rotation? Or is it detecting them but problem #1 is hiding them.

I tried finding the phase shift of the signals directly from the fourier data, but it appears this FFT has decomposed the sinuisoid into two more more harmonics. So that seems like a dead-end.

aga - 26-5-2015 at 12:38

I'm still a little confused as to how you detect the position of the free-running rotating motor that drives your rotating polariser.

If you're detecting Peaks, well, those will change if the polarisation gets shifted by the sample nuh ?

Edit:

Just remembered : for FFT you need a sample rate of 2x (the Nyqist number) of the frequency of the waveform you wish to sample.

That may be a factor in your FFT decomposing the waveform.

[Edited on 26-5-2015 by aga]

smaerd - 26-5-2015 at 14:40

Aga I have two routines.

Orientation - This runs the motor 360* and reads all the values. My soft-ware finds the two peaks in the data, gets the period of the rotation then transmits to the microcontroller where the next projected minimum light value should be. Then I tell my MC to measure.

Measure - The mc rotates freely until it reaches the projected light minimum. The photodiode readings then begin until 180* of rotation has occurred(was previously 360 and before that was 180). Then the soft-ware says "Hey I found the experimental maximum at some encoder count. The projected light maximum from the orientation routine was at some value." Then it calculates the phase shift.


Damn the nyquist number. I read a little about that. I'll have to see if it's even possible for me to do a phase angle determination then. I'm not really sure I understand the concept just yet. Maybe by tomarrow, unless you can help explain it a little bit or direct me somewere.

edit - so say I take 6000 measurements for one period of the wave form. Thats like 3000x times satisfying the nyquist criteria right? Or does it have to be 2x times the crazy noise that was in the sample prior to filtering?

[Edited on 26-5-2015 by smaerd]

m1tanker78 - 26-5-2015 at 15:26

smeard, in contrast to what aga observed with a green laser pointer, all the red laser pointers and diodes I've experimented with have emitted highly plane-polarized light. I could take a polarizing film and almost completely block the laser beam at 90 and 270* rotation. Virtually all passes at 0 and 180. If you intend to use a non-polarized laser then it's moot. Otherwise, I believe you'd have to rethink your current design. If you only have 1 stationary and 1 rotating polarizing film, I think you could get away with swapping source and sensor like I mentioned before.

LASER -> [OPTIONAL STATIONARY POL FILM] -> SAMPLE -> ROTATING POL -> SENSOR

If the laser light 'saturates' your sensor -- that is, takes it outside the linear region, you can tweak the stationary pol and/or laser and take another background scan.

I haven't tried this, I'm just thinking out loud here.

[edit]

The higher your oversampling rate, the better data integrity you'll have. You can filter out a huge chunk of high freq quantization noise or 'crazy' noise you observed before with a simple low-pass.

[Edited on 5-26-2015 by m1tanker78]

smaerd - 26-5-2015 at 16:15

Thanks for the advice m1tanker. Maybe that's why I'm not seeing any polarization? I'm going to test out the 532nm laser pointer and see if it's polarized. if it is I'll swap my source and detector around. I'm giving this project a break for a day or two so I can work on a couple other projects. Kinda burnt myself out reading academic articles on peak finding algorithms when the truth is, I just need a stable power supply going to my light source and all will be good again.

smaerd - 31-5-2015 at 14:22

So I did some work on this today. First things first. Thank you M1Tanker. You were right the red laser pointer does have a significant source polarization. I removed a polarizing film from the optical path and swapped my detector for the source as suggested. Now I have clean sinuisoids without filtering.

So I added a constant voltage power supply for the laser pointer, so glad I did, now my FFT filter has a constant setting!

no FFT minus a polarizer.png - 15kB

Anyways, now I took some results as the instrument stood without fine tuning the soft-ware for the new alignment. It's pretty buggy still, but now I have eliminated two or three huge issues. So again thank your M1Tanker. I can see polarization!

INIT w fft.png - 13kB

Here are the results:
Without a sample here are the observed rotations: 0.52*, -0.60*,0.22*,-0.27*(Average: 0.033, STDEV = 0.5)
With a 20% sucrose solution: : +7.83*, +9.67*, +9.36*, +8.08*, (Average: 8.74, STDEV = 0.9)

The mean value gives me a specific rotation of 43.7 (+/-4.5)*, which is reasonable.

The instrument is obviously not consistent but now that I have a consistent sinuisoid I can do curve fitting rather then my calculus based approaches to finding peak locations.

As suspected the variance of the orientation is 2X that of measurements, because the routine is run twice to take a measurement. So it is my algorithm that is off.

[Edited on 31-5-2015 by smaerd]

Edit - also I got the green laser pointer but when I shorted the switch on the circuit and subjected it to the 3.3V source. I'd subjectively say it's 100-200 times brighter then the red laser, but knowing the human eye is ~5-10x more sensitive to green then red, this is probably a 50mW laser. It too is polarized. It is bright enough that I would be concerned for my eyes if it were to be shined there. I'm afraid to even try it on my amplification circuit, it would likely saturate it and I'd need to use a 50kOhm trimmer pot on the second stage, too finicky for my blood knowing how the ideal FFT filter is.

[Edited on 31-5-2015 by smaerd]

aga - 31-5-2015 at 14:45

Woohoo !

Nice one smaerd.

m1tanker78 - 1-6-2015 at 18:20

Quote: Originally posted by smaerd  
So I did some work on this today. First things first. Thank you M1Tanker. You were right the red laser pointer does have a significant source polarization. I removed a polarizing film from the optical path and swapped my detector for the source as suggested. Now I have clean sinuisoids without filtering.

So I added a constant voltage power supply for the laser pointer, so glad I did, now my FFT filter has a constant setting!



Anyways, now I took some results as the instrument stood without fine tuning the soft-ware for the new alignment. It's pretty buggy still, but now I have eliminated two or three huge issues. So again thank your M1Tanker. I can see polarization!



Here are the results:
Without a sample here are the observed rotations: 0.52*, -0.60*,0.22*,-0.27*(Average: 0.033, STDEV = 0.5)
With a 20% sucrose solution: : +7.83*, +9.67*, +9.36*, +8.08*, (Average: 8.74, STDEV = 0.9)

The mean value gives me a specific rotation of 43.7 (+/-4.5)*, which is reasonable.

The instrument is obviously not consistent but now that I have a consistent sinuisoid I can do curve fitting rather then my calculus based approaches to finding peak locations.

As suspected the variance of the orientation is 2X that of measurements, because the routine is run twice to take a measurement. So it is my algorithm that is off.

[Edited on 31-5-2015 by smaerd]

Edit - also I got the green laser pointer but when I shorted the switch on the circuit and subjected it to the 3.3V source. I'd subjectively say it's 100-200 times brighter then the red laser, but knowing the human eye is ~5-10x more sensitive to green then red, this is probably a 50mW laser. It too is polarized. It is bright enough that I would be concerned for my eyes if it were to be shined there. I'm afraid to even try it on my amplification circuit, it would likely saturate it and I'd need to use a 50kOhm trimmer pot on the second stage, too finicky for my blood knowing how the ideal FFT filter is.

[Edited on 31-5-2015 by smaerd]


Looking good smeard! Can you elaborate a little on the sampling parameters? I read the thread in bits and pieces so forgive me if you already mentioned it.

Specifically:

1. How many samples per full polarizer rotation? (Ballpark, I know it depends on motor RPM). Are we talking dozens, hundreds, thousands??

2. Are you writing the sampled data to a file or processing it on the fly?

3. If writing to file, in what format? Not file format, data format.. Complex real? Absolute floats, signed, unsigned, etc. Also, are you 'packing' or compressing the data before sending over serial?

If the sinusoid amplitude was centered around zero, finding the peaks and, more importantly, phase shift would be trivial with a zero-crossing algorithm. I think this is where your peak-finding headaches originate. Is that about right or am I missing a piece of the puzzle? Directly modifying the offset would probably introduce all kinds of bugs. I'll give this some thought and see if I can come up with anything.

Oh and to the green laser intensity.... can't do much about eye safety without goggles and/or a reliable enclosure but to the sensor saturating... couldn't you just adjust the stationary pol with respect to the laser to trim down the intensity, take another background scan, proceed with sample scan?

You're running a Linux box, right?

smaerd - 1-6-2015 at 19:07

Actually I don't think I ever elaborated on this piece of information so these are great questions.

1. For a complete polarizer rotation there are 13,132 measurements (weird number I know, but it was experimentally found). So 360*/13132 = 0.027* per encoder count.I can actually double the encoder count number by running in quadrature (but it isn't worth it right now), or by expanding the gear size/tooth count.

2. Here's how the data is transferred/dealt with currently.

Motor encoder detects position change -> photodiode take a measurement (with-in 20μs) -> Data is sent over USB to soft-ware -> software stores information until analysis is completed.
->Soft-ware then FFT filters -> Calculates maxima locations -> Phase shift -> interpolates the next minima to rotate too -> etc

Scans can take from 20s-120s depending on how fast I PWM the motor. I'm preferring 40s scans just for 'safety' even though I had no difference in results with 30s scans.

3. The transferred value is based on a 1024 count (no decimals 0-1023) which the ADC reads as a voltage (0-5V). So all real values. There is no packing the value is recorded as an integer(2bytes), individual bytes are chucked sequentially down the serial pipe.

I'm not manipulating the data on the fly, I could by creating another thread for the application, but I really don't like multi-threaded applications for stability purposes.

Sinuisoid amplitude - I had never heard of a zero crossing algorithm before. Funnily that was one approach I considered, monitor the first derivative for greatest and smallest changes. That was a portion of the algorithm I was using which gave me 0-3 encoder count errors (0-0.08* off).

I think the best method would be to go back to a harmonic regression algorithm, because the 'artificial' sinuisoid will have an absolute maximum rather then an imperfect plateau. Then again, I'm open to suggestions :).

Green laser - That sounds like a good idea, but remember I removed the stationary polarizer :P. It seemed like when I had the stationary polarizer and a polarized light source I was not able to get polarization measurements of the sample cell. It also gave me a 'biased'/off-set waveform for a result. I found that counter intuitive but I am going to accept it for now as that was the only change of the instrument/soft-ware.

With batteries the source was not as ridiculously intense, but I think the intensity is limited by current not voltage (my supply can offer 1A). I didn't analyze the driver circuit too much other then how to short the switch(which was trickier then one might assume). I could try it once I stabilize the algorithm but for now I think I am happy with the Red laser, even though the green laser may give an extra significant decimal for some samples. I could also implement a filter to reduce it's intensity, which funnily enough sounds easier then current regulating the circuit.

Linux -
Yes I am running a linux operating system :). My USB ports are ACM0-5, but the soft-ware includes COM and whatever the hell Mac's use.

[Edited on 2-6-2015 by smaerd]

smaerd - 3-6-2015 at 12:06

The harmonic regression was a bust. At it's optimized form(it was quite slow) it was capable of giving me 0.09-0.90* error. I think I'm going to revisit the FFT phase-shift method because it is horrendously fast compared to a residual square error calculation. Test it's accuracy.

If not, I'm going to have to revisit the convoluted algorithm I was using before which required a lot of tuning.

aga - 3-6-2015 at 12:53

Why do you need to FFT a series of measurements of the observed polarity (by intensity) ?

Am i missing something enormously obvious ?

smaerd - 3-6-2015 at 14:15

In the frequency domain phase angle can be very easily extrapolated by the arctangent of the imaginary component over the real component.

I wasn't able to use that before because my additional polarizer gave me an improper band shape and the FFT decomposed the sinuisoid into two or more harmonic functions.

This isn't about intensity. I need to figure out how a sample's phase shift differs from a blank. Otherwise no measurement can be made.

This is one of those problems that is incredibly easy on paper, or in your mind, but when applied to real results is becoming a lot more difficult then anything else in the project.

I'm really not sure where a lot of these inconsistencies arise from with my previous approaches but its definitely frustrating.

Edit -FFT phase angle is a bust too. It's giving me 0.1-1.5* errors. Bummer.
Think I might try gaussian curve fitting next.

[Edited on 3-6-2015 by smaerd]

m1tanker78 - 3-6-2015 at 16:47

Smeard, I'm confused as to how you derive the imaginary ( i or j ) component of the signal when as far as I can tell, you don't have complex samples to begin with. Are you applying a Hilbert transform or something?

Again, if your amplitude measurements were relative to zero, it'd be an enormous shoe in for measuring the zero-crossing points and hence, your phase shift. The accuracy would be limited only by the usual factors like sample rate, sample depth, mechanical jitter, electrical noise, etc... Rather than trying to measure the peaks where you have an ocean of similar-valued amplitudes, you'd be looking at a sharp transition through the zero 'point'. The trick to knowing if it's a positive or negative-going zero crossing is to compare the current sample with the previous one(s). The zero point doesn't necessarily have to be zero-valued. My memory fails me ATM with the terminology, sorry.

Anyway, no brain-busting calculus or trig needed to find zero crossings and it's incredibly easy on resources. ;)

Quote:
(aga: Why do you need to FFT a series of measurements of the observed polarity (by intensity) ?

Am i missing something enormously obvious ?


I'm with aga here... As I understand, your samples are already ordered in the time domain which is good for finding the phase offset. I don't see a good use for applying a FT when your signals have the same frequency, no? If you violate the Nyquist rules, you'll have aliasing issues to contend with. Keep that in mind when designing your filters and functions.

[Edited on 6-4-2015 by m1tanker78]

smaerd - 3-6-2015 at 17:17

@m1tanker - The fourier transform creates imaginary components in things called 'bins'. So say I put in an array with 10 elements in to the FFT. The FFT will spit out a 20 element array with alternating Real, 'Complex' values. It's just the nature of the beast. Each bin corresponds to one 'item' in the frequency domain.

Well M1, I don't have a definite 0 point. I could artificially create one though which it sounds like you are suggesting. The amplitude remains pretty constant and I've already got an algorithm to find that 'offset' value. I see what you're saying though. Basically get the 'slope' of points and traverse the line. If the point/line intersects the "zero" line then mark its position. I see I see, because there is only one such point where that will happen(well two for a given positive peak). That's really clever. I'll experiment with that tomorrow.

smaerd - 4-6-2015 at 11:07

Just tried the zero crossing algorithm. It's about the same as the others. There's some other source of error here. I'm not 100% where it is just yet, but I am about to do some digging...

I'm starting to wonder if the arduino is gargling up the motor positioning routine. I have no idea how, but I am truly at a loss. I'm noticing that my positioning algorithm is off, probably by a degree or so (with variance). I don't believe it was doing this before.

Thinking of switching to a raspberry pi.

[Edited on 4-6-2015 by smaerd]

m1tanker78 - 4-6-2015 at 19:11

I've never used an arduino so I can't comment on the internal hardware workings. As a matter of isolating the problem, why don't you replace your encoder with a single 'tick' connected to a direct interrupt pin (??) and have the motor free-running on a stable-ish supply (not PWM) at a reasonable rate. Use a dedicated hardware counter (??) to cycle the ADC at a reasonable interval. Observe reference crossing or peak locations if that works better for you and use the tick location as a global absolute reference. Sampling at least 2 'tick' intervals continuously will guarantee that you have 2+ positive-going and negative-going reference crossings (or 2+ pos/neg peaks if you prefer).

If the readings are off by ~1 degree, that translates to ~20 counts per half rotation (or 40 counts per full rotation) that are being missed, right?


smaerd - 4-6-2015 at 20:19

m1tanker - I decided that the next phase is going from the ground up in the arduino and debugging. It's a tricky environment to navigate because it is not 'low-level' so processes do things that are not explicit. Example: I've discovered the serial functions are a 'threaded'/interrupt process, so it can interrupt other operations at indiscernible times. So I am switching to an external SPI RAM chip (23LC1024) which supports 5V logic levels. Digital write operations only take about 10 nSec (using low level commands) and do not poll back or hault or any nonsense. I estimate I'll be storing data to transfer later ~100x faster then calling serial.

Actually what you suggest is interesting m1tanker. I had to abandon 'interrupts' because of the serial writing process, instead I was polling the digital pins in a loop. So once I switch to external ram I may be able to get away with using digital write using low level commands in an interrupt (IDEAL). Without that I am likely missing encoder counts, or other things.

I am currently over-clocking the ADC in a reproducible range so I can at least eliminate that. The arduino platform does not utilize it's full or even quarter potential. Even though the documentation even states it can be exceeded significantly without a noteworthy loss of resolution. Peculiar...

Your math checks out. 20-40 counts missing depending on the mood. I've discerned that I cannot reproduce a rotation. Meaning I rotate once, create a graph. Then tell the motor to rotate another 180* (accounting for the motor drift) and the second graph's phase shift is slightly off. It looks like 1-2* but hard/impossible to measure in my current set up. So I am starting to look back and think, maybe a lot of these algorithms were working, but the basis for the microcontroller has been off the entire time.

So, it's kind of a trial by fire time to get reproducibility there, but once that's done, I should have a bank of algorithms to pick and choose from to complete the rest of the project without any serious issues. Using stepper motor would have been so much easier, but lacks the really fine positioning that I want.

I'm going to take your advice for debugging after I try 2-3 of my initial ideas. Getting the motor off PWM could only help.

aga - 5-6-2015 at 07:55

Stepper motor resolution can be magnified greatly by the use of simple gearing, and are pretty much spot on if you always rotate in the same direction.

That ensures that the gears are always well meshed, and you don't have to worry about any 'play'.

Edit:

Some more polarised film arrived today, so i'll fit my rig up with a full circle of film and see what happens.

[Edited on 5-6-2015 by aga]

smaerd - 5-6-2015 at 09:32

For sure aga I am just limited by gears. I have a 96 tooth object gear and a 16 tooth drive gear, that's it. So 1.7 degree step wouldn't cut it for me. Could get me down to ~0.3* resolution though which isn't bad at all. Well with half-steps that 0.15* which is pretty good. If all else fails, I'll go that route, but I really think I can hone this in.

I'm excited to see your results.

Edit - I think I've found where the error is. It seems to be in counting the encoder counts for the drift of the motor. I am scheming something up...

[Edited on 5-6-2015 by smaerd]

aga - 5-6-2015 at 11:41

New film fitted, so now there's an actual disc of un-scratched film, and a static piece as well.

The results with no test tube in place are a bit random, due (i think) to the direct laser light saturating everything.

With an empty test tube i now get this on the arduino's TFT shield :-

Sine.JPG - 193kB

Edit:

I initially got 4 peaks, then realised that only 180* rotation really counts.

[Edited on 5-6-2015 by aga]

aga - 5-6-2015 at 12:54

it should be said that the graph is a plot of just 64 samples over the 180* rotation with the points interpolated.

smaerd - 5-6-2015 at 12:57

aga you should only be getting 1 peak for 180* of rotation.

Looks good though, increase that resolution and smooth it out! Not sure how you got a negative value though.

aga - 5-6-2015 at 13:03

The graphing routines are pretty crude, so don't rely on them too much !

I just wanted a graph on the TFT shield so did it quick and dirty.

Decreasing the steps/sample will probably help.

Edit :

1 Peak ! Of course, if you start from the position where the light is fully blocked (blush)



[Edited on 5-6-2015 by aga]

[Edited on 6-6-2015 by aga]

aga - 6-6-2015 at 04:44

Been kicking this around a bit today, and came across a couple of references that seem to work, and easily (maths isn't my strong point).
http://stackoverflow.com/questions/26714410/partial-sine-dat...

The interesting bit starts with :-

float cog = 0f;

Using that method on a data set after taking a moving average seems to work well for this application, although i always end up with the calculated peak being x10, and can't see why.

Attachment: calcs1.xlsx (15kB)
This file has been downloaded 395 times

edit:

had to remove the code segment as the board html all goes potty.

[Edited on 6-6-2015 by aga]

aga - 6-6-2015 at 12:08

Nope.

The moving average works, but the other 'cog' thing doesn't seem to.

Edit :

any chance of some assistance smaerd ?

[Edited on 6-6-2015 by aga]

smaerd - 6-6-2015 at 15:19

You're averaging looks pretty good.

What do you mean by moving cog? Can you explain with a bit more detail. I'll be happy to help if I can.

aga - 6-6-2015 at 22:36

Moving average smooths the data OK.

Calculating the best fit sine and then the peak is boggling the mind.

The 'cog' thing doesn't work - the idea is to regard it as a 'centre of gravity' task (ref: stackoverflow link above).

Edit:

Hold on. At 1024 steps per 180*, that's an accuracy of 0.176*

Isn't that close enough for an amateur built instrument ?

[Edited on 7-6-2015 by aga]

smaerd - 7-6-2015 at 06:33

Yea aga if that's what you want then thats good enough for general purposes :). I just want at most 0.10* or ideally 0.05*.

Back to your center of gravity thing. I think that could work. Assume your sine function follows the general form of a sine function(Amplitude * Sin(inside terms) + Amplitude). What it requires is that there is only 1 peak or location above the offset or the + amplitude term. So you must carefully select half of the phase(90*) of the data in that way. Other-wise you're likely going to be finding the point of inflection between the peak and the valley.

I tried going through your excel sheet but I'm a little confused by it. I see some minor errors in the D6 & D7 cells (not the right formula?) and in the G7-G34 cells (no dividing by ten there?). Also why divide by ten, unless that's the moving average script inwhich case ignore this comment.

One way to find such a value would be to use your smoothed function. Find the set of points that are greater then the + amplitude term. Then implement the CoG algorithm there. I could be wrong but I think in this case you might have to add a subtraction term in the for next loop to account for any offset of those values. IE: if your peaks start at say 100 counts you might have to subtract 100 from the I * term so it would be (I-100) * samples. Also this script will not work if your peak shape is split meaning you have half a sine peak then the valley then the other half of the sine peak.

Why not try the zero crossing algorithm, it's really really easy! Here's the simple zero cross I wrote

Quote:

//First lets try to find the first UPWARDS zero crossing value
//Then use that to associate the phase of the data/interpolate a minima
public void findRisingZeroCross(double amplitude, int motorDrift){
int dataSize = recievedData.size();//store this to save some time
double tmpVal = 0.0, lstVal = (double) recievedData.get(0),
val = 0.0, one = 0.0, two = 0.0;
int zero = -1;
int i = 0, nullV = 0;
while(zero == -1){
tmpVal = (double) recievedData.get(i);
if(tmpVal > 100){
if(tmpVal > lstVal){//We are going upwards
//Did we JUST cross a threshold travelling upwards
if(tmpVal >= offset+amplitude && lstVal < offset+amplitude){
zero = i;
}
}
lstVal = tmpVal;
}
i++;
if(i==dataSize-1){zero = 10;System.out.println("No zero found");}
}
System.out.println("Zero: " + ((double)zero/(double)halfRotationPulseCount)*180.0);
}


aga - 7-6-2015 at 07:47

Cheers smaerd.

I can see now why the data needs to be smooth and have no lumps !

The complexity of the maths required to fit even a smoothed dataset to a sine function, and then derive a maxima, is quite some way over my head.

The last FFT function i tried gave a graph that looked like a squiggle with legs on, so i'll stick with the moving average function for now.
(i don't understand Fourier Transforms at all).

Trying 1024 sample points didn't work - the repeatability was way out (+/- 12*) presumably because of noise in the system.

smaerd - 7-6-2015 at 08:23

Aga, I think we're at roughly the same spot right now. If you need some code for finding peaks let me know. Personally the zero crossing algorithm is my new favorite because you don't even need a maximum you just need to find the same "spot" which in the algo I gave you is the left wall of the rising sine wave.

FFT - Basically this turns time domain values into frequency domain values. So say you have 1 sine wave and it's oscillating at 50 hertz. After a FFT you will see one peak at 50Hz rather then a wave form. So high frequency values/ripples in data are easily separated from low frequency(the signal we want).

The current issue is repeatability but you have a definite advantage right now. Your stepper is pretty much rock solid (chances of missing a step with a decent driver is incredibly low). My DC motor encoder approach might actually be impossible via arduino. I'm not 100% sure yet, but I'm edging towards 80%. I just spent ~2 hours trying to nail down this motor drift error and it's um awful. There are maybe 8-9 variables going on bouncing between hard-ware, firmware and soft-ware.

I have to take a break and wait until I get this SPI RAM and if I can't make it work with that then it's the encoder. If it's the encoder I'm just going to buy a stepper and a stepper driver board. I can't afford another $40 on a bad motor-encoder bundle. But at this point I've tried every logical permutation I can fathom, and cannot do any more testing without an oscilloscope.

[Edited on 7-6-2015 by smaerd]

aga - 7-6-2015 at 10:25

Thanks for the explanation of FFT - i get it now !

Oh i can put the stepper anywhere i want, just that after doing so, it detects the peak anywhere in a window of about 22* !

Pretty sure my 'design' is totally flawed at this point, with light getting in everywhere, the test tube skewing the laser out of alignment, unknown path length etc etc.

If you're on arduino, as i am, then you have to remember that it's got other interrupts going off in the background (time keeping for example) so you're not guaranteed to get your interrupt from the encoder wheel when you expect it, and could even have a few masked out without you knowing.

Offer still stands re a stepper motor & driver - just U2U the address.

 Pages:  1  2