Finding the closest match for data.

13 ビュー (過去 30 日間)
Leon Ellis
Leon Ellis 2021 年 11 月 15 日
回答済み: Brahmadev 2024 年 4 月 12 日
Good day, here I've plotted a power, frequency vs time domain of an audio signal.
I have the power, frequency and time values requered to plot this graph. I want to compare words to one another and comput the closest match. I'm thinking of using the mean square error (MSE) using the immse() function, however I'm not sure if that will give me the result I require. If I make a nx3 matrix (with n being many numbers) using horzcat(p,t,f) function to concatenate the power, time and frequency; will I be able to obtain an accurate difference using the immse() function to compare 2 arrays of size nx3? Or would a different approuch be needed to compare them and obtain more accurate results? Thanks in advance!

回答 (1 件)

Brahmadev
Brahmadev 2024 年 4 月 12 日
The strategy that you have described using "immse" function can be useful for comparison. Some other things to consider are:
  1. Does the data need to be pre-processed and normalized?
  2. Are the time and frequency ranges identical and can they be ignored for the comparison?
For comparing images or 2D matrices, you can also use "psnr" or "ssim". Refer to the example below for usage of "ssim", I have taken some example data with different time and frequency. Interpolation can be ignored if the ranges are identical.
% Dataset 1
frequency1 = linspace(0, 400, 100); % 100 points from 0 to 400
time1 = linspace(0, 0.5, 50); % 50 points from 0 to 0.5
[FreqGrid1, TimeGrid1] = meshgrid(frequency1, time1);
Power1 = sin(FreqGrid1 / 100.0) .* cos(TimeGrid1 * 4 * pi);
% Dataset 2 with different ranges
frequency2 = linspace(0, 500, 120); % Different range and number of points
time2 = linspace(0, 0.6, 60); % Different range and number of points
[FreqGrid2, TimeGrid2] = meshgrid(frequency2, time2);
Power2 = sin(FreqGrid2 / 120.0) .* cos((TimeGrid2 * 5 * pi) + pi / 8);
% Interpolate Dataset 2 to match the grid of Dataset 1
Power2Interpolated = interp2(FreqGrid2, TimeGrid2, Power2, FreqGrid1, TimeGrid1, 'linear');
% Calculate SSIM between the original Power1 and the interpolated Power2
[ssimval, ssimmap] = ssim(Power1, Power2Interpolated);
fprintf('The SSIM value is %0.4f\n', ssimval);
% Optionally, visualize the SSIM map
figure;
imshow(ssimmap, []);
title(sprintf('SSIM Index Map - Mean SSIM Value: %0.4f', ssimval));
You can refer to the following documentation link for more information:
  1. https://www.mathworks.com/help/images/ref/ssim.html
  2. https://www.mathworks.com/help/images/ref/psnr.html
Hope this helps!

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by