Skip to main content

Posts

Showing posts with the label MATLAB

MATLAB code for MSK

📘 Overview 🧮 MATLAB Codes 🧮 Theory 🧮 Simulator for MSK 🧮 Differences Between MSK and FSK 📚 Further Reading  Copy the MATLAB Code from here % The code is developed by SalimWireless.com clc; clear; close all; % Define a bit sequence bitSeq = [0, 1, 0, 0, 1, 1, 1, 0, 0, 1]; % Perform MSK modulation [modSignal, timeVec] = modulateMSK(bitSeq, 10, 10, 10000); % Plot the modulated signal subplot(2,1,1); samples = 1:numel(bitSeq); stem(samples, bitSeq); title('Original message signal'); xlabel('Time (s)'); ylabel('Amplitude'); % Plot the modulated signal subplot(2,1,2); samples = 1:10000; plot(samples / 10000, modSignal(1:10000)); title('MSK modulated signal'); xlabel('Time (s)'); ylabel('Amplitude'); % Perform MSK demodulation demodBits = demodMSK(modSignal, 10, 10, 10000); % Function to perform MSK modulation function [signal, timeVec] = modulateMSK(bits, carrierFreq, baudRate, sampleFreq)...

MATLAB code for GMSK

📘 Overview & Theory 🧮 MATLAB Codes for GMSK 🧮 Online Simulator for GMSK 🧮 Simulation Results for GMSK 📚 Further Reading   Copy the MATLAB code from here  % The code is developed by SalimWireless.com clc; clear; close all; % Parameters samples_per_bit = 36; bit_duration = 1; num_bits = 20; sample_interval = bit_duration / samples_per_bit; time_vector = 0:sample_interval:(num_bits * bit_duration); time_vector(end) = []; % Generate and modulate binary data binary_data = randi([0, 1], 1, num_bits); modulated_bits = 2 * binary_data - 1; upsampled_signal = kron(modulated_bits, ones(1, samples_per_bit)); figure; plot(time_vector, upsampled_signal); title('Message Signal'); % Apply Gaussian filter filtered_signal = conv(GMSK_gaussian_filter1(bit_duration, samples_per_bit), upsampled_signal); filtered_signal = [filtered_signal, filtered_signal(end)]; figure; plot(filtered_signal); title('Filtered Signal'); % Integration ...

Welch Method for Spectral Estimation in MATLAB

MATLAB Code % The code is developed by SalimWireless.com clc; clear; close all; % Input Signal and Parameters Fs = 1000; % Sampling frequency t = 0:1/Fs:0.3; % Time vector x = cos(2*pi*200*t) + randn(size(t)); % Signal: 200 Hz cosine + noise % Welch's Method Parameters segmentLength = 256; % Length of each segment overlapFraction = 0.5; % Fractional overlap (50%) overlapSamples = floor(segmentLength * overlapFraction); % Overlap in samples step = segmentLength - overlapSamples; % Step size N = length(x); % Length of the input signal % Define Hann Window hannWindow = 0.5 * (1 - cos(2 * pi * (0:segmentLength-1)' / (segmentLength - 1))); windowEnergy = sum(hannWindow.^2); % Normalization factor % Segment the Signal into Overlapping Windows numSegments = floor((N - overlapSamples) / step); % Number of segments segments = zeros(segmentLength, numSegments); for i = 1:numSegments startIdx = (i - 1) * step + 1; endIdx = star...

Bartlett Method in MATLAB

Steps to calculate Spectral power density using Bartlett Method 1. 'M' is the length of each segment for the Bartlett method, set to 100 samples. 2. 'K' is the number of segments obtained by dividing the total number of samples N by the segment length 'M'. 3. psd_bartlett _broadband is initialized to store the accumulated periodogram. 4. For each segment k, x_k extracts the k-th segment of the broadband signal. 5. P_k computes the periodogram of the k-th segment using the FFT. 6. The periodograms are accumulated and averaged over all segments. 7. The PSD is plotted in dB/Hz by converting the power values to decibels using 10*log10.   MATLAB Script clc; clear; close all; % Parameters fs = 1000; % Sampling frequency t = 0:1/fs:1-1/fs; % Time vector N = length(t); % Number of samples % Generate synthetic broadband ARMA process arma_order = [2, 2]; % ARMA(p,q) order a = [1, -0.75, 0.5]; % AR coefficients b = [1, 0.4, 0.3]; % MA coefficients %broadband_signal = f...

