How to calculate PSNR in Matlab Figure file?

2 vues (au cours des 30 derniers jours)
Star Rats
Star Rats le 23 Avr 2020
Commenté : Star Rats le 18 Juil 2020
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?

Réponse acceptée

Mehmed Saad
Mehmed Saad le 23 Avr 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 commentaires
Mehmed Saad
Mehmed Saad le 24 Avr 2020
your matrix are not of same dimension.
There are two possible things in this contex which make there dimension different
  1. sampling rate
  2. 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
  1. if their sampling rate is same but ending time is not, truncate the longer time signal
  2. 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
  3. 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.
Star Rats
Star Rats le 18 Juil 2020
Thanks @Mehmed !

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by