clear all; close all; clc;
Fs = 122.88;
T_samp = 1/(30.27*10^6);
rrc_coeffs = [3.0097e-4 -0.0024 -0.029 -7.6172e-4 0.0023 0.0034 0.0011 ...
-0.0028 -0.0047 -0.0024 0.0027 0.0064 0.0050 -0.0011 -0.0071 -0.0076 ...
-0.0014 0.0064 0.0087 0.0026 -0.0070 -0.0107 -0.0027 0.0120 0.0199 ...
0.0093 -0.0171 -0.0400 -0.0351 0.0056 0.0611 0.0881 0.0497 -0.0515 ...
-0.1594 -0.1860 -0.0601 0.2227 0.5820 0.8829 1 0.8829 0.5820 0.2227 ...
-0.0601 -0.1860 -0.1594 -0.0515 0.0497 0.0881 0.0611 0.0056 -0.0351 ...
-0.0400 -0.0171 0.0093 0.0199 0.0120 -0.0027 -0.0107 -0.0070 0.0026 ...
0.0087 0.0064 -0.0014 -0.0076 -0.0071 -0.0011 0.0050 0.0064 0.0027 ...
-0.0024 -0.0047 -0.0028 0.0011 0.0034 0.0023 -7.6172e-4 -0.0290 ...
-0.0024 3.0097e-4];
rrc_coeffs = rrc_coeffs/max(rrc_coeffs);
subplot(2,1,1)
plot((-0.5:1/1024:0.5-1/1024)*Fs, fftshift(20*log10(fft(rrc_coeffs/sum(rrc_coeffs),1024))))
grid
hold on
Carrier_Freq = 245.76e6; % Upsample by 16
Fsymbol = 30.72e6;
D = 8; % decimation / interpolation
Alpha = 0.25; % excess BW
% rrc_coef = sqrt(D)*fircos(80,.5,Alpha,D/2,'r','sqrt');
% rrc_coef = rrc_coef/max/(rrc_coef);
hh = rcosine(1, 4, 'sqrt', Alpha, 10); % RCOSINE(Fd, Fs, TYPE_FLAG, R)
%freqz(hh)
hh = hh/max(hh);
hhh = [hh zeros(1,7)];
hhh2 = reshape(hhh,8,11); % upsample rcosine filter by 4
hk = rcosine(1, 8, 'sqrt', Alpha, 5); % filter delay is DELAY/Fd sec.
hk = hk/max(hk); % Fd is the digital transfer sampling frequency
hhk = [hk zeros(1,7)];
hh2 = reshape(hhk,8,11); % upsample rcosine filter by 8
plot((-0.5:1/1024:0.5-1/1024)*Fs, fftshift(20*log10(fft(hh/sum(hh),1024))),'g')
plot((-0.5:1/1024:0.5-1/1024)*Fs, fftshift(20*log10(fft(hk/sum(hk),1024))),'r')
title('Spectrum of Nyquist filters')
b3 = [1/6 -1/2 1/2 -1/6];
b2 = [1/2 -1 1/2 0];
b1 = [1/3 1/2 -1 1/6];
b0 = [0 1 0 0];
h = firhalfband(18, 0.2); % EXAMPLE 1: Design a minimum order halfband
% filter with given max ripple
% b = firhalfband('minorder',.45,0.0001)
%freqz(h);
% 8 samples per symbol, 5 symbols (filter order of 40-- 41 filter taps)
% Uses D = FDESIGN.PULSESHAPING(SPS,SHAPE,SPECSTRING,NSYM,ROLLOFF,...)
rc1 = fdesign.pulseshaping(8,'Square Root Raised Cosine','Nsym,beta',10,0.25);
d1 = design(rc1)
rrc_alt = d1.numerator;
plot((-0.5:1/1024:0.5-1/1024)*Fs, fftshift(20*log10(fft(d1.Numerator/sum(d1.Numerator),1024))),'c.-.')
axis([0 40 -80 5])
legend('4x oversample Zync', '4x oversample','8x oversample','8x oversample' )
hold off
% plot(d1.Numerator);
% title('Impulse Response--5*8+1 filter taps');
My_RRC = [-0.0009, -0.0014, -0.0014, -0.0011, -0.0004, 0.0006, 0.0016, ...
0.0024, 0.0027, 0.0023, 0.0012, -0.0004, -0.0023, -0.0041, -0.0053, ...
-0.0056, -0.0047, -0.0025, 0.0008, 0.0045, 0.0082, 0.0108, 0.0118, ...
0.0104, 0.0066, 0.0006, -0.0069, -0.0147, -0.0213, -0.0252, -0.0248, ...
-0.0193, -0.0080, 0.0087, 0.0297, 0.0535, 0.0777, 0.1000, 0.1179, ...
0.1295, 0.1335, 0.1295, 0.1179, 0.1000, 0.0777, 0.0535, 0.0297, 0.0087, ...
-0.0080, -0.0193, -0.0248, -0.0252, -0.0213, -0.0147, -0.0069, 0.0006, ...
0.0066, 0.0104, 0.0118, 0.0108, 0.0082, 0.0045, 0.0008, -0.0025, ...
-0.0047, -0.0056, -0.0053, -0.0041, -0.0023, -0.0004, 0.0012, 0.0023, ...
0.0027, 0.0024, 0.0016, 0.0006, -0.0004, -0.0011, -0.0014, -0.0014, ...
-0.0009];
subplot(2,1,2)
plot(rrc_coeffs)
hold on
plot(hh,'r.')
plot(hk,'g')
legend('4x oversample Zync','4x oversample', '8x oversample')
axis([0 82 -0.4 1.2])
hold off
grid
% Complex input data
N_dat = 1000;
x0=(floor(2*rand(1,N_dat))-0.5)/0.5 + j*(floor(2*rand(1,N_dat))-0.5)/0.5;
xr = real(x0);
% Data through 4x upsample Nyquist filter
reg = zeros(1,11);
mm=0;
for nn = 1:N_dat
reg=[x0(nn) reg(1:10)];
for kk=1:4
x2(mm+kk) = reg*hhh2(kk,:)';
end
mm = mm+4;
end
% Data through 8x upsample Nyquist filter
reg = zeros(1,11);
mm=0;
for nn = 1:N_dat
reg=[x0(nn) reg(1:10)];
for kk=1:8
x1(mm+kk) = reg*hh2(kk,:)';
end
mm = mm+8;
end
x0_delay = [zeros(1,5) x0];
figure,
subplot(2,1,1)
plot(0:T_samp:999*T_samp,real(x1(1:1000)))
hold on
plot(0:T_samp:999*T_samp,real(x1(1:1000)),'g.')
plot(0:8*T_samp:999*T_samp,real(x1(1:8:1000)),'ro','linewidth',2)
stem(0:T_samp*8:124*T_samp*8,real(x0_delay(1:125)),'m.')
hold off
grid on
title('Real Part of Matched Filter Output for first 10000 samples')
ylabel('Amplitude')
xlabel('Time in Seconds')
subplot(2,1,2)
plot(0:T_samp:999*T_samp,real(x2(1:1000)))
hold on
plot(0:T_samp:999*T_samp,real(x2(1:1000)),'g.')
plot(0:4*T_samp:999*T_samp,real(x2(1:4:1000)),'ro','linewidth',2)
stem(0:T_samp*4:248*T_samp*4,real(x0_delay(1:249)),'m.')
hold off
grid on
title('Real Part of Matched Filter Output for first 10000 samples')
ylabel('Amplitude')
xlabel('Time in Seconds')
figure,
subplot(1,2,1)
plot(x1(1:8:8000),'rx')
axis('square')
grid on
title('Constellation 8 Samples/Symbol')
subplot(1,2,2)
plot(0,0)
hold on
for k = 1:16:8000-16
plot(-1:1/8:1,real(x1(k:k+16)))
% plot(-1:1/8:1,real(x1(k:k+16)),'r.')
end
hold off
grid on
title('Eye Diagram, 8 Samples/Symbol')