Iterate to filter signal in a parfor
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone
I am using MATLAB 2015 and I am using a student version with all toolboxes installed.
I have a third-dimensional order tensor containing the data coming from a thermographic measurement (in the form of pixel-pixel-time) and I want to apply a custom made low pass filter which I have created with the matlab filter designer. I want filter every signal (so the signal corresponding to every pixel in time) and I want to use a parfor.
In one .m code I am defining the following command:
test_hyper_cube = zeros(512,640,3000)
hyper_cube_filtered_lowpass = lowPassHyperCube(test_hyper_cube,LP); %% LP is a filter object
%% Then I define the following code in another external function that should process each signal from each pixel in time. The function receives 2 inputs: inputdata which is a 3rd order tensor and filterVar which is filter object
function [outputData] = lowPassHyperCube(inputData,filterVar)
outputData = [];
parfor i=1:size(inputData,1)
tempvar = [];
for j=1:size(inputData,2)
newvar = filter(filterVar,squeeze(inputData(i,j,:))-mean(squeeze(inputData(i,j,:))))+mean(squeeze(inputData(i,j,:)));
newvar = reshape(newvar,1,[]);
tempvar = [tempvar;newvar];
end
outputData(i,:,:) = tempvar;
disp(['Iteration n.', num2str(i)])
end
end
But if I run it I get the following error:
Error using lowPassHyperCube>(parfor body) (line 9)
An UndefinedFunction error was thrown on the workers for 'filter'. This might be because the file containing 'filter' is not
accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation
for 'parallel.Pool/addAttachedFiles' for more details.
Error in lowPassHyperCube (line 6)
parfor i=1:size(inputData,1)
Caused by:
Undefined function 'filter' for input arguments of type 'struct'.
Any idea why?
Let me know you can try this out. Attached you have the mat file containing the filter object I have created but you shouldn't need any specific data, you can just try with fake ones.
Greetings
Luca
3 个评论
Ridwan Alam
2019-12-13
Luca, I don't think it has much to do with freeing up those temp memory. You can certainly try to not use newvar, inputVector at all. I used those only for ease of reading.
Maybe you can try to upgrade the Matlab version. Earlier versions needed something called matlabpool. I am not sure you need that or are already using that.
回答(1 个)
Ridwan Alam
2019-12-12
编辑:Ridwan Alam
2019-12-12
The error is caused by the way global digital filter objects are handled by filter() in parfor loop.
function [outputData] = lowPassHyperCube(inputData,filterObj)
outputData = [];
filterVar = filterObj.Numerator;
parfor i=1:size(inputData,1)
tempvar = [];
for j=1:size(inputData,2)
inputVector = squeeze(inputData(i,j,:));
newvar = filter(filterVar,1,inputVector-mean(inputVector))+mean(inputVector);
newvar = reshape(newvar,1,[]);
tempvar = [tempvar;newvar];
end
outputData(i,:,:) = tempvar;
disp(['Iteration n.', num2str(i)])
end
end
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!