{"id":35813,"date":"2013-05-21T07:34:16","date_gmt":"2013-05-21T05:34:16","guid":{"rendered":"http:\/\/www.cqdx.ru\/ham\/?p=35813"},"modified":"2023-09-26T15:53:43","modified_gmt":"2023-09-26T13:53:43","slug":"diy-ssb-by-raspberrypi","status":"publish","type":"post","link":"https:\/\/www.cqdx.ru\/ham\/diy\/diy-ssb-by-raspberrypi\/","title":{"rendered":"DIY: SSB by RaspberryPI"},"content":{"rendered":"<p><a href=\"https:\/\/www.cqdx.ru\/ham\/wp-content\/uploads\/2013\/05\/sdr.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-35814 \" title=\"sdr\" src=\"https:\/\/www.cqdx.ru\/ham\/wp-content\/uploads\/2013\/05\/sdr-1024x367.png\" alt=\"\" width=\"597\" height=\"214\" srcset=\"https:\/\/www.cqdx.ru\/ham\/wp-content\/uploads\/2013\/05\/sdr-1024x367.png 1024w, https:\/\/www.cqdx.ru\/ham\/wp-content\/uploads\/2013\/05\/sdr-300x108.png 300w, https:\/\/www.cqdx.ru\/ham\/wp-content\/uploads\/2013\/05\/sdr-768x276.png 768w, https:\/\/www.cqdx.ru\/ham\/wp-content\/uploads\/2013\/05\/sdr.png 1176w\" sizes=\"auto, (max-width: 597px) 100vw, 597px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">The original idea (as seen above) was to implement a complete SSB modulator and demodulator with software in a ATTINY45 micro-controller chip and a AD9834 as DDS. The software samples microphone signal with ADC and then derives the amplitude and phase of the audio signal. The amplitude and phase extraction is derived from the in-phase microphone signal and its 90 degree phase shifted quadrature signal (created by a Hilbert transform on the in-phase signal). The resulting phase is replicated on the oscillator signal of the DDS, and the amplitude information is used to change the drive-strength (current) of the DDS. The output of the DDS is representing a clean single side-band output SSB near the configured frequency.<\/p>\n<p style=\"text-align: justify;\">To proof this idea is working, I implemented the algorithm on a RaspberryPi. In the RaspberryPi setup there is no DDS, but there is a digital-PLL on the micro-processor SoC which we can use for RF generation. By manipulating the Integer and Fractional dividers, a frequency can be generated from 0 to 250 MHz on GPIO4 pin with a resolution of about 20 Hz at 7 MHz. By alternating the Fractional divider between two nearby values, the resolution can be further increased to micro-Hz level; for this a 32 bit clock at 32 MHz is used to generate a PWM alike switching pattern between the two Fractional divider values.<\/p>\n<p style=\"text-align: justify;\">The PLL oscillator can be phase modulated by short manipulations of the configured frequency. Increasing the frequency temporarily and then restoring to its original frequency, will shift the phase upwards, while decreasing the frequency temporarily will decrease the phase of the signal.<br \/>\nIn this way the phase information for generating a SSB signal can be applied to the RaspberryPi PLL by means of frequency modulation. To do so, first phase differences are calculated for every sample. For each phase deviation (difference) the corresponding frequency change is calculated. This is dependent on the rate that the PLL is changed from frequency; the exact formula is: dev_freq_hz = dev_phase_rad * samp_rate_hz \/ (2 * pi)<\/p>\n<p style=\"text-align: justify;\">The amplitude signal can be applied by changing the drive-strength of the GPIO4 port, which has 8 levels with a dynamic range of about 13 dB. After some experimenting, amplitude information can be completely rejected, instead the frequency must be placed outside the single side band (e.g. placed to center freq). In this case single side band is generated wihout suppressed carrier, i.e. a constant amplitude envelope is applied (good to prevent RF interference). In this case the audio quality does not seem to suffer from this constant amplitude, and the audio quality becomes even better by applying a little-bit of noise to the microphone input. My impression is that using SSB with constant amplitude increases the readability when the signal is just above the noise.<\/p>\n<p style=\"text-align: justify;\">The RaspberryPi receives the Microphone input via an external USB sound device. To improve the SSB quality, the signal is companded by a A-law compression technique. Three parallel BS170 MOSFETs where directly driven by RaspberryPi GPIO4 output to create about 1Watt of RF. On 40m I could made several SSB contacts through Europe using this setup, receiving stations back by using a nearby online WebSDR receiver. From my location in south-Netherlands following contacts where made:<\/p>\n<p>Apr 27 14:00 40m on4azw\/p<br \/>\nApr 27 14:00 40m pd6king<br \/>\nApr 27 14:00 40m pa150ba<br \/>\nApr 27 14:00 40m hb9ag<br \/>\nApr 27 14:00 40m pd2edr<br \/>\nApr 28 13:22 40m m0zag<br \/>\nApr 28 13:22 40m g100rsgb<br \/>\nApr 28 13:22 40m hb9efx<br \/>\nApr 28 13:22 40m pa3zax<br \/>\nApr 28 13:22 40m tm02ref<br \/>\nApr 28 16:00 20m ea2dt<br \/>\nApr 29 19:00 40m g3mlo<br \/>\nApr 30 10:23 7100 pc1king<br \/>\nApr 30 16:42 7082 pa2cvd<br \/>\nApr 30 17:00 7092 dl9fcs Gazi, Frankfurt 57<br \/>\nApr 30 18:30 7074 pa3a Arie, Barendrecht<br \/>\nMay 4 11:52 7107 g100c<br \/>\nMay 9 15:20 7077 dl\/pc1mk Menno, Borkum<\/p>\n<p>Below a fragment of the code that generates SSB signal in the form of amplitude and frequency deviation information, based on the inputed audio signal:<\/p>\n<p>#define ln(x) (log(x)\/log(2.718281828459045235f))<\/p>\n<p>static int xv[45];<\/p>\n<p>void filter(int val, int* i, int* q)<br \/>\n{<br \/>\nint j;<\/p>\n<p>for (j = 0; j &lt; 44; j++) { xv[j] = xv[j+1]; } xv[44] = val; *i = xv[22]; int _q = (xv[1] + xv[3] + xv[5] + xv[7]+xv[7] + 4*xv[9] + 6*xv[11] + 9*xv[13] + 14*xv[15] + 23*xv[17] + 41*xv[19] + 127*xv[21] &#8211; (127*xv[23] + 41*xv[25] + 23*xv[27] + 14*xv[29] + 9*xv[31] + 6*xv[33] + 4*xv[35] + xv[37]+xv[37] + xv[39] + xv[41] + xv[43]) ) \/ 202; *q = _q; } int arctan2(int y, int x) { int abs_y = abs(y); int angle; if(x &gt;= 0){<br \/>\nangle = 45 &#8211; 45 * (x &#8211; abs_y) \/ ((x + abs_y)==0?1:(x + abs_y));<br \/>\n} else {<br \/>\nangle = 135 &#8211; 45 * (x + abs_y) \/ ((abs_y &#8211; x)==0?1:(abs_y &#8211; x));<br \/>\n}<br \/>\nreturn (y &lt; 0) ? -angle : angle; \/\/ negate if in quad III or IV } static float t = 0; static float prev_f = 0; static float prev_phase = 0; static float acc = 0; void ssb(float in, float fsamp, float* amp, float* df) { int i, q; float phase; t++; filter(in * 128, &amp;i, &amp;q); *amp = sqrt( i*i + q*q) \/ 128.0f; if(*amp &gt; 1.0){<br \/>\nprintf(&#8220;amp overflow %fn&#8221;, *amp);<br \/>\n*amp = 1.0;<br \/>\n}<br \/>\nphase = M_PI + ((float)arctan2(q,i)) * M_PI\/180.0f;<br \/>\nfloat dp = phase &#8211; prev_phase;<br \/>\nif(dp &lt; 0) dp = dp + 2*M_PI;<br \/>\nprev_phase = phase;<\/p>\n<p>*df = dp*fsamp\/(2.0f*M_PI);<br \/>\n}<\/p>\n<p>void main(){<br \/>\nint samplerate = 8000; \/\/ set sample-rate of microphone input here, use 4800 to 8000<br \/>\nint notvi = 0; \/\/ set no TVI to true if you want constant carrier<\/p>\n<p>for(;;) {<br \/>\nfloat df, amp;<\/p>\n<p>int data = \/\/16 bit microphone input here<br \/>\nssb((float)data\/32767.0, samplerate, &amp;amp, &amp;df);<\/p>\n<p>float A = 87.7f; \/\/ compression parameter<br \/>\namp = (fabs(amp) &lt; 1.0f\/A) ? A*fabs(amp)\/(1.0f+ln(A)) : (1.0f+ln(A*fabs(amp)))\/(1.0f+ln(A)); \/\/compand<\/p>\n<p>int ampval = (int)(round(amp * 8.0f)) &#8211; 1;<br \/>\nint enaval = (ampval &lt; 0) ? 0 : 1;<\/p>\n<p>if(notvi &amp;&amp; ampval &lt; 0){ enaval = 1; \/\/ tx always on df = 0; } if(notvi) ampval = 7; \/\/ optional: no amplitude changes if(ampval&gt;7) ampval=7;<br \/>\nif(ampval<\/p>\n<p>\/\/ here, send ampval to 3 bit drive-strength register (if available)<br \/>\n\/\/ here, add or substract df from PLL center frequency (in Hz), adding will make USB, substract. LSB<br \/>\n}<br \/>\n}<\/p>\n<p>Author: Guido PE1NNZ<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The original idea (as seen above) was to implement a complete SSB modulator and demodulator with software in a ATTINY45 micro-controller chip and a AD9834 as DDS. The software samples microphone signal with ADC and then derives the amplitude and phase of the audio signal. The amplitude and phase extraction is derived from the in-phase&hellip;<\/p>\n","protected":false},"author":2,"featured_media":35814,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[2],"tags":[377],"class_list":["post-35813","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-diy","tag-raspberry","category-2","description-off"],"_links":{"self":[{"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/posts\/35813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/comments?post=35813"}],"version-history":[{"count":0,"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/posts\/35813\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/media\/35814"}],"wp:attachment":[{"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/media?parent=35813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/categories?post=35813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cqdx.ru\/ham\/wp-json\/wp\/v2\/tags?post=35813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}