diff --git a/phasenmodulation.m b/phasenmodulation.m new file mode 100644 index 0000000..c821985 --- /dev/null +++ b/phasenmodulation.m @@ -0,0 +1,101 @@ +## Copyright (C) 2016 Valentin Gehrke +## +## This program is free software; you can redistribute it and/or modify it +## under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 3 of the License, or +## (at your option) any later version. +## +## This program is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this program. If not, see . + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{retval} =} phasenmodulation (@var{input1}, @var{input2}) +## +## @seealso{} +## @end deftypefn + +## Author: Valentin Gehrke +## Created: 2016-07-28 + +datalen = 10; + +d = rand(1,datalen) > 0.5; + +#d = [ 1 0 1 0 1 1 1 0 1 0 0 0 1 0 0 1 0 1 0 1 1 0 1 1 0 0 0 1]; +n = 0:datalen-1; +phases = [ -pi/2 pi/2 ]; +Tb = 0.5; +fc = 5; +fa = 200; + +subplot(6,1,1) +stem(n,d) + + +t = 0:(1/fa):(size(d,2)*Tb - 1/fa); +phi = phases( d( floor(t/Tb) + 1) + 1); + +subplot(6,1,2) +plot(t,phi) + +s = cos(2*pi*fc*t + phi); + +[bs,as] = butter(5,2*1.5*fc/fa); + +slow = filter(bs,as,s); + +subplot(6,1,3); +vgl = cos(2*pi*fc*t); +plot(t,slow,t,vgl); + +noise = 0.5 * randn(size(slow)); + +sn = slow + noise; + +subplot(6,1,4); +plot(t,sn); + +sr = sn .* cos(2*pi*fc*t); +si = sn .* sin(2*pi*fc*t); + +[b,a] = butter(5,2*fc/fa); + +srlow = filter(b,a,sr); +silow = filter(b,a,si); + + +cmplxs = srlow + j*silow; + +phase = angle(cmplxs); + + +m = zeros(size(phase)); + +for i = 1:size(t,2) + [tmp, idx] = min(abs(phase(i) - phases)); + m(i) = idx-1; +endfor + +subplot(6,1,5); +plot(t,phase,t,phases(m+1)); + +ds = zeros(1,datalen); +for i = 1:datalen; + ts = (i-1) * Tb; + te = i * Tb; + q = t > ts & t < te; + ds(i) = mean(m(q)) > 0.5; +endfor + +subplot(6,1,6) +err = (ds != d); +cla +stem(n(~err),ds(~err)) +hold on; +stem(n(err),ds(err),'rx') +hold off;