matlab码型变换bnrz、brz
时间: 2023-07-27 09:13:59 浏览: 264
下面是Matlab代码实现BNRZ和BRZ码型变换的函数:
```matlab
function [bnrz, brz] = code_conversion(data, T, R)
% BNRZ and BRZ code conversion
% data: the original digital signal
% T: the bit time
% R: the bit rate
% bnrz: the BNRZ coded signal
% brz: the BRZ coded signal
% BNRZ code
bnrz = zeros(1, length(data));
for i = 1:length(data)
if data(i) == 0
bnrz(i) = -1;
else
bnrz(i) = 1;
end
end
% BRZ code
brz = zeros(1, length(data)*2);
for i = 1:length(data)
if data(i) == 0
brz((i-1)*2+1:i*2) = -1;
else
brz((i-1)*2+1:i*2) = [1 -1];
end
end
% plot
t = 0:T/100:T*(length(data)-1);
figure;
subplot(3,1,1);
plot(t, data);
title('Original Digital Signal');
xlabel('Time/s');
ylabel('Amplitude');
subplot(3,1,2);
plot(t, bnrz);
title('BNRZ Coded Signal');
xlabel('Time/s');
ylabel('Amplitude');
subplot(3,1,3);
t = 0:T/100:T*(length(data)*2-1);
plot(t, brz);
title('BRZ Coded Signal');
xlabel('Time/s');
ylabel('Amplitude');
```
其中,`data`为原始数字信号,`T`为比特时间,`R`为比特率。函数将返回BNRZ和BRZ编码后的信号`bnrz`和`brz`,并画出原始信号、BNRZ编码后的信号和BRZ编码后的信号的波形图。
阅读全文