# Untitled

unknown

plain_text

a month ago

21 kB

5

Indexable

Never

^{}

Experiment-1 AIM: To plot the spectrum of a pulse of width 10. APPARATUS: Computer System, MATLAB THEORY: The Fourier Transform is a powerful mathematical tool used to study signals in terms of their frequency components. It breaks down a signal into its different frequencies, helping us understand its frequency content. If we have a continuous-time signal, like x(t), the Fourier Transform X(f) can be calculated by integrating x(t) multiplied by a complex exponential e-j2ftover all time t. This can be represented as: X(f)=−∞∞x(t).e-j2ftdt Here, f represents frequency, and X(f) describes the amplitude and phase of each frequency component present in the signal x(t). In practical terms, when we plot the original signal over a specified time range, we can see its amplitude and width. Applying the Fourier Transform allows us to analyze the signal's frequency components. By using symbolic variables, we can compute the Fourier Transform and obtain a spectrum that shows the signal's frequency distribution.This analysis helps us understand both the temporal characteristics of the signal through its time domain plot and its frequency content and distribution through the frequency domain plot. CODE: clc; clear all; close all; w1 = 10; A = 1; t1 = -15:0.01:15; t0 = 2; xt_original = A * rectpuls(t1, w1); syms t w expw = exp(-1j * w * t); z_original = int(1 * expw, t, -2, 2); z_original = simplify(z_original); subplot(2,1,1) plot(t1, xt_original) title('Original Signal in Time Domain') subplot(2,1,2) ezplot(abs(z_original)) title('Frequency Spectrum') PLOT: RESULT: The MATLAB code analyzes a rectangular pulse signal. In the time domain plot, a centered rectangular pulse with amplitude 1 and width 10 units is observed. The frequency spectrum plot reveals async curve, indicating the signal's composition in the frequency domain, crucial for signal analysis and processing. Experiment-2 AIM: To verify following properties of Fourier Transform: i. Time Shifting, ii. Frequency shifting, APPARATUS: Computer System, MATLAB THEORY: The experiment aims to verify two fundamental properties of the Fourier Transform: Time Shifting and Frequency Shifting. i. Time Shifting Property: This property states that a time shift in the time domain results in a phase shift in the frequency domain. Mathematically, if x(t) is a signal with Fourier Transform X(f), then a time-shifted signal x(t−t0) has a Fourier Transform e-j2πft0.X(f). ii. Frequency Shifting Property: This property states that a frequency shift in the time domain results in a time-domain modulation by a complex exponential in the frequency domain. If x(t) has Fourier Transform X(f), then a frequency-shifted signal x(t)ej2πf0t has Fourier Transform X(f−f0). CODE: Time Shift: % Time Shifting Property % Original signal t = -1:0.01:1; x = rectpuls(t, 0.5); % Rectangular pulse % Time shift t0 = 0.5; x_shifted = rectpuls(t - t0, 0.5); % Shifted pulse % Fourier Transform of the original signal X = fft(x); % Fourier Transform of the shifted signal X_shifted = fft(x_shifted); % Plot the original and shifted signals in time domain subplot(2, 1, 1); plot(t, x, 'b', t, x_shifted, 'r--'); title('Time Domain - Original and Shifted Signals'); legend('Original', 'Shifted'); xlabel('Time'); ylabel('Amplitude'); % Plot the Fourier Transforms in frequency domain subplot(2, 1, 2); f = linspace(-50, 50, length(X)); plot(f, abs(fftshift(X)), 'b', f, abs(fftshift(X_shifted)), 'r--'); title('Frequency Domain - Fourier Transforms'); legend('Original', 'Shifted'); xlabel('Frequency'); ylabel('Magnitude'); Frequency Shift: % Frequency Shifting Property % Original signal t = -1:0.01:1; x = rectpuls(t, 0.5); % Rectangular pulse % Frequency shift f0 = 2; x_shifted_frequency = x .* exp(1i * 2 * pi * f0 * t); % Shifted frequency % Fourier Transform of the original signal X = fft(x); % Fourier Transform of the shifted frequency signal X_shifted_frequency = fft(x_shifted_frequency); % Plot the original and frequency-shifted signals in time domain subplot(2, 1, 1); plot(t, x, 'b', t, real(x_shifted_frequency), 'r--'); title('Time Domain - Original and Frequency-Shifted Signals'); legend('Original', 'Frequency-Shifted'); xlabel('Time'); ylabel('Amplitude'); % Plot the Fourier Transforms in frequency domain subplot(2, 1, 2); f = linspace(-50, 50, length(X)); plot(f, abs(fftshift(X)), 'b', f, abs(fftshift(X_shifted_frequency)), 'r--'); title('Frequency Domain - Fourier Transforms'); legend('Original', 'Frequency-Shifted'); xlabel('Frequency'); ylabel('Magnitude'); PLOT: Time Shift: Frequency Shift: RESULT: In the experiment, time shifting of a signal causes a phase shift in its frequency spectrum, while frequency shifting results in a modulation in the time domain. These observations confirm the fundamental properties of Fourier Transform, crucial for signal analysis and processing in various applications. Experiment-3 AIM: To generate Uniform random number and Gaussian distributed random number. Plot its density function. Find its mean and variance. APPARATUS: Computer System, MATLAB THEORY: In our experiment, we're exploring two types of random numbers: uniformly distributed and Gaussian (or normally) distributed. Uniform Random Number Generation: Uniform random numbers are generated within a specific range, with each number having an equal chance of occurring. This means the probability density is constant within the range. To find the mean of a uniform distribution, we simply take the average of the minimum and maximum values. The variance is calculated using the formula (b−a)2/12, where a and b are the minimum and maximum values, respectively. Gaussian Random Number Generation: Gaussian random numbers follow a bell-shaped curve described by the Gaussian (normal) distribution. This distribution is characterized by its mean (center) and variance (spread). We can directly calculate the mean and variance of a Gaussian distribution from the data we generate.By studying these two types of random numbers, we gain insight into different probability distributions and how they shape the randomness of our data. CODE: clc; clear all; close all; N = 1000000; x = randn(1, N); mu = mean(x); sigma2 = var(x); step = 0.1; range = -3:step:3; h = histc(x, range); f = ((1./(sqrt(2.*pi.*sigma2))).*exp((-(range-mu).^2)./(2.*sigma2))); figure; plot(range, f, 'b', 'linewidth', 2); hold on; simulatedPDF1 = h./(step.*sum(h)); plot(range, simulatedPDF1, '*', 'markersize', 15); bar(range, simulatedPDF1, 'histc'); title('Gaussian distribution'); xlabel('range'); ylabel('PDF'); legend('Theoretical', 'Simulated', 'Simulated'); PLOT: RESULT: The density function of the Gaussian distribution is plotted and compared with the simulated density function derived from the generated data, showing agreement between theoretical and simulated distributions. Experiment-4 c PLOT: RESULT: The experiment computes the Signal to Quantization Noise Ratio (SQNR) of Uniform Quantization for various quantization levels. It iteratively increases the number of quantization levels, computes the SQNR, and plots it against the logarithm of quantization levels. The plot demonstrates how SQNR improves with increasing quantization levels, highlighting the trade-off between quantization resolution and noise performance. Experiment-5 AIM: Write a MATLAB code to sampling theorem and the effect of sampling period on signal reconstruction. APPARATUS: Computer System, MATLAB THEORY: The Sampling Theorem states that a continuous-time signal can be accurately reconstructed from its samples if the sampling frequency is at least twice the maximum frequency component of the signal, known as the Nyquist rate. In MATLAB, an experiment can be conducted to demonstrate this theorem. A sinusoidal signal can be generated and sampled at various periods. The signal can then be reconstructed using zero-order hold interpolation, which holds each sample value until the next sample occurs. The original signal, sampled signal, and reconstructed signal can be visualized to observe the effects of changing the sampling period on signal fidelity. The experiment illustrates that a higher sampling frequency results in better reconstruction fidelity because more samples capture more details of the original signal. Conversely, insufficient sampling leads to aliasing, where high-frequency components fold back into lower frequencies, causing distortion in the reconstructed signal. This highlights the importance of choosing an appropriate sampling frequency to avoid aliasing and ensure accurate signal reconstruction. CODE: clear; clc; f = 30e3; fs = 2 * f; Ts = 1/fs; t1 = 0:1e-7:5/f; x1 = cos(2 * pi * f * t1); t2 = 0:Ts:5/f; x2 = cos(2 * pi * f * t2); xr = zeros(size(t1)); for i = 1:length(t1) for j = 1:length(x2) xr(i) = xr(i) + x2(j) * sinc(2 * fs * t1(i) - j); end end % Plot the original continuous signal subplot(3, 1, 1); plot(t1, x1); title('Continuous Signal x(t)'); xlabel('Time'); ylabel('Amplitude'); % Plot the sampled signal subplot(3, 1, 2); stem(t2, x2, 'r'); title('Sampled Signal x(nT)'); xlabel('Time'); ylabel('Amplitude'); % Plot the reconstructed signal subplot(3, 1, 3); plot(t1, xr); title('Reconstructed Signal x_r(t)'); xlabel('Time'); ylabel('Amplitude'); PLOT: RESULT Sampling theorem adherence in MATLAB demonstrated the critical role of sampling period in signal reconstruction. Varying sampling frequency highlighted fidelity changes, with lower periods yielding closer resemblance to the original signal. Results underscored the necessity of Nyquist criteria for accurate signal representation in digital systems. Experiment-6 AIM: Study of pass band digital communication technique BPSK. Calculate the BER of BPSK modulated signal. APPARATUS: Computer System, MATLAB. THEORY: Binary Phase Shift Keying (BPSK) is a passband digital modulation technique where binary data is encoded by shifting the phase of a carrier signal. Each binary symbol maps to a specific phase, simplifying transmission. Modulation: s(t)=Ac⋅cos(2πfct+ϕ) where ϕ =0 for bk=0 1 for bk= 1 Bit Error Rate (BER): BER = 12erfcEbN0 where Eb is the energy per bit, N0 is the noise power spectral density, and erfc is the complementary error function. Factors influencing BER include channel noise, modulation scheme complexity, and Signal-to-Noise Ratio (SNR). Understanding BPSK modulation and BER calculation is essential for designing efficient digital communication systems, enabling optimization strategies for reliable data transmission in noisy environments. CODE: clc; clear all;close all; N = 10^6; % number of bits or symbols % Transmitter a = rand(1,N)>0.5; % generating 0 and 1 s = 2*a-1; % BPSK modulation 0 -> -1; 1 -> 1 snr_dB = 1:1:10; % multiple Eb/N0 values snr_ratio = 10.^snr_dB/10; n = 1/sqrt(2).*(randn(1,N)+1i*randn(1,N)); % mean=0; variance=1; for i = 1:length(snr_dB) y = 10^(snr_dB(i)/20).*s + n; a_dec = real(y)>0; % receiver - decision decoding nErr(i) = size(find(a- a_dec),2); % counting the errors end simBer = nErr/N; % simulated ber theoryBer = 0.5*erfc(sqrt(10.^(snr_dB/10))); % theoretical ber figure semilogy(snr_dB,theoryBer,'b-','Linewidth',1.5); hold on semilogy(snr_dB,simBer,'x','MarkerSize',8); %axis([-3 20 10^-6 0.5]) grid on legend('theory', 'simulation'); xlabel('snr dB-->'); ylabel('Bit Error Rate-->'); title('Bit error probability curve for BPSK modulation'); PLOT: RESULT: BPSK modulation demonstrated efficient binary data transmission through phase shifts in the carrier signal. BER calculations revealed transmission accuracy, influenced by factors like noise and SNR. Understanding BPSK modulation and BER facilitates the design of reliable digital communication systems in noise-prone environments. Experiment-7 AIM: Given is a linear block code with the generator matrix G G = 1 1 0 0 1 0 1 0 1 1 1 1 0 0 1 1 1 0 0 1 1 a. Calculate the number of valid code words N and the code rate RC. Specify the complete Code set C. b. Determine the generator matrix G′ of the appropriate systematic (separable) code C’. APPARATUS: Computer System, MATLAB THEORY: For a linear block code with generator matrix G, the number of valid codewords N and the code rate RC are calculated. N equals 2n, where n is the number of bits in a codeword, while RC is k/n, with k being the number of information bits. The complete code set C is determined by multiplying G with all possible information bit combinations. To find the generator matrix G′ of a systematic code C ′ , Gaussian elimination is applied to G to transform it into systematic form, ensuring separability between information and parity bits, making decoding simpler. This theoretical approach enables the calculation of code performance metrics and the transformation of the code structure for efficient decoding. CODE: % Given generator matrix G G = [1 1 0 0 1 0 1; 0 1 1 1 1 0 0; 1 1 1 0 0 1 1]; % Calculate number of bits and length of codeword [X, n] = size(G); % Calculate number of valid codewords and code rate N = 2^n; k = size(G, 1); RC = k / n; % Display results fprintf('Number of valid codewords (N): %d\n', N); fprintf('Code rate (RC): %.2f\n', RC); % Initialize G_prime with zeros G_prime = zeros(size(G)); % Perform row operations to get systematic form for i = 1:size(G, 1) % Find the index of the leading 1 in the current row leading_1_index = find(G(i,:) == 1, 1); % Update G_prime with the current row G_prime(i, :) = G(i, :); % Perform row operations to get zeros below the leading 1 for j = 1:size(G, 1) if j ~= i factor = G(j, leading_1_index); G(j, :) = mod(G(j, :) - factor * G(i, :), 2); end end end % Display the systematic form of the generator matrix G' disp('Generator Matrix G'' for Systematic Code C'''); disp(G_prime); RESULT: Experiment-8 AIM: To simulate STOP and WAIT protocol and evaluate its performance. APPARATUS: Computer System, MATLAB THEORY: The STOP and WAIT protocol is a straightforward flow control mechanism utilized in data communication. In an experiment simulating its performance, we model frame transmission and reception. Frames are sent one by one, and the sender waits for acknowledgment from the receiver before transmitting the next frame. To mimic real-world scenarios, we introduce a probability for frames to be lost during transmission. Through simulation, we measure the protocol's throughput, which indicates the rate of successful frame transmissions, and efficiency, representing the ratio of successful transmissions to total transmission attempts. This theoretical approach allows us to evaluate the protocol's effectiveness in ensuring reliable communication and managing network traffic. Assessing these performance metrics helps in understanding how well the STOP and WAIT protocol handles data transmission under varying conditions, providing insights into its reliability and efficiency in practical communication scenarios. CODE: close all; clear all; clc; n = 8; % number of frames i = 1; while i < n fprintf('Transmitting frame %d\n', i); s = randi(10, 1, 1); if s <= 3 fprintf('Time out \n %d\n', i); else fprintf('Received frame %d\n', i); i = i + 1; end end RESULT: Experiment-9 AIM: To generate a M/M/1 Queue having infinite buffer space with parameters (λ, μ) and plot the average delay per packet vs λ/μ. APPARATUS: Computer System, MATLAB THEORY: In the experiment, we model a M/M/1 queue system with infinite buffer space, characterized by arrival rate λ and service rate μ. The M/M/1 queue represents a single-server queueing system with exponentially distributed inter-arrival and service times. By varying the ratio λ/μ, we explore different traffic intensities. We measure the average delay per packet, indicating the average time a packet spends in the queue before being served, and plot it against λ/μ. This theoretical investigation allows us to analyze how the traffic intensity affects packet delay in the queue system. It provides insights into the system's performance under varying arrival and service rates, aiding in network design and optimization efforts. CODE: %Infinte Buffer Space: % M/M/1 Queue Simulation % Parameters lambda = 0.5; % Arrival rate mu = 1; % Service rate num_iterations = 1000; % Number of iterations % Initialize variables delay = zeros(1, num_iterations); rho_values = linspace(0.1, 0.9, num_iterations); % Different values of lambda/mu % Simulation for i = 1:num_iterations rho = lambda / (mu * rho_values(i)); % Calculate average delay using Little's Law delay(i) = rho / (mu - lambda * rho); end % Plot plot(rho_values, delay, 'LineWidth', 2); xlabel('\lambda / \mu'); ylabel('Average Delay per Packet'); title('M/M/1 Queue with Infinite Buffer Space'); grid on; PLOT: RESULT: In the M/M/1 queue experiment, we observed the average delay per packet plotted against the traffic intensity ratio λ/μ. As λ/μ increases, indicating higher arrival rates relative to service rates, the average delay per packet also rises. This demonstrates that as the system becomes more congested, packets spend more time waiting in the queue before being served. Conversely, lower traffic intensities lead to shorter average packet delays. The plotted results provide valuable insights into the relationship between traffic intensity and packet delay, essential for optimizing queueing systems to ensure efficient packet transmission and minimize delays. Experiment-10 AIM: To generate a M/M/1 Queue having finite buffer space with parameters (λ, μ) and plot blocking probability with respect to variation with buffer space. APPARATUS: Computer System, MATLAB THEORY: In this experiment, we simulate an M/M/1 queue with finite buffer space, characterized by arrival rate λ and service rate μ. The M/M/1 queue represents a single-server queueing system with exponentially distributed inter-arrival and service times. By varying the buffer space, we investigate its impact on the blocking probability, which indicates the likelihood of an arriving packet being blocked due to insufficient buffer capacity. As the buffer space increases, the blocking probability decreases because more packets can be accommodated without causing overflow. This allows the system to handle higher traffic loads efficiently. Conversely, with limited buffer space, the probability of blocking increases, potentially leading to packet loss if the buffer becomes full. Plotting the results provides insights into the relationship between buffer space and blocking probability, aiding in the design and optimization of queueing systems to minimize packet loss and ensure efficient packet transmission under varying traffic conditions. CODE: % M/M/1 Queue Simulation with Finite Buffer Space % Parameters lambda = 5; % Arrival rate mu = 1; % Service rate buffer_sizes = [5, 10, 15, 20, 25]; % Different buffer sizes num_iterations = 1000; % Number of iterations % Initialize variables blocking_probabilities = zeros(1, length(buffer_sizes)); % Simulation for b = 1:length(buffer_sizes) buffer_size = buffer_sizes(b); blocking_count = 0; for i = 1:num_iterations % Generate arrivals and departures arrivals = poissrnd(lambda); departures = poissrnd(mu); % Update buffer status buffer = 0; for j = 1:min(arrivals, buffer_size) if buffer < buffer_size buffer = buffer + 1; else blocking_count = blocking_count + 1; end end buffer = buffer - min(departures, buffer); % Account for blocking when buffer is full if arrivals > buffer_size blocking_count = blocking_count + (arrivals - buffer_size); end end % Calculate blocking probability blocking_probabilities(b) = blocking_count / (lambda * num_iterations); end % Plot plot(buffer_sizes, blocking_probabilities, 'o-', 'LineWidth', 2); xlabel('Buffer Size'); ylabel('Blocking Probability'); title('M/M/1 Queue with Finite Buffer Space'); grid on; PLOT: RESULT: The experiment analyzed the M/M/1 queue with finite buffer space, varying buffer sizes while keeping arrival and service rates constant (λ = 5, μ = 1). As the buffer size increased from 5 to 25, the blocking probability decreased proportionally. This relationship signifies that larger buffer sizes lead to lower blocking probabilities, indicating a reduced likelihood of packet loss due to buffer overflow. The results highlight the importance of appropriately sizing buffers to manage congestion effectively and ensure efficient packet transmission in queueing systems.

Leave a Comment