How to calculate PSNR in Matlab Figure file?
2 次查看(过去 30 天)
显示 更早的评论
I wish to calculate the PSNR between two signals.
The input file would be Matlab Figure file.
signal1 = openfig('Figure1.fig');
signal2 = openfig('Figure2.fig');
[R C]=size(signal1);
err = sum((signal1-signal2).^2)/(R*C);
MSE=sqrt(err);
MAXVAL=65535;
PSNR = 20*log10(MAXVAL/MSE);
disp(MSE);
disp(PSNR);
However, the error shows:
Operator '-' is not supported for operands of type 'matlab.ui.Figure'.
Error in file (line 4)
err = sum((signal1-signal2).^2)/(R*C);
How can I solve the error?
0 个评论
采纳的回答
Mehmed Saad
2020-4-23
signal1 = openfig('Figure1.fig');
signal2 = openfig('Figure2.fig');
signal1 contains the figure handle not the data
you have to extract data from figure handle, you cannot directly subtract two figures data by subtracting there handle
to extract data from figure handle (assuming they contain 1 line only)
data1 = signal1.Children(1).Children(1).YData;
data2 = signal2.Children(1).Children(1).YData;
Now you can process data1 and data2 from here after
3 个评论
Mehmed Saad
2020-4-24
your matrix are not of same dimension.
There are two possible things in this contex which make there dimension different
- sampling rate
- time of signal
to get the time signal from plots
t1 = signal1.Children(1).Children(1).XData;
t2 = signal2.Children(1).Children(1).XData;
Now you have to check if their sampling rates are same or not and their ending times are same or not
- if their sampling rate is same but ending time is not, truncate the longer time signal
- f their time ends at the time then they have different sampling rate. you either have to upsample the low sampling signal or downsample the high sampling signal so that both signal are of same sampling rate
- if ending time and sampling rate both are not matching, first match the time and then follow the step 2
Now you have to do it yourself. it is basic matrix operation.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!