Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

BER bit error rate w c z użyciem biblioteki allegro

Ostatnio zmodyfikowano 2016-01-13 20:59
Autor Wiadomość
aaadam
Temat założony przez niniejszego użytkownika
BER bit error rate w c z użyciem biblioteki allegro
» 2016-01-11 22:03:30
Witam staram się napisać BER-a ale mam problem przy liczeniu,
tutaj jest najważniejsza część programu, porównuje dwa wektory Nodes oraz wektor_1, i zwiększam value o 1 gdy poprawny jest warunek. Po zliczeniu wszystkich wystąpień dzielę przez 64 oraz 800 bo 800 elementow w  wektorze. Nie wydaje mi się że to jest dobrze napisane. Może ktoś pomóc ?

C/C++
value = 0;
for( int i = 0; i <= 799; ++i )
{
    for( int j = 0; j < SizeOfvalueToCheck; j++ )
    {
        if(( wektor_1[ i ].y &( 1 << j ) ) ==( Nodes[ i ].y &( 1 << j ) ) && wektor_1[ i ].y == Nodes[ i ].y )
             value += 1;
       
    }
}
cout << "value: " <<( value ) / 64.0 / 800.0 << endl;
cout << endl;
 

tutaj cały kod app.cpp
w plikach node jest struktura która zawiera pola x,y

C/C++
#include "app.h"
#include <iostream>
#include <stdlib.h>
using namespace std;

int app::SizeOfvalueToCheck = 32;
app::app( void )
    : done( 1 )
     , pi( 3.14159265358979323846 )
{
    font = al_load_font( "font2.ttf", 36, NULL );
    for( float i = 0; i < 800; i++ )
    {
        this->Nodes.push_back( node( i,( float )( 300 - i ) ) );
        this->wektor_1.push_back( Nodes[ i ] );
    }
   
    this->wektor_1.resize( 800 );
    this->wektor_2.resize( 800 );
    this->value = 0;
    A = 100, w = 1, f = 0.999, t = 1; k = 0;
    niebieskiCiemny = al_map_rgb( 150, 200, 255 );
    this->function_type = this->fun_triangle;
    this->is_clicked_change = 0;
}

void app::run()
{
   
    while( this->done )
    {
        this->keyboardControl();
        this->update();
        this->draw();
    }
}

app::~app( void )
{
   
}
void app::keyboardControl()
{
    al_wait_for_event( AllegroInit.event_queue, & AllegroInit.events );
    al_get_keyboard_state( & AllegroInit.keyState );
    if( AllegroInit.events.type == ALLEGRO_EVENT_DISPLAY_CLOSE )
    {
        this->done = false;
    }
    if( al_key_down( & AllegroInit.keyState, ALLEGRO_KEY_ESCAPE ) )
    {
        this->done = false;
    }
    if( AllegroInit.events.timer.source == AllegroInit.timer )
    {
        if( al_key_down( & AllegroInit.keyState, ALLEGRO_KEY_Z ) && ChangeClockStatus <= clock() && function_type < 3 )
        {
            this->function_type++;
            ChangeClockStatus = clock() + 0.3 * CLOCKS_PER_SEC;
        }
        if( al_key_down( & AllegroInit.keyState, ALLEGRO_KEY_X ) && ChangeClockStatus <= clock() && function_type > 0 )
        {
            this->function_type--;
            ChangeClockStatus = clock() + 0.3 * CLOCKS_PER_SEC;
        }
    }
    if( AllegroInit.events.type == ALLEGRO_EVENT_MOUSE_AXES )
    {
        this->mouseX = AllegroInit.events.mouse.x;
        this->mouseY = AllegroInit.events.mouse.y;
    }
    if( AllegroInit.events.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN )
    {
        if( AllegroInit.events.mouse.button & 1 )
        {
            if(( mouseX > 650 && mouseX < 700 ) &&( mouseY > 500 && mouseY < 550 ) )
            {
                this->function_type++;
                if( this->function_type > 3 )
                     this->function_type = 0;
               
                this->is_clicked_change = true;
                this->ChangeisClockClickedStatus = clock() + 0.03 * CLOCKS_PER_SEC;
            }
        }
        else if( AllegroInit.events.mouse.button & 2 )
        {
            if(( mouseX > 650 && mouseX < 700 ) &&( mouseY > 500 && mouseY < 550 ) )
            {
                this->function_type--;
                if( this->function_type < 0 )
                     this->function_type = 3;
               
                this->is_clicked_change = true;
                this->ChangeisClockClickedStatus = clock() + 0.03 * CLOCKS_PER_SEC;
            }
        }
       
    }
    if(( mouseX > 10 && mouseX < 60 ) &&( mouseY > 500 && mouseY < 560 ) )
         A += 3.0;
   
    if(( mouseX > 90 && mouseX < 140 ) &&( mouseY > 500 && mouseY < 560 ) )
         A -= 3.0;
   
    if(( mouseX > 210 && mouseX < 260 ) &&( mouseY > 500 && mouseY < 560 ) )
         f += 0.00005;
   
    if(( mouseX > 290 && mouseX < 340 ) &&( mouseY > 500 && mouseY < 560 ) )
         f -= 0.00005;
   
    if(( mouseX > 410 && mouseX < 460 ) &&( mouseY > 500 && mouseY < 560 ) )
         k += 0.1;
   
    if(( mouseX > 490 && mouseX < 540 ) &&( mouseY > 500 && mouseY < 560 ) )
         k -= 0.1;
   
}

