Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bits = 10;
- bitrate = 1;
- rand_bits = randi([0 1], 1,bits);
- N = 100;
- T = length(rand_bits) / bitrate;
- Ts = 1/N;
- t = 0: Ts: T;
- x = zeros(1, length(t));
- for i = 0:length(rand_bits)-1
- if rand_bits(i+1) == 1
- x(i*N+1:(i+1)*N) = 1;
- else
- x(i*N+1:(i+1)*N) = -1;
- end
- end
- subplot (6,2,1)
- plot (t , x,'LineWidth', 3);
- axis([0 t(end) -1.1 1.1]);
- grid on;
- title([' Polar NRZ: [' num2str(rand_bits) ']']);
- h = spectrum.welch;
- t_pwelch = psd(h,s,'Fs',N);
- subplot(6,2,2)
- plot(t_pwelch);
- title('Power Spectral Density');
- for i = 0:length(rand_bits)-1
- if rand_bits(i+1) == 1
- x(i*N+1:(i+1)*N) = -1;
- else
- x(i*N+1:(i+1)*N) = 1;
- end
- end
- subplot (6,2,3)
- plot (t , x,'LineWidth', 3);
- axis([0 t(end) -1.1 1.1]);
- grid on;
- title(['Inverted Polar NRZ: [' num2str(rand_bits) ']']);
- h = spectrum.welch;
- t_psd = psd(h,x,'Fs',N);
- subplot(6,2,4)
- plot(t_psd);
- title('Power Spectral Density');
- for i = 0: length(rand_bits) - 1
- if rand_bits(i+1) == 1
- s((i*N)+1:(i+1)*N) = 1;
- else
- s(i*N+1 : (i+1)*N) = 0;
- end
- end
- subplot(6,2,5)
- plot(t, s,'LineWidth', 3);
- axis([0 t(end) -0.1 1.1]);
- grid on;
- title(['Unipolar NRZ: [' num2str(rand_bits) ']']);
- h = spectrum.welch;
- t_psd = psd(h,x,'Fs',N);
- subplot(6,2,6)
- plot(t_psd);
- title('Power Spectral Density');
- for i = 0 : length(rand_bits)-1
- if rand_bits(i+1) == 1
- x((i*N)+1:(i+0.5)*N) = 1;
- x((i+0.5)*N+1:(i+1)*N) = 0;
- else
- x(i*N+1:(i+1)*N) = 0;
- end
- end
- subplot(6,2,7)
- plot(t, s,'LineWidth', 3);
- axis([0 t(end) -0.1 1.1]);
- grid on;
- title(['Unipolar RZ: [' num2str(rand_bits) ']']);
- h = spectrum.welch;
- t_psd = psd(h,x,'Fs',N);
- subplot(6,2,8)
- plot(t_psd);
- title('Power Spectral Density');
- for i = 0:length(rand_bits)-1
- if rand_bits(i+1) == 1
- x(i*N+1:(i+0.5)*N) = 1;
- x((i+0.5)*N+1:(i+1)*N) = 0;
- else
- x(i*N+1:(i+0.5)*N) = -1;
- x((i+0.5)*N+1:(i+1)*N) = 0;
- end
- end
- subplot(6,2,9)
- plot(t, x,'LineWidth', 3);
- axis([0 t(end) -1.1 1.1]);
- grid on;
- title(['Polar RZ: [' num2str(rand_bits) ']']);
- h = spectrum.welch;
- t_psd = psd(h,x,'Fs',N);
- subplot(6,2,10)
- plot(t_psd);
- title('Power Spectral Density');
- for i = 0:length(rand_bits)-1
- if rand_bits(i+1) == 1
- x(i*N+1:(i+0.5)*N) = 1;
- x((i+0.5)*N+1:(i+1)*N) = -1;
- else
- x(i*N+1:(i+0.5)*N) = -1;
- x((i+0.5)*N+1:(i+1)*N) = 1;
- end
- end
- subplot(6,2,11)
- plot(t, x,'LineWidth', 3);
- axis([0 t(end) -1.1 1.1]);
- grid on;
- title(['Manchester: [' num2str(rand_bits) ']']);
- h = spectrum.welch;
- t_psd = psd(h,x,'Fs',N);
- subplot(6,2,12)
- plot(t_psd);
- title('Power Spectral Density');
Advertisement
Add Comment
Please, Sign In to add comment