%Below is a MATLAB code to illustrate the effect of decreasing
the sampling
% rate by a factor of
%D.
% It generates a signal, downsamples it, and compares the
magnitude
% spectrum of the original and downsampled signals.
% Parameters
fs = 1000; % Original sampling frequency (Hz)
T = 1; % Duration of the signal (seconds)
f1 = 50; % Frequency of first sine wave (Hz)
f2 = 200; % Frequency of second sine wave (Hz)
D = 4; % Downsampling factor
% Time vector
t = 0:1/fs:T-1/fs;
% Original signal: sum of two sine waves
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
% Downsampling
x_downsampled = downsample(x, D);
fs_downsampled = fs / D;
% New time vector for the downsampled signal
t_downsampled = 0:1/fs_downsampled:
(length(x_downsampled)-1)/fs_downsampled;
% Frequency vectors for original and downsampled signals
N = length(x);
f = linspace(-fs/2, fs/2, N);
N_down = length(x_downsampled);
f_down = linspace(-fs_downsampled/2, fs_downsampled/2,
N_down);
% Fourier Transform and magnitude spectrum
X = fftshift(fft(x, N)) / N;
X_down = fftshift(fft(x_downsampled, N_down)) / N_down;
% Plotting
figure;
% Original signal spectrum
subplot(2,1,1);
plot(f, abs(X));
title('Magnitude Spectrum of Original Signal');
xlabel('Frequency (Hz)');
ylabel('|X(f)|');
grid on;
% Downsampled signal spectrum
subplot(2,1,2);
plot(f_down, abs(X_down));
title(['Magnitude Spectrum of Downsampled Signal (D = ',
num2str(D), ')']);
xlabel('Frequency (Hz)');
ylabel('|X_{down}(f)|');
grid on;
% Display a warning for aliasing if applicable
if fs_downsampled < 2*f2
disp('Warning: Aliasing may occur due to insufficient sampling
rate.');
end
Design and implemntation of antialiasing and anti imaging filter
% Parameters
fs = 1000; % Original sampling frequency (Hz)
T = 1; % Duration of the signal (seconds)
f1 = 50; % Frequency of first sine wave (Hz)
f2 = 200; % Frequency of second sine wave (Hz)
D = 4; % Decimation factor
I = 4; % Interpolation factor
% Time vector
t = 0:1/fs:T-1/fs;
% Original signal
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
% Anti-aliasing filter design for decimation
fc_aa = fs / (2 * D); % Cutoff frequency for anti-aliasing filter
Wn_aa = fc_aa / (fs / 2); % Normalize cutoff frequency to
Nyquist frequency
disp(['Anti-aliasing filter normalized cutoff frequency Wn_aa =
', num2str(Wn_aa)]);
% Ensure Wn_aa is valid
if Wn_aa >= 1 || Wn_aa <= 0
error('Anti-aliasing filter cutoff frequency must be within the
normalized range (0, 1).');
end
[b_aa, a_aa] = butter(8, Wn_aa, 'low'); % 8th-order lowpass
Butterworth filter
% Filter the signal before decimation
x_filtered = filter(b_aa, a_aa, x);
% Decimation (downsampling)
x_decimated = downsample(x_filtered, D);
fs_decimated = fs / D;
% Debugging step: Display decimated sampling frequency
disp(['fs_decimated = ', num2str(fs_decimated)]);
% Anti-imaging filter design for interpolation
fc_ai = fs / (2 * I); % Corrected cutoff frequency (based on
original sampling rate)
Wn_ai = fc_ai / (fs / 2); % Normalize to the original Nyquist
frequency
disp(['Anti-imaging filter normalized cutoff frequency Wn_ai =
', num2str(Wn_ai)]);
% Ensure Wn_ai is valid
if Wn_ai >= 1 || Wn_ai <= 0
error('Anti-imaging filter cutoff frequency must be within the
normalized range (0, 1).');
end
[b_ai, a_ai] = butter(8, Wn_ai, 'low'); % 8th-order lowpass
Butterworth filter
% Interpolation (upsampling)
x_interpolated = upsample(x_decimated, I);
% Filter the signal after interpolation
x_reconstructed = filter(b_ai, a_ai, x_interpolated);
% Time vectors for plots
t_decimated =
0:1/fs_decimated:(length(x_decimated)-1)/fs_decimated;
t_interpolated = 0:1/fs:(length(x_reconstructed)-1)/fs;
% Plotting
figure;
% Original signal
subplot(4,1,1);
plot(t, x);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Signal after decimation
subplot(4,1,2);
stem(t_decimated, x_decimated, 'r');
title('Decimated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Signal after interpolation
subplot(4,1,3);
stem(t_interpolated, x_interpolated, 'g');
title('Upsampled Signal (Before Filtering)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Reconstructed signal
subplot(4,1,4);
plot(t_interpolated, x_reconstructed);
title('Reconstructed Signal (After Filtering)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
write a matlab program to Design and implement an interpolator
with a frequency of 0.042Hz by a factor of L=4.
% Parameters
fs = 1; % Original sampling frequency (Hz)
L = 4; % Interpolation factor
f_signal = 0.042; % Frequency of the signal to interpolate (Hz)
T = 50; % Duration of the signal (seconds)
% Generate the original signal
t = 0:1/fs:T-1/fs; % Time vector for the original signal
x = sin(2*pi*f_signal*t); % Original signal: sine wave of
frequency 0.042 Hz
% Upsample the signal by factor of L
x_upsampled = upsample(x, L); % Insert L-1 zeros between
each sample
fs_interpolated = fs * L; % New sampling frequency after
interpolation
% Design the anti-imaging filter
fc = fs / 2; % Cutoff frequency: Nyquist of the original signal
Wn = fc / (fs_interpolated / 2); % Normalize cutoff frequency to
the new Nyquist frequency
[b, a] = fir1(50, Wn); % FIR filter of order 50
% Apply the anti-imaging filter
x_interpolated = filter(b, a, x_upsampled);
% Time vector for the interpolated signal
t_interpolated = 0:1/fs_interpolated:T-1/fs_interpolated;
% Plotting
figure;
% Original signal
subplot(3,1,1);
plot(t, x, '-b');
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Upsampled signal (before filtering)
subplot(3,1,2);
stem(t_interpolated, x_upsampled, 'r');
title('Upsampled Signal (Before Filtering)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Interpolated signal (after filtering)
subplot(3,1,3);
plot(t_interpolated, x_interpolated, '-g');
title('Interpolated Signal (After Filtering)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
Adaptive Noise cancellation by LMS
% Parameters
fs = 1000; % Sampling frequency (Hz)
T = 2; % Duration (seconds)
t = 0:1/fs:T-1/fs; % Time vector
% Generate the desired signal (sine wave)
f_signal = 50; % Frequency of desired signal (Hz)
desired_signal = sin(2*pi*f_signal*t);
% Generate noise
noise = 0.5 * randn(size(t)); % Gaussian noise
% Generate noise-corrupted signal
noisy_signal = desired_signal + noise;
% Reference noise (used for noise cancellation)
reference_noise = 0.5 * randn(size(t)); % Uncorrelated noise
for reference
% Adaptive filter parameters
mu = 0.01; % Step size (learning rate)
filter_order = 32; % Number of filter coefficients
weights = zeros(filter_order, 1); % Initialize filter weights
n_iterations = length(t); % Number of iterations
% Initialize buffers
output_signal = zeros(1, n_iterations);
error_signal = zeros(1, n_iterations);
% Adaptive filtering using LMS algorithm
for n = filter_order:n_iterations
% Input vector for the filter (reference noise)
x = reference_noise(n:-1:n-filter_order+1)';
% Filter output
y = weights' * x;
% Error signal (desired - filter output)
error_signal(n) = noisy_signal(n) - y;
% Update filter weights
weights = weights + mu * error_signal(n) * x;
% Store output signal
output_signal(n) = y;
end
% Plot results
figure;
% Original desired signal
subplot(3,1,1);
plot(t, desired_signal, 'b');
title('Original Desired Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Noisy signal
subplot(3,1,2);
plot(t, noisy_signal, 'r');
title('Noisy Signal (Desired Signal + Noise)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Error signal (cleaned signal)
subplot(3,1,3);
plot(t, error_signal, 'g');
title('Extracted Signal (Error Signal)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% 8 point IDFT
% Parameters
N = 8; % Number of points for IDFT
X = [1+1j, 2-1j, -1+2j, 3+3j, 0, -1-1j, 1-2j, 2+1j]; % Frequency-
domain sequence
% Ensure X has N points (pad or truncate if necessary)
X = X(1:N);
% IDFT computation
n = 0:N-1; % Time indices
k = 0:N-1; % Frequency indices
WN = exp(1j * 2 * pi / N); % Twiddle factor (IDFT uses positive
exponent)
WN_matrix = WN .^ (n' * k); % IDFT matrix
% Compute the IDFT
x = (1/N) * (WN_matrix * X.'); % Compute the time-domain
sequence
% Display results
disp('Frequency-domain sequence (X):');
disp(X);
disp('Time-domain sequence (x) after IDFT:');
disp(x.');
% Plot results
figure;
% Plot real part of the time-domain sequence
subplot(2,1,1);
stem(n, real(x), 'b', 'LineWidth', 1.5);
title('IDFT: Real Part');
xlabel('Time index n');
ylabel('Amplitude');
grid on;
% Plot imaginary part of the time-domain sequence
subplot(2,1,2);
stem(n, imag(x), 'r', 'LineWidth', 1.5);
title('IDFT: Imaginary Part');
xlabel('Time index n');
ylabel('Amplitude');
grid on;
program for auto correlation
% Input sequence
x = [6, -3, -1, 0, 8, 7, -2];
% Compute the autocorrelation using the formula
N = length(x); % Length of the sequence
r = zeros(1, 2*N-1); % Allocate memory for autocorrelation
lag = -N+1:N-1; % Lag indices
% Compute autocorrelation
for k = 1:length(lag)
shift = lag(k); % Current lag
for n = 1:N
if n+shift > 0 && n+shift <= N
r(k) = r(k) + x(n) * x(n+shift);
end
end
end
% Display results
disp('Autocorrelation values:');
disp(r);
% Plot the autocorrelation
figure;
stem(lag, r, 'b', 'LineWidth', 1.5);
title('Autocorrelation Function');
xlabel('Lag');
ylabel('Autocorrelation');
grid on;
Program for subband coding
% Parameters
fs = 1000; % Sampling frequency (Hz)
T = 1; % Duration of signal (seconds)
t = 0:1/fs:T-1/fs; % Time vector
% Original signal (sum of sine waves with different
frequencies)
f1 = 50; % Frequency of first sine wave (Hz)
f2 = 150; % Frequency of second sine wave (Hz)
f3 = 300; % Frequency of third sine wave (Hz)
x = sin(2*pi*f1*t) + sin(2*pi*f2*t) + sin(2*pi*f3*t); % Signal
% Filter bank design (3 sub-bands)
% Lowpass filter (cutoff at 100 Hz)
[b_low, a_low] = butter(4, 100/(fs/2), 'low');
% Bandpass filter (cutoff between 100 Hz and 200 Hz)
[b_band, a_band] = butter(4, [100 200]/(fs/2), 'bandpass');
% Highpass filter (cutoff at 200 Hz)
[b_high, a_high] = butter(4, 200/(fs/2), 'high');
% Apply filters to the signal to create sub-bands
x_low = filter(b_low, a_low, x); % Low-frequency sub-band
x_band = filter(b_band, a_band, x); % Mid-frequency sub-band
x_high = filter(b_high, a_high, x); % High-frequency sub-band
% Sub-band coding (example: quantization and downsampling)
x_low_quant = round(x_low); % Quantization (simplified)
x_band_quant = round(x_band); % Quantization (simplified)
x_high_quant = round(x_high); % Quantization (simplified)
x_low_downsampled = downsample(x_low_quant, 2); %
Downsampling
x_band_downsampled = downsample(x_band_quant, 2); %
Downsampling
x_high_downsampled = downsample(x_high_quant, 2); %
Downsampling
% Reconstruct the signal by upsampling and filtering each sub-
band
x_low_upsampled = upsample(x_low_downsampled, 2); %
Upsampling
x_band_upsampled = upsample(x_band_downsampled, 2); %
Upsampling
x_high_upsampled = upsample(x_high_downsampled, 2); %
Upsampling
% Recombine sub-bands (simple addition)
x_reconstructed = x_low_upsampled + x_band_upsampled +
x_high_upsampled;
% Plotting the results
figure;
% Original signal
subplot(4, 1, 1);
plot(t, x);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Low-frequency sub-band
subplot(4, 1, 2);
plot(t, x_low);
title('Low-frequency Sub-band');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Mid-frequency sub-band
subplot(4, 1, 3);
plot(t, x_band);
title('Mid-frequency Sub-band');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Reconstructed signal
subplot(4, 1, 4);
plot(t, x_reconstructed);
title('Reconstructed Signal (after Sub-band Coding)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
half band filters
% Parameters
fs = 10000; % Sampling frequency (Hz)
T = 1; % Duration of the signal (seconds)
t = 0:1/fs:T-1/fs; % Time vector
% Frequency specifications
transition_width = 2000; % Transition width (Hz)
stopband_attenuation = 80; % Stopband attenuation (dB)
decimation_factor = 4; % Decimation factor
interpolation_factor = 4; % Interpolation factor
% Design the FIR half-band decimator filter (lowpass filter)
% Half-band filter has a cutoff frequency at fs / (2 *
decimation_factor)
cutoff_freq_dec = (fs / 2) / decimation_factor;
N_dec = 200; % Filter order for decimator (adjust as needed
for requirements)
% Design the filter using fir1 with specified cutoff and
stopband attenuation
dec_filter = fir1(N_dec, cutoff_freq_dec / (fs / 2), 'low');
% Design the FIR half-band interpolator filter
% Half-band filter has a cutoff frequency at fs / (2 *
interpolation_factor)
cutoff_freq_int = (fs / 2) / interpolation_factor;
N_int = 200; % Filter order for interpolator (adjust as needed)
% Design the filter using fir1 with specified cutoff and
stopband attenuation
int_filter = fir1(N_int, cutoff_freq_int / (fs / 2), 'low');
% Generate a test signal (sine wave with multiple frequencies)
f1 = 1000; % Frequency 1 (Hz)
f2 = 3000; % Frequency 2 (Hz)
f3 = 5000; % Frequency 3 (Hz)
x = sin(2*pi*f1*t) + 0.5*sin(2*pi*f2*t) + 0.2*sin(2*pi*f3*t); %
Test signal
% Apply decimation (downsampling by decimation_factor)
x_decimated = filter(dec_filter, 1, x); % Filter the signal
x_decimated = downsample(x_decimated, decimation_factor);
% Downsample
% Apply interpolation (upsampling by interpolation_factor)
x_interpolated = upsample(x_decimated, interpolation_factor);
% Upsample
x_interpolated = filter(int_filter, 1, x_interpolated); % Filter the
signal
% Update the new sampling frequencies for decimated and
interpolated signals
fs_decimated = fs / decimation_factor;
fs_interpolated = fs * interpolation_factor;
% Display the power spectrum using a spectrum analyzer
figure;
subplot(3, 1, 1);
pwelch(x, [], [], [], fs, 'power', 'centered');
title('Power Spectrum of the Input Signal');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
subplot(3, 1, 2);
pwelch(x_decimated, [], [], [], fs_decimated, 'power',
'centered');
title('Power Spectrum of the Decimated Signal');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
subplot(3, 1, 3);
pwelch(x_interpolated, [], [], [], fs_interpolated, 'power',
'centered');
title('Power Spectrum of the Interpolated Signal');
xlabel('Frequency (Hz)');
ylabel('Power/Frequency (dB/Hz)');
grid on;
% Display the signals for comparison
figure;
subplot(3, 1, 1);
plot(t, x);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 2);
t_decimated = 0:1/fs_decimated:T-1/fs_decimated;
plot(t_decimated, x_decimated);
title('Decimated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(3, 1, 3);
t_interpolated = 0:1/fs_interpolated:T-1/fs_interpolated;
plot(t_interpolated(1:10000), x_interpolated);
title('Interpolated Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
8 point DFT
% Input sequence x(n)
x = [1, 1, 0, 0];
% Length of the input sequence
N = length(x);
% Initialize the DFT array
X_manual = zeros(1, N);
% Compute the DFT manually
for k = 0:N-1
sum_val = 0;
for n = 0:N-1
sum_val = sum_val + x(n+1) * exp(-1j * 2 * pi * k * n / N);
end
X_manual(k+1) = sum_val;
end
% Compute the magnitude and phase
magnitude_manual = abs(X_manual);
phase_manual = angle(X_manual);
% Display the DFT result
disp('Manual DFT of x(n):');
disp(X_manual);
% Plot the magnitude and phase of the DFT
figure;
subplot(2,1,1);
stem(0:length(X_manual)-1, magnitude_manual, 'filled');
title('Magnitude of the Manual DFT');
xlabel('Frequency index (k)');
ylabel('Magnitude');
grid on;
subplot(2,1,2);
stem(0:length(X_manual)-1, phase_manual, 'filled');
title('Phase of the Manual DFT');
xlabel('Frequency index (k)');
ylabel('Phase (radians)');
grid on;
system identification using LMS
% System identification using LMS algorithms
clear; clc;
% Parameters for the simulation
N = 500; % Number of samples
M = 4; % Order of the system (number of taps)
u = randn(N, 1); % Input signal (white noise)
d = filter([1, -0.5, 0.25, 0.1], 1, u); % Desired output (unknown
system)
sigma_n = 0.1; % Noise variance
noise = sigma_n * randn(N, 1); % Additive noise
% Observed noisy signal
y = d + noise; % Noisy output signal
% LMS Parameters
mu = 0.1; % Step size for LMS algorithms
% Initialize weights
w_standard = zeros(M, 1); % Standard LMS weights
w_nlms = zeros(M, 1); % Normalized LMS weights
w_fxlms = zeros(M, 1); % Filtered-x LMS weights
% Initialize error vectors
e_standard = zeros(N, 1);
e_nlms = zeros(N, 1);
e_fxlms = zeros(N, 1);
% LMS Algorithm - Standard LMS
for n = M:N
x = u(n:-1:n-M+1); % Input vector (size M)
e_standard(n) = y(n) - w_standard' * x; % Error
w_standard = w_standard + mu * e_standard(n) * x; % Update
weights
end
% LMS Algorithm - Normalized LMS
for n = M:N
x = u(n:-1:n-M+1); % Input vector (size M)
e_nlms(n) = y(n) - w_nlms' * x; % Error
norm_factor = x' * x; % Normalization factor
w_nlms = w_nlms + mu * e_nlms(n) * x / norm_factor; %
Update weights
end
% LMS Algorithm - Filtered-x LMS
% Use a simple FIR filter (same as the desired system) for
FxLMS
for n = M:N
x = u(n:-1:n-M+1); % Input vector (size M)
e_fxlms(n) = y(n) - w_fxlms' * x; % Error
w_fxlms = w_fxlms + mu * e_fxlms(n) * x; % Update weights
end
% Compute Mean Squared Error (MSE) for each algorithm
mse_standard = mean(e_standard.^2);
mse_nlms = mean(e_nlms.^2);
mse_fxlms = mean(e_fxlms.^2);
% Display MSE results
disp(['MSE for Standard LMS: ', num2str(mse_standard)]);
disp(['MSE for Normalized LMS: ', num2str(mse_nlms)]);
disp(['MSE for Filtered-x LMS: ', num2str(mse_fxlms)]);
% Plot the errors
figure;
subplot(3,1,1);
plot(e_standard);
title('Error using Standard LMS');
xlabel('Sample Index');
ylabel('Error');
grid on;
subplot(3,1,2);
plot(e_nlms);
title('Error using Normalized LMS');
xlabel('Sample Index');
ylabel('Error');
grid on;
subplot(3,1,3);
plot(e_fxlms);
title('Error using Filtered-x LMS');
xlabel('Sample Index');
ylabel('Error');
grid on;
decimator_with_linear_phase_FIR_filter
% Parameters
fs = 1000; % Original sampling frequency (Hz)
N = 500; % Length of the input signal
decimation_factor = 4; % Decimation factor
filter_length = 14; % Length of the FIR filter (taps)
% Generate a test signal (sum of two sine waves with different
frequencies)
t = (0:N-1) / fs; % Time vector
x = sin(2*pi*50*t) + 0.5*sin(2*pi*150*t); % Signal with
frequencies 50 Hz and 150 Hz
% Design a low-pass FIR filter using the fir1 function
% The cutoff frequency is set to fs / (2 * decimation_factor)
cutoff_freq = fs / (2 * decimation_factor); % Cutoff frequency in
Hz
normalized_cutoff = cutoff_freq / (fs / 2); % Normalized cutoff
frequency (relative to Nyquist)
b = fir1(filter_length - 1, normalized_cutoff); % FIR filter
coefficients (linear phase)
% Apply the FIR filter to the input signal (low-pass filtering)
x_filtered = filter(b, 1, x); % Filtered signal
% Decimate the signal (downsample by a factor of 4)
x_decimated = downsample(x_filtered, decimation_factor);
% Compute the new sampling rate after decimation
fs_decimated = fs / decimation_factor;
% Plot the original and decimated signals
figure;
subplot(2,1,1);
plot(t, x);
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
t_decimated = (0:length(x_decimated)-1) / fs_decimated;
plot(t_decimated, x_decimated);
title('Decimated Signal (Downsampled by a factor of 4)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Display the frequency response of the filter
figure;
freqz(b, 1, 1024, fs); % Frequency response of the FIR filter
title('Frequency Response of the Low-pass FIR Filter');
two stage decimator
% Parameters
fs = 10000; % Input sampling frequency (10 KHz)
D = 100; % Decimation factor
Fpass = 50; % Passband frequency (Hz)
Fstop = 55; % Stopband frequency (Hz)
delta1 = 10^-1; % Passband ripple
delta2 = 10^-3; % Stopband ripple
% Stage 1 Decimation Factor
D1 = 10; % First stage decimation factor
D2 = D / D1; % Second stage decimation factor
% Design the first stage filter
% We need to design a low-pass filter with the following
specifications:
% Passband: 0 Hz to 50 Hz, Transition band: 50 Hz to 55 Hz
Fpass1 = Fpass; % Passband frequency for stage 1
Fstop1 = Fstop; % Stopband frequency for stage 1
% Normalized frequencies for filter design (relative to Nyquist
frequency)
Wn1 = [Fpass1 Fstop1] / (fs / 2); % Normalized passband and
stopband edges
Rp1 = -20 * log10(1 - delta1); % Passband ripple (dB)
Rs1 = -20 * log10(delta2); % Stopband attenuation (dB)
% Design the first stage low-pass filter using Chebyshev type I
filter
[b1,a1] = cheby1(10, Rp1, Wn1); % Filter order 10 (chosen
empirically)
% Stage 1: Apply filter to input signal
x = randn(1, fs); % Example input signal (white noise)
x_filtered_stage1 = filter(b1, a1, x); % Apply the stage 1 filter
% Stage 2 Decimation Factor
% Perform second stage decimation (filtering for the next
stage)
% We can reuse the
Cross correaltion
% Define the sequences
x = [-4, 5, 1, -2, -3, 0, 2]; % Sequence x(n), n = -3 to 3
w = [32, 2, -1, 0, -2, 5]; % Sequence w(n), n = 2 to 8
% Define the indices for x(n) and w(n)
n_x = -3:3; % Indices for x(n)
n_w = 2:8; % Indices for w(n)
% Compute the cross-correlation
[cross_corr, lags] = xcorr(x, w);
% Plot the cross-correlation
figure;
stem(lags, cross_corr, 'filled');
title('Cross-Correlation between x(n) and w(n)');
xlabel('Lag');
ylabel('Cross-Correlation');
grid on;
% Display the result
disp('Cross-correlation values:');
disp(cross_corr);
bartlett, Welch, Wiener and Linear Predictor are to be studied from ADSP record