void app::update()
{
    if( AllegroInit.events.timer.source == AllegroInit.timer )
    {
        if( this->is_clicked_change && this->ChangeisClockClickedStatus <= clock() )
        {
            this->is_clicked_change = 0;
        }
        this->it_wektor_1 = this->wektor_1.begin();
        this->it_Node = this->Nodes.begin(); //poczatek wektora
        while( this->it_Node != this->Nodes.end(), this->it_wektor_1 != this->wektor_1.end() ) // iterowanie po wektorze
        {
            switch( this->function_type )
            {
            case this->fun_sin:
                this->it_Node->y =( A * sin(( 2.0 * pi * f ) * this->it_Node->x + k ) ) + 300.0; // zwykly sinus
                break;
               
            case this->fun_quadrat:
                this->it_Node->y =(( 4 * A ) / pi ) *
                (
                sin( this->it_Node->x * 2.0 * pi * f + k ) +
                sin( 3.0 * this->it_Node->x * 2.0 * pi * f + 3 * k ) / 3.0 +
                sin( 5.0 * this->it_Node->x * 2.0 * pi * f + 5 * k ) / 5.0 +
                sin( 7.0 * this->it_Node->x * 2.0 * pi * f + 7 * k ) / 7.0 +
                sin( 9.0 * this->it_Node->x * 2.0 * pi * f + 9 * k ) / 9.0 +
                sin( 11.0 * this->it_Node->x * 2.0 * pi * f + 11 * k ) / 11.0 +
                sin( 13.0 * this->it_Node->x * 2.0 * pi * f + 13 * k ) / 13.0 +
                sin( 15.0 * this->it_Node->x * 2.0 * pi * f + 15 * k ) / 15.0 +
                sin( 17.0 * this->it_Node->x * 2.0 * pi * f + 17 * k ) / 17.0 +
                sin( 19.0 * this->it_Node->x * 2.0 * pi * f + 19 * k ) / 19.0 +
                sin( 21.0 * this->it_Node->x * 2.0 * pi * f + 21 * k ) / 21.0 +
                sin( 23.0 * this->it_Node->x * 2.0 * pi * f + 23 * k ) / 23.0 +
                sin( 25.0 * this->it_Node->x * 2.0 * pi * f + 25 * k ) / 25.0 +
                sin( 27.0 * this->it_Node->x * 2.0 * pi * f + 27 * k ) / 27.0 +
                sin( 29.0 * this->it_Node->x * 2.0 * pi * f + 29 * k ) / 29.0 +
                sin( 31.0 * this->it_Node->x * 2.0 * pi * f + 31 * k ) / 31.0 +
                sin( 33.0 * this->it_Node->x * 2.0 * pi * f + 33 * k ) / 33.0 +
                sin( 35.0 * this->it_Node->x * 2.0 * pi * f + 35 * k ) / 35.0 ) +
                + 300;
                break;
               
            case this->fun_saw:
                this->it_Node->y =(( 2 * A ) /( pi * pi ) ) *
                (
                sin(( this->it_Node->x * 2.0 * pi * f + k ) ) -
                sin(( 2.0 * this->it_Node->x * 2.0 * pi * f + 2.0 * k ) ) /( 2.0 ) +
                sin(( 3.0 * this->it_Node->x * 2.0 * pi * f + 3.0 * k ) ) /( 3.0 ) -
                sin(( 4.0 * this->it_Node->x * 2.0 * pi * f + 4.0 * k ) ) /( 4.0 ) +
                sin(( 5.0 * this->it_Node->x * 2.0 * pi * f + 5.0 * k ) ) /( 5.0 ) //-
                //sin((6.0*this->it_Node->x*2.0*pi*f+6.0*k))/(6.0)+
                //sin((7.0*this->it_Node->x*2.0*pi*f+7.0*k))/(7.0)-
                //sin((8.0*this->it_Node->x*2.0*pi*f+8.0*k))/(8.0)+
                //sin((9.0*this->it_Node->x*2.0*pi*f+9.0*k))/(9.0)-
                //sin((10.0*this->it_Node->x*2.0*pi*f+10.0*k))/(10.0)+
                //sin((11.0*this->it_Node->x*2.0*pi*f+11.0*k))/(11.0)-
                //sin((12.0*this->it_Node->x*2.0*pi*f+12.0*k))/(12.0)+
                //sin((13.0*this->it_Node->x*2.0*pi*f+13.0*k))/(13.0)
                ) + 300;
                break;
               
            case this->fun_triangle:
                this->it_Node->y =(( 8 * A ) /( pi * pi ) ) *
                (
                sin(( this->it_Node->x * 2.0 * pi * f + k ) ) -
                sin(( 3.0 * this->it_Node->x * 2.0 * pi * f + 3 * k ) ) /( 3.0 * 3.0 ) +
                sin(( 5.0 * this->it_Node->x * 2.0 * pi * f + 5 * k ) ) /( 5.0 * 5.0 ) -
                sin(( 7.0 * this->it_Node->x * 2.0 * pi * f + 7 * k ) ) /( 7.0 * 7.0 ) +
                sin(( 9.0 * this->it_Node->x * 2.0 * pi * f + 9 * k ) ) /( 9.0 * 9.0 ) -
                sin(( 11.0 * this->it_Node->x * 2.0 * pi * f + 11 * k ) ) /( 11.0 * 11.0 ) +
                sin(( 13.0 * this->it_Node->x * 2.0 * pi * f + 13 * k ) ) /( 13.0 * 13.0 )
                ) + 300;
                break;
               
                /* this->it_wektor_1->y=((8*A)/(pi*pi))*
                (
                sin ((this->it_Node->x*2.0*pi*f+k)) -
                sin((3.0*this->it_Node->x*2.0*pi*f+3*k))/(3.0*3.0)+
                sin((5.0*this->it_Node->x*2.0*pi*f+5*k))/(5.0*5.0)  -
                sin((7.0*this->it_Node->x*2.0*pi*f+7*k))/(7.0*7.0)+
                sin((9.0*this->it_Node->x*2.0*pi*f+9*k))/(9.0*9.0)  -
                sin((11.0*this->it_Node->x*2.0*pi*f+11*k))/(11.0*11.0)+
                sin((13.0*this->it_Node->x*2.0*pi*f+13*k))/(13.0*13.0)
                )+300;*/
               
            }
            this->it_wektor_1->y =(( 8 * A ) /( pi * pi ) ) *
            (
            sin(( this->it_Node->x * 2.0 * pi * f + k ) ) -
            sin(( 3.0 * this->it_Node->x * 2.0 * pi * f + 3 * k ) ) /( 3.0 * 3.0 ) +
            sin(( 5.0 * this->it_Node->x * 2.0 * pi * f + 5 * k ) ) /( 5.0 * 5.0 ) -
            sin(( 7.0 * this->it_Node->x * 2.0 * pi * f + 7 * k ) ) /( 7.0 * 7.0 ) +
            sin(( 9.0 * this->it_Node->x * 2.0 * pi * f + 9 * k ) ) /( 9.0 * 9.0 ) -
            sin(( 11.0 * this->it_Node->x * 2.0 * pi * f + 11 * k ) ) /( 11.0 * 11.0 ) +
            sin(( 13.0 * this->it_Node->x * 2.0 * pi * f + 13 * k ) ) /( 13.0 * 13.0 )
            ) + 300;
            if( this->it_Node->x > 800 )
                 this->it_Node->x = 0;
           
            this->it_Node++;
           
            if( this->it_wektor_1->x > 800 )
                 this->it_wektor_1->x = 0;
           
            this->it_wektor_1++;
        }
        value = 0;
        for( int i = 0; i <= 799; ++i )
        {
            for( int j = 0; j < SizeOfvalueToCheck; j++ )
            {
                if(( wektor_1[ i ].y &( 1 << j ) ) ==( Nodes[ i ].y &( 1 << j ) ) && wektor_1[ i ].y == Nodes[ i ].y )
                     value += 1;
               
            }
        }
        cout << "value: " <<( value ) / 32.0 / 800.0 << endl;
        cout << endl;
    }
}

