DSPRelated.com
Forums

Matlab code needed for SSB demodulation

Started by Rick Lyons June 30, 2012
On Tue, 03 Jul 2012 00:35:42 -0400, robert bristow-johnson wrote:

> On 7/3/12 12:03 AM, Jerry Avins wrote: >> On 7/2/2012 7:57 AM, Rick Lyons wrote: >> >>> ... What I'm tryin' to do is understand, >>> and model, the various schemes I've encountered on the Internet for >>> demodulating real-valued bandpass SSB signals. >> >> I listened to SSBSC with my short-wave portable by using the BFO. > > i was trying to remember what that was called. Beat Frequency > Oscillator. i called it my "local oscillator", not quite right.
The local oscillator is the signal that mixes with the signal at the antenna, to get the intermediate frequency signal. The BFO is mixed with the signal at the end of the intermediate frequency chain to get audio. If there's more than one IF, then the terminology is for "first LO" and "second LO", etc. -- Tim Wescott Control system and signal processing consulting www.wescottdesign.com
On 3.7.12 7:03 , Jerry Avins wrote:
> On 7/2/2012 7:57 AM, Rick Lyons wrote: > >> ... What I'm tryin' to do is understand, >> and model, the various schemes I've encountered >> on the Internet for demodulating real-valued >> bandpass SSB signals. > > I listened to SSBSC with my short-wave portable by using the BFO. It > works well when it is tuned to the where the suppressed carrier would > have been. Otherwise, quack quack. Distortion is low provided the BFO > level is high enough. I once built an analog SSB phasing detector for > use with weak AM signals that was straight out of the ARRL Handbook. The > brain is a wonderful filter. By sending the upper sideband to one ear > and the lower to the other, an AM signal made unintelligible by noise > came through well. The brain extracted what was common to both ears and > ignored what was different. If the problem was an interfering signal on > one side of the carrier, the other sideband could be sent to both ears. > > Jerry
BFO is just one of the frequencies combined to effect the carrier substitution. Actually, the name comes from the time of CW Morse code usage, when the BFO was used on an AM receiver to make the transmission audible (instead of the pffft pffft ...). In the early days of SSB, there were commercial systems using a small amount of pilot carrier for receiver phase locking. Also, a DSBSC (double sideband suppressed carrier) transmission has enough redundancy to permit phase locking. It it also necessary to have an exact frequency and a good phase lock to detect a DSB signal with little distortion. The analog phase lock AM reception built by Jerry belongs into this group. We used similar receivers to listen to Radio Luxembourg in the era of European state monopoly radios. -- -Tauno
>On 7/1/12 r b-j wrote:
[Snipped by Lyons] Hi Robert,
>i'm unfamiliar with Weaver or Tim's "regular". i know how we did it in >analog with ham-radio gear in the 70s. with an IF frequency of, i >dunno. it's wasn't 455 kHz (that was my old shortwave radio). i think >it was around 3 MHz and we had a helluva sharp "crystal-lattice filter" >with piezo "XTAL"s. > >with a good baseband filter, you can do it with a *real* mix. > >let xq(t) be the Hilbert transform of xi(t). the real IF (for USB) is > > > v(t) = xi(t)*cos(w0*t) - xq(t)*sin(w0*t) > > = Re{ (xi(t) + j*xq(t)) * e^(j*w0*t) }
Ok. That seems to be the standard way of generating a real-valued upper sideband SSB signal at an RF freq of w0.
>now you can multiply ("mix" using old-fashioned comm lingo) v(t) with >cos(w0*t) (assuming you have no sync problem) and filter out the >high-frequency images leaving only the base band. > > > v(t)*cos(w0*t) = xi(t)*(cos(w0*t))^2 - xq(t)*sin(w0*t)*cos(w0*t) > > = 1/2*( xi(t) + xi(t)*cos(2*w0*t) - xq(t)*sin(2*w0*t) ) > >it's not hard to get xi(t) from that to an arbitrary postive limit of >error (and some delay).
Yes, and *THAT* is what's surprising me. All the 'SSB demod' literature I've found so far describes SSB demodulation as needing Hilbert transformation, complex down-conversion, and some sort of digital filtering. But my Matlab modeling seems to indicate that SSB demodulation can be performed by simple real-valued mixing (your cos(w0*t)) and lowpass filtering. (Of course, this is assuming a copy of the 'w0' carrier freq is available at the receiver.) At this point I don't understand why all the SSB demod literature's methods (including Frerking's book) are significantly more complicated than what you described above.
>in fact, if you were to do this using complex arithmetic, from a real >IF, v(t), you end up doing it mathematically equivalently, because you >have to separate xi(t)*cos(w0*t) from xq(t)*sin(w0*t) and that requires >"mixing" and filtering v(t).
[Snipped by Lyons] Thanks Robert, [-Rick-]
 On 7/2/2012, Mark wrote:

>>PS. As far as I can tell, your 'myhilbert()' >>function does not produce the same results >>as Matlab's 'hilbert()' function. Or am >>I missing something?=20 > >Yes, it differs due to a careless typo on my part. >The line before the return statement should read: > >y =3D ifft(Y); > >instead I carelessly wrote: y =3D ifft(x); > >With this correction results should match Matlab's hilbert() function to
wi=
>thin rounding.
Ah, OK. Great. (I probably should have seen that simple typo myself.)
>>Hi, >> because I'm using the dsprelated.com web site to >>access the newsgroup here, I'm unable to determine >>to whom I'm replying.=20 > >Yes, I'm a long time reader (and big fan) of your posts, books, tips and
tr=
>icks etc. I'm not much of a poster but thought I could help out with this
=
>particular question. I'm accessing this forum through Google Groups which
=
>not only makes it impossible for you to know to whom you're replying but
al=
>so seems to corrupt my text with what looks like formatting characters.
So=
>rry for that.
Yea, I've often noticed those strange, oddball, charaters in some comp.dsp posts. It's too bad that in 2012 some software is unable to display simple ASCII characters.
>If you're still having problems and explain more about the inconsistencies
=
>you're seeing in your model perhaps I could better help. > >Sincere regards. >Mark
Thanks for the offer. When I return to my office I may well take you up on your offer. See Ya', [-Rick-]
>On 2.7.12 Tauno wrote: >>> >> Rick, maybe the hard part of the problem is FINDING THE CARRIER >> FREQUENCY! I just ASSUMED one knows the carrier frequency. In reality,
I
>> don't know what you'd do to get a carrier lock on a SSB (suppressed >> carrier) signal. >> > >There is no means (except the listening ham's ears), if there is >the sideband signal alone. It is a frequency-shifted copy of the >baseband (maybe inverted for LSB). An automatick lock would need >some kind of pre-known redundancy in the signal. > >For audio modulation, the carrier should be correct within a few >tens of Hz to sound intelligible. > >Rick, it seems to me that you're making a simple thing far too >complicated - it is just a complex frequency translation. See >the excellent Lyons' book for details. > >Tauno Voipio, OH2UG
Hi Tauno, You may be right. My standard operating procedure is (to paraphrase a famous quote by Albert Einstein): "Make things as complicated as possible, but not too complicated." [-Rick-]
>On Mon, 02 Jul 2012 Eric wrote: > >>On 2.7.12, Tauno wrote: > >>Rick, it seems to me that you're making a simple thing far too >>complicated - it is just a complex frequency translation. See >>the excellent Lyons' book for details. > >Yeah, Rick could learn a thing or two from that Lyons guy... > >;) > >Eric Jacobsen
Hi Eric, I glad you and Tauno are having fun here. :-) :-). [-Rick-]
>Most hams know, for voice communications, a clean speech signal is
intelligible even with 200 Hz or more carrier frequency error.
> >I've pasted a simple demo passband SSB model with link to voice cut used
to test. The example I ran used 250 Hz carrier frequency error at the receiver LO. Sounds funny but still intelligible.
> >function [musb,mlsb,mpbu,mpbl,mhatu,mhatl,mhatam] = demo_ssb(m,ferr) >% Simple passband SSB model for demonstration >% m is the baseband (modulating) signal >% ferr is the LO tuning error at the receiver in Hz >% musb,mlsb are the baseband USB and LSB signals >% mpb_u, mpb_l are the passband USB, LSB signals >% mhatam is the result of AM envelope detection on the SSB signal >% >% Tested with wav file male.wav (link=eng2_m, fs=8khz, 16 bits/sample) >% from http://www.signalogic.com/index.pl?page=codec_samples >% >% Example run with 250 Hz LO error: >% >> [x,fs,nbits]=wavread('male.wav'); >% >> m = x(1:2e5); % first 25 seconds >% >> [musb,mlsb,mpbu,mpbl,mhatu,mhatl,mhatam] = demo_ssb(m, 250); >% >> wavplay(mhatl,fs); % recovered usb with 250 Hz error >% >> wavplay(mhatu,fs); % recovered lsb with 250 Hz error >% >> wavplay(mhatam,fs); % using AM envelope detection (garbled) > >% Force row-vector with even length >m = m(:).'; >m = m(1:2*floor(length(m)/2)); > >% Baseband transmitter model at sampling freq fsbb >musb = myhilbert(m); >mlsb = conj(musb); > >%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >% Passband Tx at center freq fcif and sampling freq fsif >% pick some values for baseband,IF sampling freqs and IF center freq >fsbb=8e3; >fsif=200e3; > >% upsample baseband signal to IF sampling freq to prep for mix >% Note: fsif/fsbb rational >[P,Q]=rat(fsif/fsbb); >[m2u,bu] = resample(musb,P,Q); >[m2l,bu] = resample(mlsb,P,Q); > >% create LO for mix (LO at 80 kHz for this example) >fcif=80e3; >nn = (0:length(m2u)-1); >lo = exp(j*2*pi*fcif/fsif*nn); > >% up-mix >mpbu = sqrt(2)*real( m2u .* lo ); % Passband USB >mpbl = sqrt(2)*real( m2l .* lo ); % Passband LSB > >%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >% Add channel impairments (use AWGN @ SNR=10dB for this example) >snr = 10; % 10 linear ratio = 10 dB >nscale = sqrt(var(mpbu)/10); >noiseu = nscale*randn(size(mpbu)); >noisel = nscale*randn(size(mpbl)); >rxu = mpbu + noiseu; >rxl = mpbl + noisel; > >%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% >% Process passband Rx at center freq fcif and sampling freq fsif >% model Rx LO freq and phase error, ferr and phierr >% even at freq error = 250 Hz, no problem understanding clean speech >phierr = (0/16)*pi; >lorx = exp(-j*(2*pi*(fcif+ferr) + phierr)/fsif*nn); > >% down-mix >musb_iq_hi = sqrt(2)*(rxu .* lorx); >mlsb_iq_hi = sqrt(2)*(rxl .* lorx); > >% down-sample >musb = resample(musb_iq_hi,Q,P); >mlsb = resample(mlsb_iq_hi,Q,P); > >% Baseband receiver model >mhatu = real(musb); >mhatl = real(mlsb); > >% AM envelope detection (garbled audio) >mhatam = abs(musb); > >% << END >> > >function y = myhilbert(x) >% Note: x is a row vector and length(x) must be even >X=fft(x); >W=[1 2*ones(1,length(x)/2-1) 1 zeros(1,length(x)/2-1)]; >Y = X.*W; >y = ifft(Y); >return
Hi, Thanks! I'll definitely experiment with the above code of yours. [-Rick-]
>>On 7/3/12 Rick wrote:
[Snipped by Lyons]
> >Yes, and *THAT* is what's surprising me. All >the 'SSB demod' literature I've found so far >describes SSB demodulation as needing >Hilbert transformation, complex down-conversion, >and some sort of digital filtering. But my >Matlab modeling seems to indicate that SSB >demodulation can be performed by simple >real-valued mixing (your cos(w0*t)) and >lowpass filtering. (Of course, this is >assuming a copy of the 'w0' carrier freq >is available at the receiver.) > >At this point I don't understand why all the >SSB demod literature's methods (including >Frerking's book) are significantly more >complicated than what you described above.
Oops, I spoke too soon. I just now (3:40 AM, 7/3/12) encountered a description of the 'simple real-valued mixing and lowpass filtering' on page 284 of my copy of the Frerking book. [-Rick-]
On 3.7.12 12:59 , Rick Lyons wrote:

> At this point I don't understand why all the > SSB demod literature's methods (including > Frerking's book) are significantly more > complicated than what you described above.
> [-Rick-]
That's OK as long as there is nothing else on the band. For a simple real mixing you'll get an image response band from the other side of the re-injected carrier. The complex multiply / frequency shift is needed to get rid of the image, in the same way as it is used to get rid of opposite sideband on transmission. -- -Tauno
On 7/3/12 5:59 AM, Rick Lyons wrote:
>> On 7/1/12 r b-j wrote: > > [Snipped by Lyons] > > Hi Robert, > >> i'm unfamiliar with Weaver or Tim's "regular". i know how we did it in >> analog with ham-radio gear in the 70s. with an IF frequency of, i >> dunno. it's wasn't 455 kHz (that was my old shortwave radio). i think >> it was around 3 MHz and we had a helluva sharp "crystal-lattice filter" >> with piezo "XTAL"s. >> >> with a good baseband filter, you can do it with a *real* mix. >> >> let xq(t) be the Hilbert transform of xi(t). the real IF (for USB) is >> >> >> v(t) = xi(t)*cos(w0*t) - xq(t)*sin(w0*t) >> >> = Re{ (xi(t) + j*xq(t)) * e^(j*w0*t) } > > Ok. That seems to be the standard way of > generating a real-valued upper sideband SSB > signal at an RF freq of w0. >
i wouldn't say that was the standard way of *generating* USB back when i was a kid with my trusty Hot-Water 100. but, mathematically, that *is* what USB should look like.
>> now you can multiply ("mix" using old-fashioned comm lingo) v(t) with >> cos(w0*t) (assuming you have no sync problem) and filter out the >> high-frequency images leaving only the base band. >> >> >> v(t)*cos(w0*t) = xi(t)*(cos(w0*t))^2 - xq(t)*sin(w0*t)*cos(w0*t) >> >> = 1/2*( xi(t) + xi(t)*cos(2*w0*t) - xq(t)*sin(2*w0*t) ) >> >> it's not hard to get xi(t) from that to an arbitrary postive limit of >> error (and some delay). > > Yes, and *THAT* is what's surprising me. All > the 'SSB demod' literature I've found so far > describes SSB demodulation as needing > Hilbert transformation, complex down-conversion, > and some sort of digital filtering.
shoulda been a ham operator back in the 60s/70s (i think i got my Novice class license in '68). it was a way for me to learn many of the concepts, but admittedly, i did *not* know how the circuits worked. i built Heathkits and when my HW-100 did not work right away, i had to bring it into the local ham-club at NDSU in Fargo (the EE building had this big ) and have these EE students (and hams) figure it out.
> But my > Matlab modeling seems to indicate that SSB > demodulation can be performed by simple > real-valued mixing (your cos(w0*t)) and > lowpass filtering. (Of course, this is > assuming a copy of the 'w0' carrier freq > is available at the receiver.) > > At this point I don't understand why all the > SSB demod literature's methods (including > Frerking's book) are significantly more > complicated than what you described above.
for me, i learned this frequency-domain method of SSB when i was a high-school student and a ham operator (WB0CCA). there was some stuff in the ARRL Handbook about Hilbert transforms that i didn't have the foggiest what it was, but i *did* understand how regular AM had two sidebands and all of the SSB gear worked by doing AM and then whacking the sideband you didn't want with that kick-ass crystal-lattice filter.
> Thanks Robert,
as if i did anything... -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."