iam getting error while iam debugging the code in matlab 2019, But it is excuting in matlab 2014 version.... Iwant this in MATLAB 2019 please help me

6 views (last 30 days)
function varargout = mygui(varargin)
% MYGUI MATLAB code for mygui.fig
% MYGUI, by itself, creates a new MYGUI or raises the existing
% singleton*.
%
% H = MYGUI returns the handle to a new MYGUI or the handle to
% the existing singleton*.
%
% MYGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYGUI.M with the given input arguments.
%
% MYGUI('Property','Value',...) creates a new MYGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before mygui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to mygui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help mygui
% Last Modified by GUIDE v2.5 02-Mar-2019 16:47:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State=struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mygui_OpeningFcn, ...
'gui_OutputFcn', @mygui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
% gui_State1 = struct2cell(gui_State);
% gui_State= cell2mat(gui_State1);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before mygui is made visible.
function mygui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to mygui (see VARARGIN)
% Choose default command line output for mygui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes mygui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = mygui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in image_read.
function image_read_Callback(hObject, eventdata, handles)
% hObject handle to image_read (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im_inp
im_inp=imread('greens.jpg'); % image to be transmitted and matlab code should be in same directory
axes(handles.axes1)
imshow(im_inp);
title('Original Image');
% --- Executes on button press in select_fading.
function select_fading_Callback(hObject, eventdata, handles)
% hObject handle to select_fading (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of select_fadingc
global im_inp tx_16qam input P_av
val=get(hObject,'Value');
N=numel(im_inp);
[LL,LH,HL,HH]=dwt2(im_inp,'haar');
var_ll=var(LL(:));
var_lh=var(LH(:));
var_hl=var(HL(:));
var_hh=var(HH(:));
in2=reshape(im_inp,N,1);
bin=de2bi(in2,'left-msb');
%% Serialization
input=reshape(bin',numel(bin),1);
len=length(input);
%%%%% padding zeroes to input CP addition%%%
z=len;
while(rem(z,2) || rem(z,4)|| rem(z,6))
z=z+1;
input(z,1)=0;
end
input=double(input);
h_16qam=qammod('M',16,'inputtype','bit');
y_16qam=modulate(h_16qam,input);
ifft_out_16qam=ifft(y_16qam);
SNR=menu('Select SNR Value','5','10','15'); % SNR in dB
SNR=SNR*5;
p=raylpdf(ifft_out_16qam,0.5);
solve('log(P_av)+(0.5/P_av)+log(p)==0','P_av')
P_av=ans;
for ii=1:4
if ii<4
y_distort(ii)=var_ll.^2+var_lh.^2+var_hl.^2+var_hh.^2+i*(128/12);
else
y_distort(ii)=i*128/12;
end
end
x_distort=(0:5);
if (val==3)
rayleighChan=comm.RayleighChannel(...
'SampleRate', 1000,...
'PathDelays', [0 1.5e-4],...
'AveragePathGains', [2 3],...
'NormalizePathGains', true,...
'MaximumDopplerShift', 30,...
'DopplerSpectrum', {doppler('Gaussian',0.06), doppler('Flat')},...
'RandomStream', 'mt19937ar with seed',...
'Seed', 22,...
'PathGainsOutputPort', true);
[ifft_0ut_16qam,SNR]=Step(rayleighChan,ifft_out_16qam,SNR);
end
for j=6:15
P_th=1/j;
F=P_av.*P_th;
prob(j,:)=1-exp(-1./F);
end
for k=1:numel(x_distort)
P(k,:)=[4;x_distort(k)].*prob(k).^(4-x_distort(k)).*(1-prob(k)).^x_distort(k);
end
tx_16qam=awgn(ifft_out_16qam,SNR,'measured');
msgbox('Modulation DOne')
% --- Executes on button press in rcv.
function rcv_Callback(hObject, eventdata, handles)
% hObject handle to rcv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global tx_16qam im_inp input y_distort
N=numel(im_inp);
k_16qam=fft(tx_16qam);
g_16qam=qamdemod('M',16,'outputtype','bit');
l_16qam=demodulate(g_16qam,k_16qam);
output_16qam=uint8(l_16qam);
%% Serial to Paraller
b2=reshape(output_16qam,8,N)';
%%binary to dec
dec_16qam=bi2de(b2,'left-msb');
y_distort=[31,18,17,12,-5];
len=length(input);
BER_16qam=biterr(input,l_16qam)/len;
im_16qam=reshape(dec_16qam(1:N),size(im_inp,1),size(im_inp,2),size(im_inp,3));
axes(handles.axes2);
imshow(uint8(im_16qam));title('16QAM');
SSIM_16qam=ssim(im_16qam,im_inp);
UQI=calculate_uqi(im_16qam,im_inp);
PSNR=psnr(im_16qam,im_inp)
fprintf('The BER=%f SSIM=%f UQI=%f PSNR=%f\n',BER_16qam,SSIM_16qam,UQI,PSNR)
function UQI=calculate_uqi(img1,img2)
global x_distort y_distort
block_size = 8;
N = block_size.^2;
sum2_filter = ones(block_size);
img1=im2double(rgb2gray(img1));
img2=im2double(rgb2gray(img2));
img1_sq = img1.*img1;
img2_sq = img2.*img2;
img12 = img1.*img2;
img1_sum = filter2(sum2_filter, img1, 'valid');
img2_sum = filter2(sum2_filter, img2, 'valid');
img1_sq_sum = filter2(sum2_filter, img1_sq, 'valid');
img2_sq_sum = filter2(sum2_filter, img2_sq, 'valid');
img12_sum = filter2(sum2_filter, img12, 'valid');
img12_sum_mul = img1_sum.*img2_sum;
img12_sq_sum_mul = img1_sum.*img1_sum + img2_sum.*img2_sum;
numerator = 4*(N*img12_sum - img12_sum_mul).*img12_sum_mul;
denominator1 = N*(img1_sq_sum + img2_sq_sum) - img12_sq_sum_mul;
denominator = denominator1.*img12_sq_sum_mul;
x_distort=0:4;
quality_map = ones(size(denominator));
index = (denominator1 == 0) & (img12_sq_sum_mul ~= 0);
quality_map(index) = 2*img12_sum_mul(index)./img12_sq_sum_mul(index);
index = (denominator ~= 0);
quality_map(index) = numerator(index)./denominator(index);
UQI = mean2(quality_map);
% --- Executes on button press in conditional_distort.
function conditional_distort_Callback(hObject, eventdata, handles)
% hObject handle to conditional_distort (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x_distort y_distort
bar(x_distort,y_distort)
xlabel('No of data vectors rcvd')
ylabel('Conditional Distortion')
% --- Executes on button press in datavector_loss.
function datavector_loss_Callback(hObject, eventdata, handles)
% hObject handle to datavector_loss (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global P
P_th=6:15;
%axes(handles.axes2);
%cla
figure
plot(P_th,P(1,:),'b*-')
hold on
plot(P_th,P(2,:),'g*-')
plot(P_th,P(3,:),'r*-')
plot(P_th,P(4,:),'k*-')
plot(P_th,P(5,:),'y*-')
legend('P0','P1','P2','P3','P4')
error is
>> mygui
Error using qammod
Expected input number 1, X, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64
Error in qammod>validateInput (line 284)
validateattributes(x, {'numeric'}, {'real','binary'}, mfilename, 'X', 1);
Error in qammod (line 95)
validateInput(x, M, bitInput, outputDataType);
Error in mygui>select_fading_Callback (line 117)
h_16qam=qammod('M',16,'inputtype','bit');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in mygui (line 44)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)mygui('select_fading_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
  3 Comments
krishna kotha
krishna kotha on 15 Apr 2019
Edited: Rik on 15 Apr 2019
modem.qammod
in 2014 i used this function instead of qammod to excute code but in 2019 it says it is removed in 2014 i used this code
function varargout = mygui(varargin)
% MYGUI MATLAB code for mygui.fig
% MYGUI, by itself, creates a new MYGUI or raises the existing
% singleton*.
%
% H = MYGUI returns the handle to a new MYGUI or the handle to
% the existing singleton*.
%
% MYGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYGUI.M with the given input arguments.
%
% MYGUI('Property','Value',...) creates a new MYGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before mygui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to mygui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help mygui
% Last Modified by GUIDE v2.5 02-Mar-2019 16:47:03
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @mygui_OpeningFcn, ...
'gui_OutputFcn', @mygui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before mygui is made visible.
function mygui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to mygui (see VARARGIN)
% Choose default command line output for mygui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes mygui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = mygui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in image_read.
function image_read_Callback(hObject, eventdata, handles)
% hObject handle to image_read (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global im_inp
im_inp=imread('greens.jpg'); % image to be transmitted and matlab code should be in same directory
axes(handles.axes1)
imshow(im_inp);
title('Original Image');
% --- Executes on button press in select_fading.
function select_fading_Callback(hObject, eventdata, handles)
% hObject handle to select_fading (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of select_fadingc
global im_inp tx_16qam input P_av
val=get(hObject,'Value');
N=numel(im_inp);
[LL,LH,HL,HH]=dwt2(im_inp,'haar');
var_ll=var(LL(:));
var_lh=var(LH(:));
var_hl=var(HL(:));
var_hh=var(HH(:));
in2=reshape(im_inp,N,1);
bin=de2bi(in2,'left-msb');
%% Serialization
input=reshape(bin',numel(bin),1);
len=length(input);
%%%%% padding zeroes to input CP addition%%%
z=len;
while(rem(z,2) || rem(z,4)|| rem(z,6))
z=z+1;
input(z,1)=0;
end
input=double(input);
h_16qam=modem.qammod('M',16,'inputtype','bit');
y_16qam=modulate(h_16qam,input);
ifft_out_16qam=ifft(y_16qam);
SNR=menu('Select SNR Value','5','10','15'); % SNR in dB
SNR=SNR*5;
p=raylpdf(ifft_out_16qam,0.5);
solve('log(P_av)+(0.5/P_av)+log(p)==0','P_av')
P_av=ans;
for ii=1:4
if ii<4
y_distort(ii)=var_ll.^2+var_lh.^2+var_hl.^2+var_hh.^2+i*(128/12);
else
y_distort(ii)=i*128/12;
end
end
x_distort=(0:5);
if (val==3)
rayleighChan=comm.RayleighChannel(...
'SampleRate', 1000,...
'PathDelays', [0 1.5e-4],...
'AveragePathGains', [2 3],...
'NormalizePathGains', true,...
'MaximumDopplerShift', 30,...
'DopplerSpectrum', {doppler('Gaussian',0.06), doppler('Flat')},...
'RandomStream', 'mt19937ar with seed',...
'Seed', 22,...
'PathGainsOutputPort', true);
[ifft_0ut_16qam,SNR]=Step(rayleighChan,ifft_out_16qam,SNR);
end
for j=6:15
P_th=1/j;
F=P_av.*P_th;
prob(j,:)=1-exp(-1./F);
end
for k=1:numel(x_distort)
P(k,:)=[4;x_distort(k)].*prob(k).^(4-x_distort(k)).*(1-prob(k)).^x_distort(k);
end
tx_16qam=awgn(ifft_out_16qam,SNR,'measured');
msgbox('Modulation DOne')
% --- Executes on button press in rcv.
function rcv_Callback(hObject, eventdata, handles)
% hObject handle to rcv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global tx_16qam im_inp input y_distort
N=numel(im_inp);
k_16qam=fft(tx_16qam);
g_16qam=modem.qamdemod('M',16,'outputtype','bit');
l_16qam=demodulate(g_16qam,k_16qam);
output_16qam=uint8(l_16qam);
%% Serial to Paraller
b2=reshape(output_16qam,8,N)';
%%binary to dec
dec_16qam=bi2de(b2,'left-msb');
y_distort=[31,18,17,12,-5];
len=length(input);
BER_16qam=biterr(input,l_16qam)/len;
im_16qam=reshape(dec_16qam(1:N),size(im_inp,1),size(im_inp,2),size(im_inp,3));
axes(handles.axes2);
imshow(uint8(im_16qam));title('16QAM');
SSIM_16qam=ssim(im_16qam,im_inp);
UQI=calculate_uqi(im_16qam,im_inp);
PSNR=psnr(im_16qam,im_inp)
fprintf('The BER=%f SSIM=%f UQI=%f PSNR=%f\n',BER_16qam,SSIM_16qam,UQI,PSNR)
function UQI=calculate_uqi(img1,img2)
global x_distort y_distort
block_size = 8;
N = block_size.^2;
sum2_filter = ones(block_size);
img1=im2double(rgb2gray(img1));
img2=im2double(rgb2gray(img2));
img1_sq = img1.*img1;
img2_sq = img2.*img2;
img12 = img1.*img2;
img1_sum = filter2(sum2_filter, img1, 'valid');
img2_sum = filter2(sum2_filter, img2, 'valid');
img1_sq_sum = filter2(sum2_filter, img1_sq, 'valid');
img2_sq_sum = filter2(sum2_filter, img2_sq, 'valid');
img12_sum = filter2(sum2_filter, img12, 'valid');
img12_sum_mul = img1_sum.*img2_sum;
img12_sq_sum_mul = img1_sum.*img1_sum + img2_sum.*img2_sum;
numerator = 4*(N*img12_sum - img12_sum_mul).*img12_sum_mul;
denominator1 = N*(img1_sq_sum + img2_sq_sum) - img12_sq_sum_mul;
denominator = denominator1.*img12_sq_sum_mul;
x_distort=0:4;
quality_map = ones(size(denominator));
index = (denominator1 == 0) & (img12_sq_sum_mul ~= 0);
quality_map(index) = 2*img12_sum_mul(index)./img12_sq_sum_mul(index);
index = (denominator ~= 0);
quality_map(index) = numerator(index)./denominator(index);
UQI = mean2(quality_map);
% --- Executes on button press in conditional_distort.
function conditional_distort_Callback(hObject, eventdata, handles)
% hObject handle to conditional_distort (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global x_distort y_distort
bar(x_distort,y_distort)
xlabel('No of data vectors rcvd')
ylabel('Conditional Distortion')
% --- Executes on button press in datavector_loss.
function datavector_loss_Callback(hObject, eventdata, handles)
% hObject handle to datavector_loss (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global P
P_th=6:15;
%axes(handles.axes2);
%cla
figure
plot(P_th,P(1,:),'b*-')
hold on
plot(P_th,P(2,:),'g*-')
plot(P_th,P(3,:),'r*-')
plot(P_th,P(4,:),'k*-')
plot(P_th,P(5,:),'y*-')
legend('P0','P1','P2','P3','P4')
and iam getting these type of error
>> mygui
Error using modem.qammod (line 82)
MODEM.QAMMOD has been removed. Use QAMMOD instead.
Error in mygui>select_fading_Callback (line 115)
h_16qam=modem.qammod('M',16,'inputtype','bit');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in mygui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)mygui('select_fading_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
>>
what should i do now....?
krishna kotha
krishna kotha on 15 Apr 2019
Edited: krishna kotha on 15 Apr 2019
I don't see why you would expect your syntax to work
mean i din't understand.....???
what shoud i do i need solution. any changes can i do.....?

Sign in to comment.

Accepted Answer

Rik
Rik on 15 Apr 2019
There are only two relevant lines from your enormous blocks of code (that you didn't format yourself):
%initial post:
h_16qam=qammod('M',16,'inputtype','bit');
%second post:
h_16qam=modem.qammod('M',16,'inputtype','bit');
Did you read the documentation? It explains the syntax that you can use for that function. I can't find explicit documentation for modem.qammod, but for the qammod function you can find the syntax in the doc pages I linked. Judging by what I could find, I suspect the correct syntax in your case should be this:
%remove these two lines:
h_16qam=modem.qammod('M',16,'inputtype','bit');
y_16qam=modulate(h_16qam,input);
%replace by:
y_16qam=qammod(input,16,'inputtype','bit');
I'm not entire sure if you need to change something about the input variable.
  7 Comments
krishna kotha
krishna kotha on 18 Apr 2019
Edited: Rik on 18 Apr 2019
i have done it. i excuted code with qammod in r2019b but the error is
>> mygui
Error using solve>getEqns (line 418)
List of equations must not be empty.
Error in solve (line 226)
[eqns,vars,options] = getEqns(varargin{:});
Error in mygui>select_fading_Callback (line 123)
solve('log(P_av)+(0.5/P_av)+log(p)==0','P_av');
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in mygui (line 44)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)mygui('select_fading_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
>>
syntax is does not matching with previous one
h_16qam=modem.qammod('M',16,'inputtype','bit');
y_16qam=qammod(input,16,'inputtype','bit');
and modified code is
Edit Rik: code moved to attachment for readability of the thread.
Rik
Rik on 18 Apr 2019
You call the function solve (R2019a doc). That has a warning:
Character vector inputs have been removed.
Instead, use syms to declare variables and replace inputs
such as solve('2*x == 1','x') with solve(2*x == 1,x).
So let's do that. Since the R2012a version of solve also supports sym inputs, we don't need to worry about any incompatiblity.
%don't use globals
%use other methods of sharing data between callback (like e.g. guidata)
syms P_av
P_av_result=solve(log(P_av)+(0.5/P_av)+log(p)==0,P_av);
%don't use ans, just store the result

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!