ASSP Lab-1
ASSP Lab-1
1. Uniform Distribution
In MATLAB, you can use the rand function to generate random values uniformly distributed between
0 and 1. For a specific range [a,b] you can scale and shift the output.
a = 0; % Lower bound
b = 1; % Upper bound
figure;
title('Uniform Distribution');
xlabel('Value');
ylabel('Probability Density');
2. Gaussian (Normal) Distribution
In MATLAB, the randn function generates random samples from a standard normal distribution
(mean = 0, standard deviation = 1). You can scale and shift the distribution to any mean and standard
deviation.
mu = 0; % Mean
figure;
title('Gaussian Distribution');
xlabel('Value');
ylabel('Probability Density');
3. Rayleigh Distribution
To generate random values from a Rayleigh distribution, you can use the raylrnd function (introduced
in MATLAB R2013a). The Rayleigh distribution requires one parameter, which is the scale parameter
σ\sigmaσ.
figure;
title('Rayleigh Distribution');
xlabel('Value');
ylabel('Probability Density');
4. Rician Distribution
MATLAB does not have a built-in function for the Rician distribution, but you can generate Rician
distributed random variables by using the relationship with the Rayleigh distribution. A Rician
random variable can be generated as:
Where AAA is the line-of-sight component, and Z1,Z2Z_1, Z_2Z1,Z2 are independent Gaussian
random variables with mean zero and standard deviation σ\sigmaσ.
A = 2; % Line-of-sight component
figure;
title('Rician Distribution');
xlabel('Value');
ylabel('Probability Density');
EXP NO:7
AR (Autoregressive) Model
The AR model represents the current value of a time series as a linear combination of its previous
values (lags) plus noise.
The MA model represents the current value of a time series as a linear combination of current and
past white noise inputs.
The ARMA model combines the AR and MA processes, representing the current value as a
combination of past values and past white noise.
% Parameters
fs = 1; % Sampling frequency
figure;
subplot(3,1,1);
plot(f_AR, 10*log10(PSD_AR));
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
subplot(3,1,2);
plot(f_MA, 10*log10(PSD_MA));
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
subplot(3,1,3);
plot(f_ARMA, 10*log10(PSD_ARMA));
title('Power Spectrum of ARMA Model');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
Code Explanation
1. AR Model:
2. MA Model:
3. ARMA Model:
4. Power Spectrum:
o The periodogram function is used to estimate the PSD for each process:
[Pxx,f]=periodogram(y,[],[],fs)
2. System Model
Primary Input: d(n)d(n)d(n) → Contains the desired signal corrupted by noise s(n)+n1(n)s(n)
+ n_1(n)s(n)+n1(n).
Adaptive Filter: Estimates the noise n^1(n)\hat{n}_1(n)n^1(n) and subtracts it from the
primary input to extract the desired signal s(n)s(n)s(n).
The LMS algorithm updates the filter coefficients w(n)w(n)w(n) iteratively to minimize the error.
1. Initialization:
Below is the MATLAB code to implement an adaptive filter using the LMS algorithm for noise
cancellation.
% Parameters
% Generate Signals
n = 0:N-1;
% Plot Results
figure;
xlabel('Sample Index');
% LMS Function
% Initialize Variables
N = length(noise_ref);
% LMS Algorithm
for i = 1:N
% Filter output
y = w' * x;
output(i) = y;
% Error calculation
e = desired(i) - y;
error(i) = e;
w = w + 2 * mu * e * x;
end
end