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});endif 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_inpim_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_avval=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;endinput=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; endendx_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);endfor k=1:numel(x_distort) P(k,:)=[4;x_distort(k)].*prob(k).^(4-x_distort(k)).*(1-prob(k)).^x_distort(k);endtx_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_distortN=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_distortblock_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_distortbar(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 PP_th=6:15;%axes(handles.axes2);
%cla
figureplot(P_th,P(1,:),'b*-')hold onplot(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.
Best Answer