How to calculate PSNR in Matlab Figure file?
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Mehmed Saad
on 23 Apr 2020
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 Comments
Mehmed Saad
on 24 Apr 2020
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.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!