How to calculate PSNR in Matlab Figure file?

2 ビュー (過去 30 日間)
Star Rats
Star Rats 2020 年 4 月 23 日
コメント済み: Star Rats 2020 年 7 月 18 日
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?

採用された回答

Mehmed Saad
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
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
  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 2020 年 7 月 18 日
Thanks @Mehmed !

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by