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 ? 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 #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(); while( this->it_Node != this->Nodes.end(), this->it_wektor_1 != this->wektor_1.end() ) { 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; 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 ) ) + 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; 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 ) ); } }
|