communication system project

assassinood
provided.rar

compute_spectrum.m

function [magnitude, frequency] = compute_spectrum( x, fs , N); % syntax: [magnitude, frequency] = compute_spectrum( x, fs, N ); % % This function computes the Discete Fourier Transform (Spectrum) of vector % x by using the Fast Fourier Transform (FFT). % % Required Input Arguments: % x : vector to be processed % fs : sampling frequency of vector x % % Optinal Input Arguments: % N : number of samples used to comptue the spectrum. % (default: N = 2048) % Output Arguments: % % magnitude: y-axis of spectrum (relative strength of the % frequency components). % frequency: x-axis of spectrum (corresponding frequencies) % % Author: Temesguen Messay-Kebede % University of Dayton (Fall 2013) % check if optinal argument is provided if nargin == 2 % number of arguments equal to 2 (only x and fs have been provided by user) % if optinal agument N is not provided use N = 2048 to compute spectrum N = 2048; end % compute spectrum (full blown) magnitude =1./length(x).* abs(fftshift(fft(x,N))); % generate corresponding frequency array for single sided spectrum frequency = linspace(-fs/2,fs/2,N);

bit_error_probability.m

function [pe,ne] = bit_error_probability(in,out) % % [pe,ne] = bit_error_probability(in,out) % % pe = probability of bit error % ne = number of bit errors % Number of bit errors ne = sum(xor(logical(in),logical(out))); % Probability of error pe = ne/length(in);

compute_fft.m

function [out, f] = compute_fft(in, fs, N) % Syntax: [out, f] = compute_fft(in, fs, N) % % This function computes the spectrum of a given signal (or frequency % response of the impulse response of a system) usng the fft() built-in function. % It also returns an array that describes the frequency axis % (for the computed spectrum or fourier reponse). % % REQUIRED INPUT ARGUMENTS: in - signal or impulse response of system (1D array) % fs - sampling rate/frequency in samples/sec % (scalar) % % OPTINAL INPUT ARGUMENTS: N - number of samples to use (resolution of % fft) ... (scalar). % % OUTPUT ARGUMENTS: - out - spectrum of freq response of given input (1D of % size 8192 or N if optional argument is supplied) % - f - frequency axis (same size as out). % % Author: Tem % University of Dayton % Fall 2015 % check the number of input arguemnts if nargin < 3 N = 1024*8; end % normalize input, compute fft, circularly shift result and take its % magnitude out = abs(fftshift(fft(in./sum(in(:)),N))); % define related frequncy axis f = linspace(-fs/2,fs/2,N);

ECE401_Proj2_PCM_student.m

%--------------------------% % ECE 401 Project 2 % %--------------------------% close all clear all clc %---------------------------------------% % Define Discrete Simulation Parameters % %---------------------------------------% sample_rate = 10000; % sample_period = 1/sample_rate; % sampling period of simulation total_time = 10; % approximate total time, modified later to give an interger number of bits %-----------------------------% % Define data characteristics % %-----------------------------% num_samples_bit = 125; % number of samples for a bit duration bit_rate=sample_rate/num_samples_bit % bits/second bit_interval = 1/bit_rate; % length of time for each bit num_bits = floor( bit_rate * total_time ); % How many full bits will fit into total time total_time = num_bits * bit_interval % revised total time with full bits t = [0:sample_period:total_time-sample_period]; % time array for full simulation %----------------------% % Generate binary data % %----------------------% % generate binary "message" rand('seed',1) bit_stream = rand(1,num_bits) > .5; %---------------------% % Perform line coding % %---------------------% % make data polar polar_data = double(bit_stream); polar_data( find( bit_stream == 0 ) ) = -1; polar_data( find( bit_stream == 1 ) ) = 1; % generate narrow pulse data start_sample_indices = [ (num_samples_bit+1)/2 : num_samples_bit : length(t) ]; delta_data = zeros(size(t)); delta_data(start_sample_indices) = polar_data; % plot a small portion of the signal figure subplot(211) plot(t,delta_data) xlabel('t (seconds)'); ylabel('a_{k}(t) (Volts)') title('Binary data converted to narrow polar pulses (almost Dirac deltas)'); axis([.3,.5,-2,2]); grid on subplot(212) % compute and plot its spectrum [out, f] = compute_fft(delta_data, sample_rate,2^15); plot(f,out) xlabel('frequency in Hz') ylabel('Magnitude') axis([-160 160 0 max(out)+.2]) title('Spectrum of Binary data') grid on %-------------------------% % Generate pulse waveform % %-------------------------% % Rectangular pulse A=1; % Amplitude of the pulse rect = A*ones(1,num_samples_bit); % implement transmision filter (g(t)) s_rect = conv2(delta_data,rect,'same'); %generating INPUT pulses figure subplot(211) % plot polar NRZ rect based waveform plot(t,s_rect,'b-',t(start_sample_indices),s_rect(start_sample_indices),'ro') xlabel('t (seconds)'); ylabel('s(t) (Volts)') title('Polar NRZ PCM'); legend('Polar NRZ waveform','key samples') axis([.3,.5,-2,2]) grid on subplot(212) % compute and plot its spectrum [out, f] = compute_fft(s_rect, sample_rate,2^15); plot(f,out) xlabel('frequency in Hz') ylabel('Magnitude') axis([-160 160 0 max(out)+.2]) title('Spectrum of PCM polar') grid on