Correlogram in MATLAB

 Steps to compute correlogram of an input signal 1. Compute the autocorrelation function of narrowband_signal 2. Computes the Fast Fourier Transform (FFT) of the autocorrelation function ( acf ), resulting in corr_spectrum . 3. freq = (0:N-1)*(fs/N); Constructs a frequency vector ( freq ) corresponding to the FFT results, spanning from 0 Hz to just under the Nyquist frequency ( fs/2 ). Where, N = Number of Samples in the Input Signal 4. Plots the magnitude of the FFT ( abs(corr_spectrum) ) against the frequency vector ( freq ), showing the correlogram of the narrowband signal.   MATLAB Code clc; clear; close all; %Parameters fs = 1000; % Sampling frequency t = 0:1/fs:1-1/fs; % Time vector N = length(t); % Number of samples %Generate narrowband signal f0 = 50; % Center frequency of narrowband process narrowband_signal = sin(2*pi*f0*t) + 0.5*randn(size(t)); % Narrowband signal with noise %Compute autocorrelation function (ACF) of narrowband signal acf = autocorrelation(narrowb...

FFT Magnitude and Phase Spectrum using MATLAB

📘 Overview & Theory 🧮 MATLAB Code 1 🧮 MATLAB Code 2 📚 Further Reading   MATLAB Code  % Developed by SalimWireless.Com clc; clear; close all; % Configuration parameters fs = 10000; % Sampling rate (Hz) t = 0:1/fs:1-1/fs; % Time vector creation % Signal definition x = sin(2 * pi * 100 * t) + cos(2 * pi * 1000 * t); % Calculate the Fourier Transform y = fft(x); z = fftshift(y); % Create frequency vector ly = length(y); f = (-ly/2:ly/2-1) / ly * fs; % Calculate phase while avoiding numerical precision issues tol = 1e-6; % Tolerance threshold for zeroing small values z(abs(z) < tol) = 0; phase = angle(z); % Plot the original Signal figure; subplot(3, 1, 1); plot(t, x, 'b'); xlabel('Time (s)'); ylabel('|y|'); title('Original Messge Signal'); grid on; % Plot the magnitude of the Fourier Transform subplot(3, 1, 2); stem(f, abs(z), 'b'); xlabel('Frequency (Hz)'); ylabel('|y|'); title('Magnitude o...

Adaptive Equalizer to mitigate Channel Distortion - in MATLAB

  Adaptive equalizer adjusts its parameters based on the characteristics of the communication channel. It uses adaptive algorithms to continuously estimate and correct for channel distortion, aiming to minimize errors in the received signal. Adaptive equalizers are versatile and effective in varying channel conditions.   MATLAB Code clc; clear; close all; % Parameters N = 100000; % Number of samples filter_order = 10; % Order of the adaptive filter lambda = 0.99; % Forgetting factor for RLS algorithm delta = 1; % Initial value for the inverse correlation matrix SNR_range = -20:1:20; % SNR range in dB ber = zeros(length(SNR_range), 1); % Initialize BER array % Generate a random signal original_signal = randi([0, 1], N, 1) * 2 - 1; % Bipolar signal (-1, 1) % Channel impulse response h = [0.8, 0.5, 0.2]; % Loop over SNR values for snr_idx = 1:length(SNR_range)     SNR = SNR_range(snr_idx); % Current SNR value          % Pass the signal...

Fourier Differentiation Property in MATLAB

  Fourier Differentiation Property The Fourier transform of a time-domain signal is defined as follows   Fourier Differentiation Property     MATLAB Code for Fourier Differentiation property of a Sine Function clc; clear; close all;   % Parameters fs = 1000; % Sampling frequency (Hz) T = 1; % Duration of the signal (seconds) f = 50; % Frequency of the sine wave (Hz) A = 1; % Amplitude of the sine wave % Time vector t = 0:1/fs:T-1/fs; % Generate sine wave x = A * sin(2*pi*f*t); % Compute Fourier Transform X = fft(x); % Frequency vector N = length(x); frequencies = (0:N-1)*(fs/N); % Apply differentiation property in frequency domain jw = 1i * 2 * pi * frequencies; % jω term for differentiation % Multiply Fourier coefficients by jω dX = jw .* X; % Compute Inverse Fourier Transform for differentiated signal dx = ifft(dX); % Plotting figure; % Plot original signal and its magnitude spectrum subplot(3,1,1); plot(t, x); title('Original Sine Wave'); xlabel('Time (s)');...

MATLAB Code for BER performance of QPSK with BPSK, 4-QAM, 16-QAM, 64-QAM, 256-QAM, etc

📘 Overview 🧮 MATLAB Codes 🧮 Online Simulator for Calculating BER of M-ary PSK and QAM 🧮 QPSK vs BPSK and QAM: A Comparison of Modulation Schemes in Wireless Communication 🧮 Are QPSK and 4-PSK same? 📚 Further Reading   QPSK offers double the data rate of BPSK while maintaining a similar bit error rate at low SNR when Gray coding is used. It shares spectral efficiency with 4-QAM and can outperform 4-QAM or 16-QAM in very noisy channels. QPSK is widely used in practical wireless systems, often alongside QAM in adaptive modulation schemes [Read more...] What is the Gray Code? Gray Code: Gray code is a binary numeral system where two successive values differ in only one bit. This property is called the single-bit difference or unit distance code. It is also known as reflected binary code. Let's convert binary 111 to Gray code: Binary bits: B = 1 1 1 Apply the rule: G[0] = B[0] = 1...

When to use 'scatter' or 'scatterplot'?

   The MATLAB command 'scatter' plots a constellation diagram when original message symbols or demodulated symbols are in the complex number format. On the other hand, the MATLAB command 'scatterplot' is used when original message symbols or demodulated symbols are in the decimal format.   Example (use of 'scatterplot') % Clearing workspace, closing figures, and setting seed for random number generation clc; clear all; close all; % Setting parameters rng(10); M = 4; % Number of phases for PSK modulation N_Bits = 2520; % Total number of bits to transmit Phase = 0; % Initial phase angle % Generating random binary data data_info_bit = randi([0,1],N_Bits,1); % Converting binary data to decimal data_temp = bi2de(reshape(data_info_bit,N_Bits/log2(M),log2(M))); % Performing PSK modulation modData = pskmod(data_temp,M,Phase); % Visualizing modulated data figure(1); scatterplot(modData); % Simulating channel with AWGN channelAWGN = 15; % Noise power rxData2 = awgn(m...

MATLAB Code for BER vs SNR for 4-QAM

MATLAB Script % This code is written by SalimWirelss.Com clc; clear all; close all; M = 4; % Number of levels after quantization / size of signal constellation k = log2(M); % Number of bits per symbol rng(1) % Assaining the value of seed integer N = 1000000; % Number of bits to process % Initialize SNR values and BER array snr_dB = -20:1:20; % SNR values in dB BER = zeros(size(snr_dB)); for snr_idx = 1:length(snr_dB) snrdB = snr_dB(snr_idx); InputBits = randi([0 1], 1, N); % Generating randon bits InputSymbol_matrix = reshape(InputBits, length(InputBits)/k, k); % Reshape data into binary k-tuples, k = log2(M) InputSymbols_decimal = bi2de(InputSymbol_matrix); % Convert binary to decimal for n = 1:N/k if InputSymbols_decimal(n) == 0 QAM(n) = complex(1,1); elseif InputSymbols_decimal(n) == 1 QAM(n) = complex(-1,1); elseif InputSymbols_decimal(n) == 2 QAM(n) = complex(1,-1); else QAM(n) = complex(-1,-1); end end % Transmission of 4QAM data over AWGN channel Y = awgn(QAM,...

People are good at skipping over material they already know!

View Related Topics to







Admin & Author: Salim

s

  Website: www.salimwireless.com
  Interests: Signal Processing, Telecommunication, 5G Technology, Present & Future Wireless Technologies, Digital Signal Processing, Computer Networks, Millimeter Wave Band Channel, Web Development
  Seeking an opportunity in the Teaching or Electronics & Telecommunication domains.
  Possess M.Tech in Electronic Communication Systems.


Contact Us

Name

Email *

Message *