added bandpass filter

This commit is contained in:
madmaurice 2016-07-28 19:29:39 +02:00
parent d6d4a97f47
commit d81b6383c0

View file

@ -24,24 +24,30 @@
datalen = 10; datalen = 10;
d = rand(1,datalen) > 0.5; pilot = [ 1 0 1 0 ];
#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]; dr = rand(1,datalen) > 0.5;
n = 0:datalen-1;
signallen = datalen + size(pilot,2);
d = [ pilot dr ];
n = 0:signallen-1;
phases = [ -pi/2 pi/2 ]; phases = [ -pi/2 pi/2 ];
Tb = 0.5; Tb = 0.3;
fc = 5; fc = 40;
fa = 200; fa = 1000;
subplot(6,1,1) subplot(6,1,1)
stem(n,d) stem(n,d)
timelen = (signallen*Tb - 1/fa);
t = 0:(1/fa):(size(d,2)*Tb - 1/fa); t = 0:(1/fa):timelen;
phi = phases( d( floor(t/Tb) + 1) + 1); phi = phases( d( floor(t/Tb) + 1) + 1);
subplot(6,1,2) subplot(6,1,2)
plot(t,phi) plot(t,phi)
axis([0 timelen -pi pi])
s = cos(2*pi*fc*t + phi); s = cos(2*pi*fc*t + phi);
@ -50,30 +56,34 @@ s = cos(2*pi*fc*t + phi);
slow = filter(bs,as,s); slow = filter(bs,as,s);
subplot(6,1,3); subplot(6,1,3);
vgl = cos(2*pi*fc*t); plot(t,slow);
plot(t,slow,t,vgl); axis([0 timelen -1.5 1.5])
noise = 0.5 * randn(size(slow)); noise = 1 * randn(size(slow));
sn = slow + noise; sn = slow + noise;
subplot(6,1,4); subplot(6,1,4);
[bbp,abp] = butter(5,[2*0.5*fc/fa , 2*1.5*fc/fa]);
sbp = filter(bbp,abp,sn);
plot(t,sn); plot(t,sn);
axis([0 timelen -3 3])
sr = sn .* cos(2*pi*fc*t);
si = sn .* sin(2*pi*fc*t);
[b,a] = butter(5,2*fc/fa); sr = sbp .* cos(2*pi*fc*t);
si = sbp .* sin(2*pi*fc*t);
[b,a] = butter(5,2*0.7*fc/fa);
srlow = filter(b,a,sr); srlow = filter(b,a,sr);
silow = filter(b,a,si); silow = filter(b,a,si);
cmplxs = srlow + j*silow; cmplxs = srlow + j*silow;
phase = angle(cmplxs); phase = angle(cmplxs);
m = zeros(size(phase)); m = zeros(size(phase));
for i = 1:size(t,2) for i = 1:size(t,2)
@ -83,9 +93,10 @@ endfor
subplot(6,1,5); subplot(6,1,5);
plot(t,phase,t,phases(m+1)); plot(t,phase,t,phases(m+1));
axis([0 timelen -pi pi])
ds = zeros(1,datalen); ds = zeros(1,signallen);
for i = 1:datalen; for i = 1:signallen;
ts = (i-1) * Tb; ts = (i-1) * Tb;
te = i * Tb; te = i * Tb;
q = t > ts & t < te; q = t > ts & t < te;