【问题标题】:BER result in MATLABBER 结果在 MATLAB 中
【发布时间】:2022-10-05 00:48:38
【问题描述】:

我建立了一个 pam-2 调制,然后用半正弦波(匹配滤波器)进行脉冲整形。 然后我通过 AWGN 通道发送它。 最后我进行下采样和解调。 但我在绘制 BER 时遇到问题。我不明白我做错了什么:

clc;
clear;
N=1e4;
N2 = 1e2; 
M = 2;
range = 0:10;
error =  zeros(1,length(range)); %BER

%
% half sine
Rc = 1e3;       % Chip rate
T = 1/Rc;      % inverse of chip rate
Tc = 0.5* T;
Fs = 2e3;      % sampling frequency
dt = 1/Fs;
over = Fs/Rc;   % sampling factor
sps = 10;  

time = 0:dt/sps:2*T;
half_Sine = sin(pi*time/(2*T)).^3; 

%% BER

for i = 1:length(range)
    for n = 1:N2 
        
% Modulation
        x=randi([0 M-1],N,1);
        h_mod = pammod(x,M);       
        over_data=upsample(h_mod,over); 
        txSig = conv(over_data,half_Sine, 'same'); 
% AWGN  
        Ps = mean(((txSig)).^2);
        Sigma = sqrt(Ps  * 10^(-range(i)/10) / 2);
        Noise = randn(length(txSig), 1) * Sigma;
        rx_SIG = Noise + txSig; 

% Downsample
     down = rx_SIG(1:over:end);
     
%  Demodulation 
        hDemod  =  pamdemod(down,M);
% Errors
       error(i) = error(i)+...
           sum(hDemod~=x) / length(hDemod);

    end
    
     BER = error/n;
end
figure(1);
grid on
semilogy(range,BER);
title('BER');