void app::draw()
{
    if( AllegroInit.events.timer.source == AllegroInit.timer )
    {
        al_draw_line( 0, 300, 800, 300, al_map_rgb( 255, 0, 0 ), 1.0 );
        this->it_wektor_1 = this->wektor_1.begin();
        while( this->it_wektor_1 != this->wektor_1.end() )
        {
            al_draw_pixel( this->it_wektor_1->x, this->it_wektor_1->y, al_map_rgb( 255, 255, 255 ) );
            this->it_wektor_1++;
        }
        this->it_Node = this->Nodes.begin();
        while( this->it_Node != this->Nodes.end() )
        {
            al_draw_pixel( this->it_Node->x, this->it_Node->y, al_map_rgb( 255, 255, 255 ) );
            this->it_Node++;
        }
        if(( mouseX > 10 && mouseX < 60 ) &&( mouseY > 500 && mouseY < 560 ) )
             al_draw_tinted_bitmap( this->AllegroInit.arrow, al_map_rgba_f( 1.0, 0.0, 0.0, 1.0 ), 10, 500, 0 );
        else
             al_draw_bitmap( this->AllegroInit.arrow, 10, 500, 0 );
       
        if(( mouseX > 90 && mouseX < 140 ) &&( mouseY > 500 && mouseY < 560 ) )
             al_draw_tinted_bitmap( this->AllegroInit.arrow, al_map_rgba_f( 1.0, 0.0, 0.0, 1.0 ), 90, 500, 3 );
        else
             al_draw_bitmap( this->AllegroInit.arrow, 90, 500, 3 );
       
        if(( mouseX > 210 && mouseX < 260 ) &&( mouseY > 500 && mouseY < 560 ) )
             al_draw_tinted_bitmap( this->AllegroInit.arrow, al_map_rgba_f( 1.0, 0.0, 0.0, 1.0 ), 210, 500, 0 );
        else
             al_draw_bitmap( this->AllegroInit.arrow, 210, 500, 0 );
       
        if(( mouseX > 290 && mouseX < 340 ) &&( mouseY > 500 && mouseY < 560 ) )
             al_draw_tinted_bitmap( this->AllegroInit.arrow, al_map_rgba_f( 1.0, 0.0, 0.0, 1.0 ), 290, 500, 3 );
        else
             al_draw_bitmap( this->AllegroInit.arrow, 290, 500, 3 );
       
        if(( mouseX > 410 && mouseX < 460 ) &&( mouseY > 500 && mouseY < 560 ) )
             al_draw_tinted_bitmap( this->AllegroInit.arrow, al_map_rgba_f( 1.0, 0.0, 0.0, 1.0 ), 410, 500, 0 );
        else
             al_draw_bitmap( this->AllegroInit.arrow, 410, 500, 0 );
       
        if(( mouseX > 490 && mouseX < 540 ) &&( mouseY > 500 && mouseY < 560 ) )
             al_draw_tinted_bitmap( this->AllegroInit.arrow, al_map_rgba_f( 1.0, 0.0, 0.0, 1.0 ), 490, 500, 3 );
        else
             al_draw_bitmap( this->AllegroInit.arrow, 490, 500, 3 );
       
        if( !is_clicked_change )
             al_draw_bitmap( this->AllegroInit.arrow2, 650, 500, 3 );
        else
             al_draw_tinted_bitmap( this->AllegroInit.arrow2, al_map_rgba_f( 1.0, 0.0, 0.0, 1.0 ), 650, 500, 3 );
       
        al_draw_text( font, al_map_rgb( 0, 255, 255 ), 10, 550, NULL, "amplituda" );
        al_draw_text( font, al_map_rgb( 0, 255, 255 ), 220, 550, NULL, "pulsacja" );
        al_draw_text( font, al_map_rgb( 0, 255, 255 ), 420, 550, NULL, "przesuniecie" );
        al_flip_display();
        al_clear_to_color( al_map_rgb( 0, 0, 0 ) );
    }
}




P-143380
DejaVu
» 2016-01-12 17:31:38
P-143400
aaadam
Temat założony przez niniejszego użytkownika
» 2016-01-12 20:34:30
dostałem zadanie że mam sprawdzić bit po bicie różnice jednego sygnału od drugiego bez modulacji czy innych rzeczy.
np sygnał 1:
101010101011000000000110101010101010101
np sygnał 2:
101010101011000000000110101010111111111
                                                  /\
to różnica zaczyna się tutaj            |
i w tym przypadku wynosi 4 bity a sygnał ma 30 znaków czyli wychodzi 4/30 czyli 0.13(33)

w programie porównuje np sygnał piłokształtny z sinusem ale jakieś bzdurne wartości mi wychodzą
P-143407
mateczek
» 2016-01-12 21:24:29
nie wiem czy dobrze zrozumiałem ale krótki kod z pomocniczą klasą bittsArray
C/C++
#include <iostream>
using namespace std;
class BitsArray
{
    int data;
public:
   
    BitsArray( int _data = 0 ) { data = _data; }
    void fromNumer( int numer ) { data = numer; }
    bool operator []( int bitNumer ) {
        return data & 1 << bitNumer;
    }
};
int main()
{
    BitsArray a( 4294967295 ); //zmienna int bitowo 11111111111111111111111111111111
    BitsArray b( 4294443007 ); //rowniez int bitowo 11111111111101111111111111111111
    int bitErrorCount = 0;
    for( int i = 0; i < 32; i++ ) {
        if( b[ i ] != a[ i ] ) bitErrorCount++;
       
    }
    cout << bitErrorCount << endl;
}
P-143409
mateczek
» 2016-01-12 23:03:32
PS tak sobie pomyślałem że zawsze można zrobić XOR między liczbami i policzyć jedynki !!!
xor daje jedynkę tam gdzie bity są różne, a zero tam gdzie bity są identyczne.

C/C++
#include <iostream>
using namespace std;
class BitsArray
{
    int data;
public:
   
    BitsArray( int _data = 0 ) { data = _data; }
    void operator =( int numer ) { data = numer; }
    bool operator []( int bitNumer ) {
        return data & 1 << bitNumer;
    }
};
int main()
{
    BitsArray tablBitow;
    int a = 4294967295;
    int b = 0;
   
    tablBitow = a xor b; //zawsze można walnąć xor i policzyć jedynki
   
    int bitErrorCount = 0;
    for( int i = 0; i < 32; i++ ) {
        if( tablBitow[ i ] == true ) bitErrorCount++;
       
    }
    cout << bitErrorCount << endl;
}
P-143419
aaadam
Temat założony przez niniejszego użytkownika
» 2016-01-13 20:59:41
dzięki tyle wystarczy :)
P-143478
« 1 »
  Strona 1 z 1