predator/channelz.c
2021-10-28 07:58:56 +10:00

49 lines
1.3 KiB
C

#include <stdio.h>
#include <math.h>
int main(void)
{
char sn_ratio[20];
float ratio ;
/*ratio is the sn_r expressed as an actual ratio, not dB */
char bwidth[20];
float bandwidth;
float channels;
char chan[20];
float bits_per_sec;
float dB;
/*get the nums*/
printf("How many Hz of bandwidth is available?\n");
if (fgets(bwidth,20,stdin) == NULL) { exit(1);}
printf("What's the signal/noise ratio (NOT in db, eg 30dB=1000) ?\n");
if (fgets(sn_ratio,20,stdin) == NULL) { exit(1); }
printf("How many channels exhibit these parameters in your system?\n");
if (fgets(chan,20,stdin) == NULL) { exit(1); }
/*conv to values*/
ratio=atoi(sn_ratio);
bandwidth=atoi(bwidth);
channels=atoi(chan);
dB= log10(ratio)*10;
printf(" B/W : %f Hz , SNR : %f dB\n\n",bandwidth, dB);
/*shannon's law is expressed in terms of log2(x) hence fiddly conversion*/
bits_per_sec= (log10(ratio +1) / log10 (2)) * bandwidth;
printf("Total bits per second per channel is %.2f bps\n\n", bits_per_sec);
printf("Total throughput for combined channels is %.2f kbps \n",
((bits_per_sec * channels)/1024) );
printf("which is equal to %.2f Megabits/sec \n",
(((bits_per_sec * channels)/1024)/1024));
printf("which is equal to %.2f Megabytes/sec \n",
(((bits_per_sec * channels)/1024)/1024)/8);
return 0;
}