フィルターのクリア

Cannot run 16-PSK code in Switch case inside of another switch case

1 回表示 (過去 30 日間)
Ibnu Darajat
Ibnu Darajat 2022 年 10 月 30 日
コメント済み: Ibnu Darajat 2022 年 11 月 11 日
Here's the 16-PSK modulation code I tried:
kanal = get(handles.popupmenu1,'Value');
switch kanal
case 1
bitt=randi([0 1],12,1);
all_bit=sprintf('%d', bitt);
n_bit=length(all_bit);
sampling_bit=50;
bit=[];
for i=1:length(all_bit)
if all_bit(i)~=dec2bin(0) && all_bit(i)~=dec2bin(1)
set_ok=0;
break
else
set_ok=1;
end
end
for n=1:1:length(all_bit);
if all_bit(n)==dec2bin(0)
bit=[bit 1*zeros(1,sampling_bit)];
elseif all_bit(n)==dec2bin(1)
bit=[bit 1*ones(1,sampling_bit)];
end
end
plot(bit,'LineWidth',1.5);
xlabel('ms');
ylabel('amplitude');
grid on;
axis([0 n_bit*sampling_bit -2 2]);
xticks([0:sampling_bit:n_bit*sampling_bit]);
yticks([-2:1:2]);
ax=gca;
ax.XTickLabelRotation = -90;
freq=100;
amp=1;
cycle=2*pi;
ts = 0.0001:0.0002:0.01;
n_psk=16;
n_bit=length(all_bit);
nb_psk=log2(n_psk);
n_simbol=n_bit/nb_psk;
l_ts=length(ts);
ph=[];
simbol=[];
tempSymbol= [];
modulatedSignal=[];
stddev=1;
urutan_konstelasi_sudut=[0 1 3 2 7 6 4 5 15 14 12 13 8 9 11 10];
for i=1:n_psk/2
for j=i:i
urutan_konstelasi_sudut=[urutan_konstelasi_sudut j];
end
for k=n_psk-i+1:n_psk-i+1
urutan_konstelasi_sudut=[urutan_konstelasi_sudut mod(k,n_psk)];
end
end
for i=1:n_psk
ph=[ph urutan_konstelasi_sudut(i)/n_psk*cycle];
simbol=[simbol [amp*sin(cycle*freq*ts+ph(i))]];
end
for i = 1:nb_psk:n_bit-nb_psk+1
tempSymbol = [all_bit(i:i+nb_psk-1)];
for j=0:n_psk-1
if tempSymbol == dec2bin(j,nb_psk)%[000]
modulatedSignal = [modulatedSignal simbol(j*l_ts+1:(j+1)*l_ts)];
end
end
tempSymbol = []; %reset tempSymbol
end
axes(handles.axes2);
hold off;
plot(modulatedSignal,'LineWidth',1.5);grid on;
hold on;
legend('sinyal informasi')
end
the code above was executed successfully. but when i put the code in Switch case inside of another switch case like below:
kanal = get(handles.popupmenu1,'Value');
switch kanal
case 1
mod = get(handles.popupmenu2,'Value');
switch mod
case 1
bitt=randi([0 1],12,1);
all_bit=sprintf('%d', bitt);
n_bit=length(all_bit);
sampling_bit=50;
bit=[];
for i=1:length(all_bit)
if all_bit(i)~=dec2bin(0) && all_bit(i)~=dec2bin(1)
set_ok=0;
break
else
set_ok=1;
end
end
for n=1:1:length(all_bit);
if all_bit(n)==dec2bin(0)
bit=[bit 1*zeros(1,sampling_bit)];
elseif all_bit(n)==dec2bin(1)
bit=[bit 1*ones(1,sampling_bit)];
end
end
plot(bit,'LineWidth',1.5);
xlabel('ms');
ylabel('amplitude');
grid on;
axis([0 n_bit*sampling_bit -2 2]);
xticks([0:sampling_bit:n_bit*sampling_bit]);
yticks([-2:1:2]);
ax=gca;
ax.XTickLabelRotation = -90;
freq=100;
amp=1;
cycle=2*pi;
ts = 0.0001:0.0002:0.01;
n_psk=16;
n_bit=length(all_bit);
nb_psk=log2(n_psk);
n_simbol=n_bit/nb_psk;
l_ts=length(ts);
ph=[];
simbol=[];
tempSymbol= [];
modulatedSignal=[];
stddev=1;
urutan_konstelasi_sudut=[0 1 3 2 7 6 4 5 15 14 12 13 8 9 11 10];
for i=1:n_psk/2
for j=i:i
urutan_konstelasi_sudut=[urutan_konstelasi_sudut j];
end
for k=n_psk-i+1:n_psk-i+1
urutan_konstelasi_sudut=[urutan_konstelasi_sudut mod(k,n_psk)];
end
end
for i=1:n_psk
ph=[ph urutan_konstelasi_sudut(i)/n_psk*cycle];
simbol=[simbol [amp*sin(cycle*freq*ts+ph(i))]];
end
for i = 1:nb_psk:n_bit-nb_psk+1
tempSymbol = [all_bit(i:i+nb_psk-1)];
for j=0:n_psk-1
if tempSymbol == dec2bin(j,nb_psk)%[000]
modulatedSignal = [modulatedSignal simbol(j*l_ts+1:(j+1)*l_ts)];
end
end
tempSymbol = []; %reset tempSymbol
end
axes(handles.axes2);
hold off;
plot(modulatedSignal,'LineWidth',1.5);grid on;
hold on;
legend('sinyal informasi')
end
end
there is an error as follows:
Index in position 1 exceeds array bounds (must not exceed 1).
Error in mod16psk>pushbutton1_Callback (line 186)
urutan_konstelasi_sudut=[urutan_konstelasi_sudut mod(k,n_psk)];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in mod16psk (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)mod16psk('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
Did I miss something? Thanks before

採用された回答

Setsuna Yuuki.
Setsuna Yuuki. 2022 年 10 月 30 日
Hi.
In the second code your use the variable:
mod = get(handles.popupmenu2,'Value');
but this name is a function name.
Change the variable name for other.
mod2 = get(handles.popupmenu2,'Value');
switch mod2
case 1
  2 件のコメント
Ibnu Darajat
Ibnu Darajat 2022 年 10 月 31 日
thankyou so much
Ibnu Darajat
Ibnu Darajat 2022 年 11 月 11 日
After I change the function name into "mod2", I got this error:
>> mod_fsk
Unrecognized function or variable 'mod'.
Error in mod_fsk>pushbutton2_Callback (line 261)
urutan_konstelasi_sudut=[urutan_konstelasi_sudut mod(k,n_psk)];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in mod_fsk (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)mod_fsk('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback.
>>
Now variable "mod" unrecognized

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by