Appendix C: Solutions to Selected Exercises

 < Day Day Up > 



Solutions to selected exercises given in various chapters are provided in this Appendix. For exercises involving software development, the source code listings are given. For exploratory exercises, references to Internet resources are provided.

CHAPTER 1

  1. To generate a bit stream of 1s and 0s, you can write a program that takes characters as input and produces the ASCII bit stream. A segment of the VC++ code is given in Listing C.1. The screenshot for this program is given in Figure C.1. Please note that you need to create your own project file in VC++ and add the code given in Listing C.1.

click to expand
Figure C.1: Screenshot that displays the input text and equivalent ASCII code.

Listing C.1: To generate a bit stream of 1s and 0s.

start example
 /* Converts the text into ASCII */ CString CAsciiMy::TextToAscii(CString text) {    CString ret_str, temp_str;    int length, temp_int=0;    length=text.GetLength();    for(int i=0;i<length;i++){       temp_int=text.GetAt(i);       temp_str=ConvertBase(temp_int,2);       ret_str=ret_str+temp_str;    }    return ret_str; } CString CAsciiMy::ConvertBase(int val, int base) {    CString ret_str, temp_str;    int ret_val=0;    int temp=val;    while(1){       if(temp>0){          temp_str.Format("%d",temp%base);          ret_str=temp_str+ret_str;          temp=temp/base;       }       else             break;    }    while(ret_str.GetLength()<7){       ret_str="0"+ret_str;    }    return ret_str; } 
end example

  1. To generate noise, you need to write a program that generates random numbers. The random numbers can be between –1 and +1. Listing C.2 gives the VC++ code segment that does this. You need to create a project file in the VC++ environment and add this code. The waveform of the noise generated using this program is shown in Figure C.2.

click to expand
Figure C.2: Waveform of the noise signal.

Listing C.2: To generate random numbers between –1 and +1 and display the waveform.

start example
 /* To display the signal on the screen */ int CNoise_signalDlg::NoiseFunction() {    CWindowDC dc(GetDlgItem(IDC_SINE));    CRect rcClient;    LOGBRUSH logBrush;    logBrush.lbStyle =BS_SOLID;    logBrush.lbColor=RGB(0,255,0);    CPen pen(PS_GEOMETRIC | PS_JOIN_ROUND,1, &logBrush);    dc.SelectObject(&pen);    dc.SetTextColor(RGB(255,255,255));    while(continueThread){       m_sine.GetClientRect(rcClient);       dc.FillSolidRect(rcClient, RGB(0,0,0));       dc.MoveTo(0,rcClient.bottom/2);       int x, y;       dc.MoveTo(0,rcClient.bottom/2);       for (x =0 ; x < (rcClient.right); x++) // display Input       {          y = rcClient.bottom/2 - Noise();          dc.LineTo(x, y);       }       Sleep(200);    }    return 0; } /* To generate the noise signal */ int CNoise_signalDlg::Noise() {    int NISample;    double NSample;    double N2PI = 2*TPI;    double NWT;    NoiseFreq = 300+rand()%4300;    NoiseAMP = 8+rand()%32;    NWT = NoiseFreq*0.00125;    NSampleNo++;    NSample =NoiseAMP*sin(N2PI*NWTn);    NWTn += NWT;    if (NWTn > 1.0) NWTn -= 1.0;    NISample = (int) NSample;    return NISample; } 
end example

  1. To simulate a transmission medium, you need to modify the bit stream at random places by converting 1 to 0 and 0 to 1. Listing C.3 gives VC++ code segment that generates the bit stream and then introduces errors at random places. Figure C.3 gives the screenshot that displays the original bit stream and the bit stream with errors.

click to expand
Figure C.3: Screenshot that displays the original bit stream and the bit stream with errors.

Listing C.3: To simulate a transmission medium.

start example
    /* To convert the text into bit stream and introduce errors in the bit stream */    void CBitStreamDlg::OnDisplay()    {       // TODO: Add your control notification handler code here       CString strdata, binary, s, ss, no;       int bit, i=0, count=0;       char ch;       m_text.GetWindowText(strdata);       for(int j=0;j<strdata.GetLength();j++)       {          ch=strdata[j];          for(int k=0;k<8;i++,count++,k++)          {             bit = ch%2;             bin_val[i]=bit;             ch=ch/2;             s.Format("%d",bin_val[i]);             binary = binary + s;       }    }    m_bin_data.SetWindowText(binary);    for(int n=0;n<10;n++)    {       int ran_no;       srand((unsigned)time( NULL ) );       ran_no = rand() % 100;       ss.Format("%d",ran_no);       AfxMessageBox(ss);       no = no + "," + ss;       if(bin_val[ran_no]==0)             bin_val[ran_no]=1;       else             bin_val[ran_no]=0;    }    CString bin1;    for(i=0;i<104;i++)    {       s.Format("%d",bin_val[i]);       bin1 = bin1 + s;    }    m_con_text.SetWindowText(bin1);    m_Random_no.SetWindowText(no); } 
end example

  1. Many semiconductor vendors provide integrated circuits that generate noise in the audio frequency band. Suppliers of measurement equipment provide noise generators used for testing communication systems. The best way to generate noise is through digital signal processors.



 < Day Day Up > 



Principles of Digital Communication Systems and Computer Networks
Principles Digital Communication System & Computer Networks (Charles River Media Computer Engineering)
ISBN: 1584503297
EAN: 2147483647
Year: 2003
Pages: 313
Authors: K V Prasad

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net