help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

subplot plot not obeying ylim


From: Gui Ritter
Subject: subplot plot not obeying ylim
Date: Sat, 7 Sep 2013 17:31:10 -0300

Hi everyone.

I just started using Octave at college, but our teacher requested that we learn mostly by ourselves and this specific question is about a file that someone else wrote.

We were tasked with modifying a file for a certain objective. I did almost everything, but there's a small detail I can't fix. I want to change the Y range of a plot made inside a subplot. I tried using ylim, but it only affects the first plot, and I need it to affect the second.

The file is actually three files. The first one is Main.m:

% alterado por Guilherme Alan Ritter (UNISC · m72642)
% para Atividade 5 de Comunicação de Dados (09/09/2013)

clear all;
close all;

function guir_random_number = guir_random ()
    guir_random_number = stdnormal_rnd(1);
    while (true)
        if (guir_random_number < 0)
            ++guir_random_number;
        elseif (guir_random_number > 1)
            --guir_random_number;
        else
            break
        endif
    endwhile
    guir_random_number *= 99;
    ++guir_random_number;
end

function guir_noise = guir_AWGN (guir_v)
    guir_noise = sqrt(guir_v) * guir_random();
end

function guir_increment = guir_adjust (guir_v, guir_x)
    guir_increment = guir_v*(((guir_x-sqrt(guir_v))*(4/(99*sqrt(guir_v))))-2);
end

printf("\n\n");
printf("================================================================================\n");
printf("====               COMUNICACAO DE DADOS Codificação/Decodificação           ====\n");
printf("====                                                                        ====\n");
printf("====             Adaptado do trabalho dos alunos do Semestre 2012/2         ====\n");
printf("================================================================================\n");

palavra=input("\n\nInforme uma palavra a ser transmitida: ", "s");

%-------------------------------------------
% Codificação de Fonte
%-------------------------------------------
s_bit="";

for i=1:length(palavra)
    s_bit = strcat(s_bit,dec2bin(double(palavra(i)),8));
endfor

bit_stream=[];

for i=1:length(s_bit)
    if(s_bit(i)=='0')
        bit_stream(i) =0;
    else
        bit_stream(i) =1;
    endif
endfor

printf("\nA sequência binária da palavra é: %s\n");
bit_stream % Original


%-------------------------------------------
% Declaração de Variaveis Utilizadas
%-------------------------------------------
A = 1;                                            % Amplitude Nivel Alto (1)
A2 = 0.5;                                         % Amplitude Nivel Baixo (0)
polar = [ -A +A ];                                % Mapeamento dos Polos
M = 16;                                            % Taxa de amostragem 
T_bits = length(bit_stream);                    % Duração da sequencia de bits
t = 1/M:1/M:T_bits ;                            % gera o tempo de amostragem por bit                                    
Rb=100;                                         % bits por segundo
bit_M= [];                                      % matriz de bits para exibição
V_exibe=1;%4                                        % variavel para exibição das ondas (zoom 1 a T-bits)
N_ruido=600;                                     % nivel do sinal de ruido

if((V_exibe > T_bits) || (V_exibe <1))
    V_exibe=1;
endif
    
for i=1:length(bit_stream)                    
    bit_M = [bit_M bit_stream(i)*ones(1,M)];    % gera 32 'bits' para cada bit
end

p_M(1:(M/2)+1)=-1; p_M((M/2)+1:M)=1;            % pulso mancheter para 1 a 17 = -1 e para 17 até 32 = 1
p_NRZ(1:M)=1;                                    % são todos = 1 (32 uns)

tipoCod = input("\nEscolha o tipo de codificacao que deseja exibir e depois pressione [ENTER]:\n[1] Manchester\n[2] Differential Manchester\n"); %[2]NRZ L\n[3] Unipolar RZ\n[4] Polar NRZ\n[5] Polar RZ\n[6] AMI NRZ\n[7] AMI RZ\n"

    codificacao
    decodificacao


%-------------------------------------------
% Decodificação de Fonte
%-------------------------------------------
palavraRec="";
temp="";
j=1; 

printf("\nA sequência binária recebida é: %s\n");
bitRec
for i=1:length(bitRec)
    if(bitRec(i)==0)
        temp=strcat(temp,"0");
    else
        temp=strcat(temp,"1");
    endif
    j++;
    if(j==9)
        palavraRec = strcat(palavraRec,bin2dec(temp));
        j=1;
        temp="";
    endif
endfor

printf("\n\nEsta foi a palavra recuperada: ");
palavraRec

The second one is codificacao.m:

% alterado por Guilherme Alan Ritter (UNISC · m72642)
% para Atividade 5 de Comunicação de Dados (09/09/2013)

guir_variance = input("\nInsira a quantidade de variância: ");

pular=input("\nEtapa de Codificacao, ENTER para ver ou P para pular ", "");
if(length(pular)==0)
    figure(1)
    subplot(3,1,1);
    plot(t,bit_M);
    title ('Bit Original');
    %xlabel('Tempo');
    ylabel('Amplitude');
    axis ([ 0 T_bits  -0.1 1.1 ]);
    subplot(3,1,2:3);
