questions_to_be_revised-6
questions_to_be_revised-6
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;
% Downsampling
x_downsampled = downsample(x, D);
fs_downsampled = fs / D;
N_down = length(x_downsampled);
f_down = linspace(-fs_downsampled/2, fs_downsampled/2,
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;
% Time vector
t = 0:1/fs:T-1/fs;
% Original signal
x = sin(2*pi*f1*t) + sin(2*pi*f2*t);
% Decimation (downsampling)
x_decimated = downsample(x_filtered, D);
fs_decimated = fs / D;
% Interpolation (upsampling)
x_interpolated = upsample(x_decimated, I);
% Plotting
figure;
% Original signal
subplot(4,1,1);
plot(t, x);
title('Original Signal');
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)
% Plotting
figure;
% Original signal
subplot(3,1,1);
plot(t, x, '-b');
title('Original Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
% Parameters
fs = 1000; % Sampling frequency (Hz)
T = 2; % Duration (seconds)
t = 0:1/fs:T-1/fs; % Time vector
% Generate noise
noise = 0.5 * randn(size(t)); % Gaussian noise
% Initialize buffers
output_signal = zeros(1, n_iterations);
error_signal = zeros(1, n_iterations);
% Plot results
figure;
% Noisy signal
subplot(3,1,2);
plot(t, noisy_signal, 'r');
title('Noisy Signal (Desired Signal + Noise)');
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
% 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
% Display results
disp('Frequency-domain sequence (X):');
disp(X);
disp('Time-domain sequence (x) after IDFT:');
disp(x.');
% Plot results
figure;
% 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);
% Parameters
fs = 1000; % Sampling frequency (Hz)
T = 1; % Duration of signal (seconds)
t = 0:1/fs:T-1/fs; % Time vector
% 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
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;
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];
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
% 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
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)
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;
% 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