How can I rewrite this code without cutting the data up into arrays?

1 visualización (últimos 30 días)
Lala0099
Lala0099 el 8 de Mzo. de 2019
Respondida: Star Strider el 8 de Mzo. de 2019
I have attached a photo, of my code. I am trying to filter the data, from an imorted file, but I cannot do it without cutting the data up into arrays.
I was thinking of doing it with for loops, but it did not work. The first code works, but it is very long and I need a code that can do it without me transforming everytihing several times.
T = transpose(table2array(drink00(:,1)));%this is to make the first coloumn into an array, for Time
R = transpose(table2array(drink00(:,3))); %this is to make the fourth coloumn into an arra for Roll
P = transpose(table2array(drink00(:,4))); %for pitch
Y = transpose(table2array(drink00(:,5)));%for yall
[d,c] = butter(3,0.2/60,'high'); %the cut off frequency is 0.2 Hz and the Sampling frequency is 120 Hz
dataOut_4 = filter(d,c,R);
dataOut_5 = filter(d,c,P);
dataOut_6 = filter(d,c,Y);
[b,a] = butter(3,20/60,'low');
dataOut_IV = transpose(filter(b,a,dataOut_4));
dataOut_V = transpose(filter(b,a,dataOut_5));
dataOut_VI = transpose(filter(b,a,dataOut_6));
Output = [dataOut_VI,dataOut_V,dataOut_VI,];
this is me trying to do it with for loops
filtered_output = [];
for i = 1:numel(drink00) % for each datasheet
for j = 1:size(drink00{i},2) % for each column in each datasheet
filtered_output(i,j) = rms(drink00{i}{:,j}) %for each datasheet, store rms value into a row vector
end
end
this is a code that I do not understand this code or how to do it.
Can someone help me, properly? I am very confused.
Can I make it as a function?

Respuestas (1)

Star Strider
Star Strider el 8 de Mzo. de 2019
The filtfilt function operates on arrays, and will operate on the first dimension greater than 1, as I mentioned in How to filter data of every coloumn in a dataset (link). You do not have to break them up into individual columns, although you may need to transpose your array so that filtfilt will operate on the dimension you want it to.
Use the table2array function once, then filter it, transposing it first, if necessary.
Also, you may find it easier to work with the lowpass (link) function, if you have R2018a or later.

Categorías

Más información sobre Single-Rate Filters en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by