Template matching between 1d frequency curves using normxcorr2
36 views (last 30 days)
Show older comments
Hi,
I'm trying to use 2d cross correlation between 1d dimensional frequency curves (frequencies between 6000 and 22000 Hz) to find if a template curve is present in a test one which is bigger:
Template curve:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1725541/image.png)
Test curve:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1725546/image.png)
I'm willing to use two dimensional cross correlation between both curves using normxcorr2 but I'm not quite sure the most efficient way to do this.
I've tried to convert both curves to binary image arrays, and then applying nomxcorr2 using:
img_template=bsxfun(@eq, 1:22000,curve_template);
img_test=bsxfun(@eq, 1:22000,curve_test);
c=normxcorr2(img_template,img_test);
but this way the 2d arrays are huge (77x22000 and 5703x22000) and the results are difficult to plot ( because of memory issues) and so to analize:
figure;mesh(img_template');hold on;
view([0 90]);
mesh(img_test);
figure;
surf(c)
Any clue on how to do this template matching between curves in a more efficcient way?
2 Comments
Matt
on 1 Jul 2024 at 21:34
Hi,
If you want to detect, in a 1D signal, a certain pattern you can simply use 1D correlation. No need, except if I missed your goal, to convert the data like you are.
% normxcorr2 works on 1d data:
plot(normxcorr2(curve_template,curve_test))
% but it also work on N signals of length M
n = 512;
m=1024;
imagesc(normxcorr2(curve_template,rand(m,n)))
and if you want to go faster on many signals, you can drop the normalisation part and simply do a convolution between your signals, and the pattern.
imagesc(conv2(curve_template,rand(m,n),'valid'))
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!