Script for CSV processing
Mostra commenti meno recenti
Hi friends.
First of all I apologize for my bad English.
I tell you my problem. I was working with an osciloscope and I take around 500 measures (Voltage/Time) in CSV files. The signal is a pulse train with only the 1% of the period crossing the zero.I want to measure with matlab, for each csv, which is the value of x axis (time) for exactly 25 pulses of the whole train.
Doing this with cursors is a very hard work. I'm trying to build a Script. My main idea (because of the small time that the signal cross the zero) is to make a FOR loop, with a IF loop inside that, when Y axis have crossed the zero 25 times, the script catchs the value of the X axis in a new variable. This operation, with the bucle, for all the CSV files.
This is my idea, but Im new in Matlab and is costing me a lot.
Anyone can help me? Thank you very much.
Risposte (2)
dpb
il 23 Mar 2015
s=csvread('yourfile.csv'); % read the signal
ix=find([0 diff(s>0)==1,25); % locate first 25 zero crossings
The above works by turning the input signal into a 0/1 pulse train, then looks for the positive crossing locations (where the 0 turns to 1 is a +1 difference).
The ix index vector is the position in the original vector of those crossings, specifically it will be the index of the first positive location after the zero-crossing.
Antonio Jayena
il 23 Mar 2015
3 Commenti
dpb
il 23 Mar 2015
There is no r2 variable???
As well, there's no guarantee the data will be sampled at precisely zero so the test for ==0 may (or may not) ever actually be satisfied. Hence the reason for checking for the crossing instead.
While one could make something like htat work, why are you refusing to use the facilities of Matlab vectorization which is the whole point of using Matlab to begin with? ix above will be precisely your vector of crossings; if you only want the location of the 25th without the preceding 24 then it would be the last entry in the ix vector; find does have the option builtin to count the number found but not the nth only so one gets 25 and uses the one(s) of interest.
ix=ix(end); % save the 25th one only
Antonio Jayena
il 23 Mar 2015
dpb
il 23 Mar 2015
OK, I presumed a row vector in s; for a Nx2 array then for the voltage column it would be
ix=find([0; diff(s(:,1)>0)==1,25]);
again assuming the data array is s; obviously use whatever you use in your script.
For processing multiple files, you might look at the File Exchange function filefun that applies a function "automagically" to each function. It's at <Apply a function to files>
Categorie
Scopri di più su MATLAB in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!