Forums

Matlab code needed for SSB demodulation

Started by Rick Lyons June 30, 2012
On 2.7.12 9:48 , Randy Yates 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 tauno voipio at iki fi
On Mon, 02 Jul 2012 22:00:36 +0300, Tauno Voipio
<tauno.voipio@notused.fi.invalid> wrote:

>On 2.7.12 9:48 , Randy Yates 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 Anchor Hill Communications www.anchorhill.com
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
On Mon, 02 Jul 2012 22:00:36 +0300, Tauno Voipio wrote:

> On 2.7.12 9:48 , Randy Yates 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.
There was an article in QEX some years back on using the peaks in the spectrum of the received signal (which are assumed to be evenly spaced from DC) to identify the frequency error. -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
On Mon, 02 Jul 2012 14:48:52 -0400, Randy Yates wrote:

> "Rick Lyons" <R.Lyons@n_o_s_p_a_m.ieee.org> writes: > >> Hi Randy, >> >>>I don't know exactly how the phase shifting and filtering perform part >>>of the demodulation, but could you simply >>> >>> a) complex-mix the input signal by the carrier frequency b) >>> complex-filter the result to 0 to Fb, where Fb is the highest >>> modulating frequency >>> c) take the real part? >>> >>>-- >>>Randy Yates >> >> Yes, I think you are correct. I've modeled that exact process. And >> because we can >> discard the imaginary part of the complex-filtering result, based on my >> modeling it seems we only need to perform real-valued filtering. >> >> However, because the process described above is simpler than any SSB >> demod process I've found on the web, I'm suspicious that I'm doing >> something wrong in my Matlab modeling. That's why I wanted to have a >> look at other people's SSB demod Matlab code and compare it with mine. > > 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.
Amateur radio operators do it by twiddling the tuning knob until the signal sounds right. UPS for a while wanted to set up some service based on vestigial-carrier SSB, that would let the receiver phase-lock to the carrier. -- My liberal friends think I'm a conservative kook. My conservative friends think I'm a liberal kook. Why am I not happy that they have found common ground? Tim Wescott, Communications, Control, Circuits & Software http://www.wescottdesign.com
On Mon, 02 Jul 2012 17:01:40 -0500, Tim Wescott <tim@seemywebsite.com>
wrote:

>On Mon, 02 Jul 2012 14:48:52 -0400, Randy Yates wrote: > >> "Rick Lyons" <R.Lyons@n_o_s_p_a_m.ieee.org> writes: >> >>> Hi Randy, >>> >>>>I don't know exactly how the phase shifting and filtering perform part >>>>of the demodulation, but could you simply >>>> >>>> a) complex-mix the input signal by the carrier frequency b) >>>> complex-filter the result to 0 to Fb, where Fb is the highest >>>> modulating frequency >>>> c) take the real part? >>>> >>>>-- >>>>Randy Yates >>> >>> Yes, I think you are correct. I've modeled that exact process. And >>> because we can >>> discard the imaginary part of the complex-filtering result, based on my >>> modeling it seems we only need to perform real-valued filtering. >>> >>> However, because the process described above is simpler than any SSB >>> demod process I've found on the web, I'm suspicious that I'm doing >>> something wrong in my Matlab modeling. That's why I wanted to have a >>> look at other people's SSB demod Matlab code and compare it with mine. >> >> 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. > >Amateur radio operators do it by twiddling the tuning knob until the >signal sounds right. > >UPS for a while wanted to set up some service based on vestigial-carrier >SSB, that would let the receiver phase-lock to the carrier.
In the US the NTSC and ATSC broadcast TV signals both work this way, i.e., VSB with a small carrier for phase-lock. There's more than one way to demodulate the ATSC 8-VSB signal, with some mixing the vestigial carrier to zero Hz and some mixing the center of the signal to zero Hz. The slicer looks different for both cases, and I *think* the performance is the same in either case. Eric Jacobsen Anchor Hill Communications www.anchorhill.com
On Jul 2, 3:00=A0pm, Tauno Voipio <tauno.voi...@notused.fi.invalid>
wrote:
> On 2.7.12 9:48 , Randy Yates 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 > tauno voipio at iki fi
Haha... that's funny
Rick Lyons wrote:
> [*GROSS SNIP* ;/] > Either I'm misunderstanding the "phasing method" of > SSB demodulation, or my Matlab code is fouled up. > I can't figure what I'm doing wrong. > [snip]
Three points: 1. I'm from the "old school" of BRUTE FORCE testing [once required to document what happened when 1" copper strap went phase->gnd on multi-MW multi-KV line. Wish I still had the pictures ;) P.S. we were on backup power longer than intended ;] 2. There's an OLD joke - "Thought I was wrong - wasn't!" Have you run a suitably perverse signal thought both your code and their code? I like the idea of modulating frequencies which are mutually relatively prime to each other and the carrier frequency. I'd run perverse test cases where the carrier was *perfectly* suppressed and where it wasn't. Are you actually correct? P.S. i not be known to be mathematically inclined ;)
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 -- Engineering is the art of making what you want from things you can get. &#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;&#2013266095;
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. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."