How can I use FFT to get frequency of this chemical oscillator (BZ FKN reaction)?

1 visualizzazione (ultimi 30 giorni)
So, I filmed the reaction with my phone and wrote a script to pull the Red, Green and Blue color data from a couple pixels in each beaker as they stirred along with a time stamp in milliseconds.
Using this code I wrote for AutoHotkey:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance Force
A = 297
B = 462
C = 330
D = 454
StartTime := A_TickCount
SetTitleMatchMode, 2
ControlSend, , {space}, VLC media player
SetWinDelay, 2
SetBatchLines, -1
Loop
{
ElapsedTime := A_TickCount - StartTime
IfWinExist, 20160114_143257.mp4 - VLC media player
{
WinActivate
pixelgetcolor, vthiscolor, %A%, %B%, rgb
vblue := (vthiscolor & 0xFF)
vgreen := ((vthiscolor & 0xFF00) >> 8)
vred := ((vthiscolor & 0xFF0000) >> 16)
pixelgetcolor, vthiscolor2, %C%, %D%, rgb
vblue2 := (vthiscolor2 & 0xFF)
vgreen2 := ((vthiscolor2 & 0xFF00) >> 8)
vred2 := ((vthiscolor2 & 0xFF0000) >> 16)
}
IfWinExist, Pixel 1.txt - Notepad
{
WinActivate
}
sendinput %vred%, %vgreen%, %vblue%, %ElapsedTime%, {Space} {Enter}
IfWinExist, Pixel 2.txt - Notepad
{
WinActivate
}
sendinput %vred2%, %vgreen2%, %vblue2%, %ElapsedTime%, {Space} {Enter}
}
Esc::
SetTitleMatchMode, 2
ControlSend, , {space}, VLC media player
ExitApp
My script pulls and measures the time the pixels were pulled based on the tick counter of the PC which is time in ms since the PC is started. So it measures time elapsed with
(Start time) - (Ticks since started)
Each pixels rgb value can be r 0-255 g 0-255 and or b 0-255. I've decided to ignore green since the color oscillates between red and blue. So I've plotted r/(r+b) over time to get a %red value.
A picture of the data is attached.
The highest values are when the solution is the most red, and lowest are when the solution is blue. I want information about how often it cycles. The time between changing from red to blue. It's my understanding that this can be done with FFT. I can easily measure the time between cycles just by analyzing the data and getting the time stamps from when my red value is at minimums. However, I'm interested in how the FFT function works and how/if I can apply it to my work.
Here is what I've done/THINK I've done so far:
Import my data as a Nx2 Matrix
Rename my variable to "X" so I can continue using the above guide as a walkthrough.
Note that my Value is 30732 for the variable X, so I will be using the part of the code for an even length:
xdft = fft(X(:,2));
% sampling interval -- assuming equal sampling
DT = X(2,1)-X(1,1);
% sampling frequency
Fs = 1/DT;
DF = Fs/size(X,1);
freq = 0:DF:Fs/2;
xdft = xdft(1:length(xdft)/2+1);
plot(freq,abs(xdft))
Enter Code:
And :(
I've attached my excel sheet.
Thanks, Ryan

Risposta accettata

Star Strider
Star Strider il 21 Gen 2016
I cannot understand the file you posted. What is the time and what is the signal?
I used this code, so correct the time ‘t’ and signal ‘r’ references to your file if I have them wrong:
[d,s,r] = xlsread('Ryzx7 Run 4 FFT.xlsx');
t = d(:,3); % Time
r = d(:,4); % Signal
L = length(r);
Ts = mean(diff(t));
Fs = 1/Ts;
Fn = Fs/2;
Fr = fft(r)/L;
Fv = linspace(0, 1, fix(L/2)+1)*Fn;
Iv = 1:length(Fv);
figure(1)
loglog(Fv, abs(Fr(Iv)))
grid
axis([0 180 ylim])
xlabel('Frequency (Hz)')
ylabel('Amplitude')
  4 Commenti
Ryzx7
Ryzx7 il 21 Gen 2016
Star Strider, thank you so much for taking the time. I ended up with this as my output:
Had a little bit of a struggle with the xlsread, but with your code I was able to easily import my data into a Nx2 matrix and proceed from there. Really appreciate you taking the time to help me with this. Thank you.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Chemistry in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by