endif
%-------------------------------------------
%Codificação Manchester
%-------------------------------------------
if(tipoCod == 1)

    for i=1:length(bit_stream) 
        for j=(i-1)*M+1:i*M
            sinalCod(j) = polar(bit_stream(i)+1)*p_M(j-(i-1)*M); % cria codificação se for 0 entao 1-0 1 = 0.1
            sinalCod(j) += guir_adjust(guir_variance, guir_AWGN(guir_variance));
        end
    end
    if(length(pular)==0)
        plot(t,sinalCod);
        ylim('manual');
        ylim([-4.1 4.1]);
        title ('Codificacao Manchester');
    endif

%------------------------------------------------------
%Codificação Differential Manchester - por Diego Pittol
%------------------------------------------------------
elseif(tipoCod == 2)
    inverte = -1;
    for i=1:length(bit_stream)
        for j=(i-1)*M+1:i*M
            sinalCod(j) = polar(bit_stream(i)+1)*p_M(j-(i-1)*M); % cria codificação se for 0 entao 1-0 1 = 0.1
        sinalCod(j)*=inverte;
        end
    if(bit_stream(i)==1)
            inverte=inverte*-1;
        endif
    end
    if(length(pular)==0)
        plot(t,sinalCod);
        title ('Codificacao Differential Manchester');
    endif


endif

if(length(pular)==0)
    xlabel('Tempo');
    ylabel('Amplitude');
    axis ([ 0 T_bits  -1.1*A 1.1*A ]);
endif

The third one is decodificacao.m:

% alterado por Guilherme Alan Ritter (UNISC · m72642)
% para Atividade 5 de Comunicação de Dados (09/09/2013)

pular=input("Etapa de Decodificacao, ENTER para ver ou P para pular ", "");

%-------------------------------------------
% Decodificação Manchester
%-------------------------------------------
%sinalCod = tranfInvNoise;
if(tipoCod == 1)

    bitRec=[];
    j=1;
    cont=0;
    larg = M/2;
    
    for i=2:length(sinalCod) 
        cont++;
        if((sinalCod(i) < sinalCod(i-1)) && cont==larg)
            bitRec(j) = 0;
            j++;
            cont=-larg;
        endif
        if((sinalCod(i) > sinalCod(i-1)) && cont==larg)
            bitRec(j) = 1;
            j++;
            cont=-larg;
        endif    
    end

    sinalDecodificado= [];
    
    for i=1:length(bitRec)
        sinalDecodificado = [sinalDecodificado bitRec(i)*ones(1,M)];
    end
        if(length(pular)==0)
            figure(6)
            subplot(2,1,1)
            plot(sinalCod);
            title ('Sequencia de bits decodificada em Manchester');
            %xlabel('Tempo');
            ylabel('Amplitude');
            axis([ 0 length(sinalCod) -1.1*A 1.1*A]);
        endif

%---------------------------------------------------------
% Decodificação Differential Manchester - por Diego Pittol
%---------------------------------------------------------
elseif(tipoCod == 2)

    bitRec=[];
    j=1;
    cont=0;
    larg = M/2;
    primeiro=1; %informa que é o primeiro bit
    passado=1;      %1 significa borda final alta, e 0 borda final baixa

    for i=2:length(sinalCod)
        cont++;
           
        % bits do primeiro perido
        if(primeiro==1)
        if((sinalCod(i) < sinalCod(i-1)) && cont==larg)
            bitRec(j) = 1;
            passado=1;
            primeiro=0;
            j++;
            cont=-larg;
        endif
        if((sinalCod(i) > sinalCod(i-1)) && cont==larg)
            bitRec(j) = 0;
            passado=0;
            primeiro=0;
            j++;
            cont=-larg;
        endif  

        % bits a partir do segundo periodo
        else
        if((sinalCod(i) < sinalCod(i-1)) && cont==larg)
            if(passado==0)
                bitRec(j) = 1;
            else
                bitRec(j) = 0;
            endif
            passado=1;
            j++;
            cont=-larg;
        endif
        if((sinalCod(i) > sinalCod(i-1)) && cont==larg)
            if(passado==1)
                bitRec(j) = 1;
            else
                bitRec(j) = 0;
            endif
            passado=0;
            j++;
            cont=-larg;
        endif  
        endif
    end

    sinalDecodificado= [];
       
    for i=1:length(bitRec)
        sinalDecodificado = [sinalDecodificado bitRec(i)*ones(1,M)];
    end
        if(length(pular)==0)
            figure(6)
            subplot(2,1,1)
            plot(sinalCod);
            title ('Sequencia de bits decodificada em Differential Manchester');
            %xlabel('Tempo');
            ylabel('Amplitude');
            axis([ 0 length(sinalCod) -1.1*A 1.1*A]);
        endif

endif


T_bits_decod = length(bitRec);                    % Duração da sequencia de bits
printf("Total de Bits Reuperados: %d",T_bits_decod)
t_decod = 1/M:1/M:T_bits_decod;

if(length(pular)==0)
    figure(6)
    subplot(2,1,2)
    plot(t_decod,sinalDecodificado);
    title ('Bit Recuperado');
    xlabel('Tempo');
    ylabel('Amplitude');
    axis ([ 0 T_bits  -0.1 1.1 ]);
endif

Run Main.m, input any string, input 1, input a number between 0.1 and 0.9, press enter. My objective is to change the Y range of that second plot. I added ylim at line 30 and 31 of codificacao.m, but it doesn't have an effect. I tried several other commands, and axis was able to change the range, but not to the values that I typed.

I searched in Google and this mailing list but found nothing. I'm using Octave 3.6.2, installed from Debian Wheezy's repositories and OS is up to date.

Thanks in advance.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]