PDA

View Full Version : MATLAB Filtering


1337Hendrix
03-01-2009, 04:45 PM
Alright, so I'm having quite the headache trying to figure out this simple filtering problem using MATLAB.

I'm not too familiar with MATLAB syntax or structure, so I'm having a much harder time writing my m-file than I would be in C++. :facepalm:

Anyways, so, I have a 1x2000x252 matrix of voltage readings, and a 1x2000 matrix of where they occurred in time.

I need to find all voltages greater than an inputted threshold, find where they occurred in time, and place them in a 2-D array with the first column being voltage and the second being time.

I linearly indexed the voltage values using the find command, but I'm not sure how to progress further, ie finding what the value was and finding where that occurred in time, then placing it in an array.

Any help??

Thanks!

1337Hendrix
03-01-2009, 06:23 PM
Alright, so I figured it out, but my code is very elementary and looks more like a C++ program...

threshold = input('Please enter the threshold voltage level: ');
voltage = EEG.data;
time = EEG.times;
latentvalue=latentcalc(voltage,time,threshold)


function latentvalue=latentcalc(voltage, time, threshold)

count=1; %initalizes counter%
for i=1:length(voltage(1,1,: )) %increments page%
for k=1:length(voltage(1,:,1)) %increments column%
if (voltage(1,k,i)>threshold)
latentvalue(count,1)=voltage(1,k,i); %assigns values 1st Col%
latentvalue(count,2)=time(1,k); %assigns values 2nd Col%
count=count+1; %increments counter%
end
end
end


Though I notice that for some reason the values I get are a few orders of magnitude smaller than I really want. Perhaps because the measurements are in microvolts are milliseconds.

So, any ideas about how I can make my code more MATLAB worthy?