【问题讨论】:

    标签: matlab signal-processing telecommunication modulation


    【解决方案1】:

    1.-您的脚本启动并运行:

    有许多代码行变成了我用来运行启动脚本的 cmets。我把它们留下了,应该只在调试时使用。

    close all;clear all;clc;
    
    N=1024;
    M = 2;
    
    % pulse : half sine
    Rc = 1e3; % [b/s] chip rate
    T = 1/Rc; % [s/b] inverse of chip rate
    Tc = 0.5* T;
    Fs = 2e3; % [Hz] sampling frequency
    dt = 1/Fs; % [s]  
    ov1 = Fs/Rc;   % sampling factor
    sps = 10;  
    dt2=dt/sps
    
    % single pulse time reference
    t = [0:dt2:2*T];  % [s]
    
    % signals usually have a known preable
    % a heading known sequence that helps receivers
    % extract with relative ease when pulse peaks take place
    % the sync preamble has to be long enough to acquire
    % the sampling interval.
    % For simplicity here I just make sure that the first bit of the signal is always 1 
    nsync=64 % length sync header
    x=[ones(1,nsync) randi([0 M-1],1,N-nsync)];  % signal : data
    
    xm=reshape(x([nsync+1:end]),[(N-nsync)/8 8])
    L1=sum(repmat(2.^[7:-1:0],size(xm,1),1).*xm,2); % string to check received bytes against, to measure BER
    
    over_data = pammod(x,M); % signal : PAM symbols
    
    % err1 =  zeros(1,length(x)); %BER
    
    % single pulse
    pulse_half_Sine = sin(pi*t/(2*T)).^3; 
    figure;plot(t,pulse_half_Sine)
    grid on;xlabel('t');title('single pulse')
    
    % A=[.0001:.0001:1];
    A=[1e-3 5e-3 1e-2 5e-2 .1 .5 1 10 100];
    % A=[5e-2:1e-2:2];
    rng1 = [1:numel(A)];  % amount S power levels to check for BER
    
    % to use power on requires a reference impedance
    % usually assumed 1, in accademic literature, but then when attempting to correlated
    % BER with used Watts if R0=1 the comparison is not correct.
    R0=50 % [Ohm]
    
    
    %% BER measuring loop
    % k=1
    
    % Logging BER for different signal  power levels,
    % Logging signal power levels, it was useful when getting script up and running
    BER=[]; 
    SNR_log=[]; 
    
    figure(1)
    ax1=gca
    
    for k = 1:length(rng1)
    
    % generating signal
    x2=2*(x-.5); % [0 1] to [-1 1]
     S=[]
     for k2=1:1:numel(x)
         S=[S  A(k)*x2(k2)*pulse_half_Sine];
     end
     
    Ps = mean(S.^2)/R0; % signal power
            
    % adding AWGN 
    % you are making the noise proportional to the signal
    % this causes BER not to improve when signal power up
    % sigma1 = sqrt(Ps  * 10^(-rng1(k)/10) / 2); % not used
    sigma1=.1
    noise1 = randn(length(S), 1) * sigma1;
    
    Pn=mean(noise1.^2)/R0;
            
    rx_S = noise1' + S; % noise + S
    
    % Downsample
    % this downsampling is an attempt to sync received signal
    % to the time stamps where pulse peaks are expected
    % but it does not work
    %      dwn1 = rx_SIG(1:ov1:end);
         
    %  Demodulation 
    % because the sampling times of the previous line are not
    % centered pamdemod doesn't work either
    %         hDemod  =  pamdemod(dwn1,M);
    
    % the missing key step : conv on reception with expected pulse shape
    rx2_S=conv(pulse_half_Sine,rx_S);
    
    rx2_sync=conv(pulse_half_Sine,rx_S([1:1:nsync*numel(pulse_half_Sine)]));
    
    % removing leading samples that only correspond to the 
    % pulse used to correlate over received signal
    rx2_S([1:numel(pulse_half_Sine)-1])=[];
    
    % syncing 
    [pks,locs]=findpeaks(abs(rx2_sync),'NPeaks',nsync,'MinPeakHeight',A(k)/2);
    % [pks,locs]=findpeaks(abs(rx2_S));
    
    % x3(find(pks<.1))=[]; % do not use sign results close to zero
    % locs(find(pks<.1))=[];
    
    %  t0=dt2*[0:1:numel(rx2_sync)-1];
    %  figure;plot(t0,rx2_sync);hold on
    %  plot(t0(locs),pks,'bo')
    
    % 5 header pulses needed, 1st and last header samples are null, not needed
    n01=find(pks<.2*A(k));
    if ~isempty(n01) peaks(n01)=[];locs(n01)=[]; end
    %  pks([1 end])=[];locs([1 end])=[];
    %  plot(t0(locs),pks,'rs')
    
    % since we know there have to be 5 leading pulses to be all ones
    % we extract the sampling interval from this header
    
    nT2=round(mean(diff(locs)))
    
    % t3=dt2*[0:1:numel(rx2_S)-1];
    % figure;plot(t3,abs(rx2_S));
    % hold on
    % xlabel('t')
    % plot(t3(locs),pks,'ro')
    
    % nt3=[1:nT2:numel(x)*nT2];  % sampling times
    % plot(t3(nt3),max(pks)*ones(1,numel(nt3)),'sg')
    
    x3=sign(rx2_S([1:nT2:N*nT2])); % only N bits expected so only sample N times
    
    % x3 [-1 1] back to [0 1] otherwise when comparing v3 against x
    % a roughtly 50% of bits are always going to be wrong, which comes
    % from the signal statistics
    x3=.5*(1+x3);
    
    % sampling
    % x3=sign(rx_S(locs));
    
    % making sure x3 and x same length
    % x3(find(pks<.1))=[]; % do not use sign results close to zero
    
    SNR=Ps/Pn;
    SNR_log=[SNR_log Ps];
    
    x3_8=reshape(x3([nsync+1:end]),[(N-nsync)/8 8])
    Lrx=sum(repmat(2.^[7:-1:0],size(x3_8,1),1).*x3_8,2);
    
    err1 = sum(L1~=Lrx) / length(Lrx);
    BER = [BER err1];
    
    end
    
    %% BER(S)
    figure(1);
    plot(rng1,BER);
    grid on
    title('BER/rng1');
    

    这不是误码率正如我们所知,它被用于各种质量测量。

    注意误码率不一样误码率尽管这两个术语通常使用相同。

    速率意味着和数量/秒的速度,速度。

    误码率常用来测量信号质量是比率,而不是比率。

    BER = 正确位/总位,但它并不像我要展示的那样简单。

    例如,请注意最糟糕的误码率使用快速修复的脚本获得的值未达到 0.5 以上(!?)误码率当消息没有“到达那里”时,肯定会达到 1。

    我相信以下几点对于您了解如何误码率真的有效。

    2.- 对于真正不同的信号功率电平,BER 完全平坦

    在较早的工作脚本中,即使使用脉冲幅度 A=100,也未显示低噪声mean(noise1)=-7.36e-04 大约 1/3 的接收符号是错误的,而figure;plot(rx_S) 显示了相当干净的信号,没有骑马纹,没有突然的变化..

    1/3 错误位没有被信道噪声破坏,但它已经在传输的信号中。我已将每个脉冲间隔足够长以避免重叠脉冲。

    相邻脉冲至少需要 2ms 才能避免重叠。

    这没有考虑多普勒。

    当命令conv 用于以您的方式生成的脉冲序列时会发生严重重叠的符号:

    S = conv(over_data,A(k)*pulse_half_Sine, 'same');
    

    3.- 您从 1e4 数据位开始,将其视为 1e4 调制符号

    但是您的发送接收时间信号也显示长度为 1e4 个时间样本,不能是时间样本太少。

    over_datapulse_half_Sine 的时间参考不应相同。奈奎斯特;如果在比方说载波调制脉冲的周期中只有 2 个样本,则信号将被破坏而无法恢复。

    我试过了

    h_mod = pammod(x,M);       
    over_data=upsample(h_mod,ov1); 
    S = conv(h_mod,A(k)*pulse_half_Sine, 'same'); % modulated signal
    
    h_mod = pammod(x,M);       
    S = conv(h_mod,A(k)*pulse_half_Sine, 'same'); % modulated signal
    
    S = conv(over_data,A(k)*pulse_half_Sine, 'same'); % modulated signal
    

    这三个都没有达到预期误码率显示信号是强还是弱。

    4.- 原来命令 upsample 是针对离散时间模型的

    sys = tf(0.75,[1 10 2],2.25)
    L = 14;
    sys1 = upsample(sys,L)
    

    例如,不要直接插入信号以使您尝试的样本量增加一倍。

    5.- 这就是传输信号(添加噪声之前)的样子

    t2=dt2*[0:1:numel(S)-1];
    figure;plot(t2,S);
    grid on;xlabel('t');title('transmitted signal before noise')
    
    t3=dt2*[0:1:numel(rx2_S)-1];
    [pks,locs]=findpeaks(abs(rx2_S))
    figure;plot(t3,rx2_S);
    hold on
    xlabel('t')
    plot(t3(locs),pks,'ro')
    

    6.- 选择的脉冲对 AWGN 不是特别强

    主要原因是因为它是基带脉冲。未调制,除此之外只有正值。

    调制脉冲时卷积效率大大提高,在每个脉冲上发现的正负脉冲样本增加了在尝试确定是否存在脉冲或噪声时的鲁棒性。

    例如,啁啾脉冲要强得多。

    7.- 测量 BER:使用字节、星座点、编码符号,但不使用裸比特

    测量误码率使用裸比特,或者更广泛地说,使用具有固定统计矩的随机测试信号误码率在没有弱信号的情况下,受限于分配给信号的任何均值和 var 和/或来自噪声的均值 var。

    改写,测试误码率当信号较弱或无信号时,使用裸比特计数误码率实际上是在测量信号试图避免的噪声。

    大约 50% 的接收比特,无论信号或噪声,您尝试 BER 测量的方式,总是会命中明显正确的比特:误报.

    为了避免这些误报,我展示了如何测量误码率针对预期的字符。

    N=1024
    ..
    nsync=64 % length sync header
    x=[ones(1,nsync) randi([0 M-1],1,N-nsync)];  % signal : data
    

    现在x 是 1024,最初的 64 位仅用于同步,留下N-sync 用于消息。

    让我们检查误码率反对让我们说L1 预期的字节序列

    xm=reshape(x([nsync+1:end]),[(N-nsync)/8 8])
    L1=sum(repmat(2.^[7:-1:0],size(xm,1),1).*xm,2);
    

    L1x3_8 生成的 Lrx 进行检查,x3 解调符号的消息部分

    8.- 上采样下采样不起作用

    接收时的这种下采样

    dwn1 = rx_SIG(1:ov1:end);
    

    试图将接收到的信号与预期脉冲峰值的时间戳同步,但它不起作用。

    因为采样时间没有居中pamdemod 也不起作用。

    9.- 使用同步头计算采样间隔

    我只对nsync (64) 初始位进行卷积

    rx2_sync=conv(pulse_half_Sine,rx_S([1:1:nsync*numel(pulse_half_Sine)]));
    

    这些脉冲允许可靠地计算nT2 采样间隔,以检查接收帧的其余部分。

    我得到nT2

    [pks,locs]=findpeaks(abs(rx2_sync),'NPeaks',nsync,'MinPeakHeight',A(k)/2);
    

    需要进一步调节,但基本上 locs 已经拥有获取 nT2 的必要信息。

    10.- 这是得到的图表

    当没有信号BER = 1 并且信号强度足够高时,PAM 信号显示良好的“BER”结束为 0。

    当精炼A 步骤时,通过这个意思使它变小,得到以下

    误码率测试仪通常在设置时插入基站并留下几个小时甚至几天的记录,并且此类测试仪不会记录裸比特错误、字节、星座点,甚至检查帧。

    11.- BER/SNR BER/EbN0 不只针对信号

    误码率通常针对信噪比(模拟信号)或Eb/N0(数字信号)不仅仅针对信号幅度或信号功率。

    12.- Communications Toolbox 是 MATLAB 的附加组件

    这个工具箱增加了以下支持功能:pammodpamdemodgenqammodgenqamdemod,是的pammod和pamdemod分别使用genqammodgenqamdemod

    除非安装了 Communications Toolbox,否则这些功能不可用。

    对于 BER 模拟,请尝试 Simulink,已经有可用的 BER 示例。

    【讨论】:

      猜你喜欢
      • 2015-06-03
      • 2014-08-11
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      • 2010-11-01
      相关资源
      最近更新 更多