matlab - Low-pass filter in carrier modulation and demodulation -
i'm designing project in array passed through quadrature amplitude modulation (qam) modulator, , carrier modulation, make playable sound() command, demodulate qam demodulation.
firstly, have used standard way of qam modulation:
m = 16; x = randint(5000, 1, m); y = modulate(modem.qammod(m), x);
then, wrote own carrier modulation function:
function [out] = carriermodulation(x) fs = 16000; t = 1.0 / 4000; fc = 8000; q = real(x); = imag(x); t = 0:t:(size(x))*t; c1 = zeros(size(x), 1); c2 = zeros(size(x), 1); = 1:size(x) c1(i) = i(i)*sin(2*pi*(fc)*t(i)); c2(i) = q(i)*sin(2*pi*fc*t(i) + pi/2); end out = c1 + c2;
no problem far. when done demodulation function, found result different original value (the qam modulator output).
function [out] = carrierdemodulation(x) fs = 16000; t = 1.0 / 4000; fc = 8000; t = 0:t:(size(x))*t; a1 = zeros( size(x), 1); a2 = zeros( size(x), 1); = 1:size(x) a1(i) = x(i)*sin( 2*pi*(fc)*t(i)); a2(i) = x(i)*cos( 2*pi*(fc)*t(i)); end a1 = sqrt(a1); a2 = sqrt(a2); out = a1 + a2;
i think modulation part right. problem think have don't have low-pass filter (lpf) demodulation. , should not calculate a1 , a2 directly. how add lpf demodulation code such output same original?
you need low-pass filter @ receiver after coherent demodulation, that's right. there's problem modulation. in example, symbol rate rs
less angular carrier frequency w_c
potentially causes overlapping of spectra @ receiver. consequently, reconstruction of information signal impossible. additionaly, in example fc * t = 2
. means argument of sine function integer multiple of 2pi , therefore zero.
what need impulse shaper (can implemented low-pass filter) @ transmitter bandwidth w_g >= r/2
. should so-called nyquist lowpass. carrier frequency must satisfy w_c > w_g
.
i've written matlab script impulse shaping, modulation, demodulation, filtering , sampling, transmitted signal can reconstructed.
first define parameters, create random bits , mapping you've done. simple impulse response impulse shaping used, namely rectangular impulse. in real world we're going digital analog domain here, computer model, represent analog signal discrete 1 sampling frequency f_s
. impulse shaper simple, because repeats each sample l
times.
m = 16; % qam order fs = 16000; % sampling frequency in hz ts = 1/fs; % sampling interval in s fc = 1000; % carrier frequency in hz (must < fs/2 , > fg) rs = 100; % symbol rate ns = 20; % number of symbols x = randint(ns, 1, m); y = modulate(modem.qammod(m), x); l = fs / rs; % oversampling factor % impulse shaping y_a = reshape(repmat(y', l, 1), 1, length(y)*l);
now modulation. used carrier frequency satisfies above conditions: it's higher signal bandwidth , can still represented sampling frequency used.
%% modulation = real(y_a); q = imag(y_a); t = 0 : ts : (length(y_a) - 1) * ts; c1 = .* sin(2*pi * fc * t); c2 = q .* cos(2*pi * fc * t); s = c1 + c2;
demodlation straightforward...
%% demodulation r_i = s .* sin(2*pi * fc * t); r_q = s .* -cos(2*pi * fc * t);
to remove spectral tributaries @ 2f_c
after demodulation low-pass filter required. used matlab fdatool create filter , part of following code. remember: signal bandwidth rs/2
, , unwanted tributaries begin @ 2*fc - rs/2
. how fpass
, fstop
found. (it might useful relax these requirements little bit.)
%% filter % design filter least-squares method n = 50; % order fpass = rs/2; % passband frequency fstop = 2*fc - rs/2; % stopband frequency wpass = 1; % passband weight wstop = 1; % stopband weight % calculate coefficients using firls function. b = firls(n, [0 fpass fstop fs/2]/(fs/2), [1 1 0 0], [wpass wstop]); % filtering w_i = filter(b, 1, r_i); w_q = filter(b, 1, r_q);
after filtering still have sample received signal. here it's downsampling. used phase offset of l/2
avoid filter transitions.
%% sampling u_i = downsample(w_i, l, l/2); u_q = downsample(w_q, l, l/2);
finally, plot constellation diagram , nice 16-qam constellation:
plot(u_i, u_q, '.');
you can find complete code here.
your question touched lot of topics of both dsp , matlab programming. not go detail everywhere. if have specific questions 16-qam modulation , demodulation place stack exchange site signal processing.
Comments
Post a Comment