⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit02.m

📁 用MATLAB编写的qpsk调制解调程序并且方针通过
💻 M
字号:
% this section is for Y388N
% 2007.10.23
% lidongshi
%

clear all;
close all;
% tx_bit = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
% tx_bit = [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1];
% tx_bit = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
% tx_bit = [1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0];
tx_bit = [0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1];

tx_bit_num = size(tx_bit);

% single pole to double pole 
tx_bit = tx_bit*2-1;

% I and Q 
I = tx_bit(1:2:tx_bit_num(2));
Q = tx_bit(2:2:tx_bit_num(2));

f_lo1 = 42.8e6/2;
f_lo2 = 846.6e6;
bit_rate = 1e6;

% t = 0:1/(4*f_lo2):1/bit_rate;
t = 0:1/(4*f_lo2):tx_bit_num(2)/(2*bit_rate);
cos_lo1 = cos(2*pi*f_lo1*t);
sin_lo1 = -sin(2*pi*f_lo1*t);

I_lo1(1) = 0;
Q_lo1(1) = 0;
for i = 1:tx_bit_num(2)/2
    I_lo1 = [I_lo1 I(i)*cos_lo1(3386*(i-1)+1:3386*i)];
    Q_lo1 = [Q_lo1 Q(i)*sin_lo1(3386*(i-1)+1:3386*i)];
end
IQ_size = size(I_lo1);
f = 0:1e5:(4*f_lo2);
IF_out = I_lo1(2:IQ_size(2)) + Q_lo1(2:IQ_size(2));
plot(f(1:33860),(abs(fft(hilbert(IF_out(1:33860))))));

t = 0:1/(4*f_lo2):tx_bit_num(2)/(2*bit_rate);
LO2 = 0.1*cos(2*pi*f_lo2*t);

x = f_lo2/f_lo1;
rf_out = IF_out(1:33860) .* LO2(1:33860);
figure;
f = 0:1e5:(4*f_lo2);
plot(f(1:33860),(abs(fft(hilbert(rf_out)))));

figure;
% hold on;
f = 0:1e5:(4*f_lo2);
plot(f,(abs(fft(hilbert(LO2)))));

% bandpass filter, center frequence is 868MHz
% highpass filter
figure;
N = 64;
F = [0, 0.5, 0.51, 1];
A = [0, 0, 1, 1];
LF_coefficient = firls(N,F,A);
for i = 1:2:4
   plot([F(i) F(i+1)],[A(i) A(i+1)],'--'), hold on
end
[H,k] = freqz(LF_coefficient,1,512,2);
plot(k,abs(H)), grid on, hold off;
legend('Ideal','firls Design')

rf_filter = conv(LF_coefficient,rf_out);
figure;
plot(f,(abs(fft(hilbert(rf_filter((N/2+1):(33929-N/2)))))));


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
IF_in = rf_filter((N/2+1):(33929-N/2)) .* LO2(1:33865);
figure;
plot(f,(abs(fft(hilbert(IF_in(1:33865))))));

% lowpass filter
figure;
N = 64;
F = [0, 0.5, 0.51, 1];
A = [100, 100, 0, 0];
LF_coefficient = firls(N,F,A);
for i = 1:2:4
   plot([F(i) F(i+1)],[A(i) A(i+1)],'--'), hold on
end
[H,k] = freqz(LF_coefficient,1,512,2);
plot(k,abs(H)), grid on, hold off;
legend('Ideal','firls Design')

if_filter = conv(LF_coefficient,IF_in);
figure;
plot(f,(abs(fft(hilbert(if_filter((N/2+1):(33929-N/2)))))));

t = 0:1/(4*f_lo2):10/bit_rate;
cos_lo1 = cos(2*pi*f_lo1*t);
sin_lo1 = -sin(2*pi*f_lo1*t);

if_filter((N/2+1):(33924-N/2)) = IF_out(1:33860);

I_in = if_filter((N/2+1):(33924-N/2)) .* cos_lo1(1:33860);
Q_in = if_filter((N/2+1):(33924-N/2)) .* (sin_lo1(1:33860));
figure;
subplot(2,1,1);
plot(I_in);
subplot(2,1,2);
plot(Q_in);

% O = zeros(1,3385);
% I_to_judge = [O I_in O];
% Q_to_judge = [O Q_in O];
% 
% for i = 1:33860
%     I_judge(i) = mean(I_to_judge(i:i+3385));
%     Q_judge(i) = mean(Q_to_judge(i:i+3385));
% end

% for i = 1:10
%     data_judge(i) = I_in(3387*(i-1)+1);
% end

% lowpass filter
figure;
N = 1024;
F = [0, 0.01, 0.02, 1];
A = [1, 1, 0, 0];
LF_coefficient = firls(N,F,A);
for i = 1:2:4
   plot([F(i) F(i+1)],[A(i) A(i+1)],'--'), hold on
end
[H,k] = freqz(LF_coefficient,1,512,2);
plot(k,abs(H)), grid on, hold off;
legend('Ideal','firls Design')

I_filter = conv(LF_coefficient,I_in);
Q_filter = conv(LF_coefficient,Q_in);
figure;
% plot(abs(fft(hilbert(I_filter((N/2+1):(33929-N/2))))));
subplot(2,1,1);
plot(I_filter((N/2+1):(33924-N/2)));
subplot(2,1,2);
plot(Q_filter((N/2+1):(33924-N/2)));

for i = 1:10
    if I_filter(3386*i-3386/2) < 0
        data_judge(i*2-1) = 0;
    elseif I_filter(3386*i-3386/2) > 0
            data_judge(i*2-1) = 1;
    end
    if Q_filter(3386*i-3386/2) < 0
        data_judge(i*2) = 0;
    elseif Q_filter(3386*i-3386/2) > 0
            data_judge(i*2) = 1;
    end
end

error_bit = 0;
for i = 1:20
    if data_judge(i) ~= tx_bit(i)
        error_bit = error_bit + 1;
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -