Program To Perform The Following Operations On Signals. A) Signal Addition, B) Signal Multiplication, C) Scaling, D) Shifting, E) Folding
Program To Perform The Following Operations On Signals. A) Signal Addition, B) Signal Multiplication, C) Scaling, D) Shifting, E) Folding
X = dit_radix2_fft(x);
disp('Input sequence:');
disp(x);
function X = dit_radix2_fft(x)
N = length(x);
if N == 1
X = x;
return;
end
if mod(N, 2) ~= 0
error('The length of the input sequence must be a power of 2.');
end
x_even = x(1:2:N);
x_odd = x(2:2:N);
X_even = dit_radix2_fft(x_even);
X_odd = dit_radix2_fft(x_odd);
X = zeros(1, N);
for k = 1:N/2
twiddle_factor = exp(-2j * pi * (k-1) / N);
X(k) = X_even(k) + twiddle_factor * X_odd(k);
X(k + N/2) = X_even(k) - twiddle_factor * X_odd(k);
end
end
6 Using the DFT and IDFT, compute the following
x1 = [1, 2, 3, 4];
x2 = [1, 2, 1, 2];
N1 = length(x1);
N2 = length(x2);
N = max(N1, N2);
x1 = [x1, zeros(1, N-N1)];
x2 = [x2, zeros(1, N-N2)];
X1 = zeros(1, N);
X2 = zeros(1, N);
for k = 0:N-1
for n = 0:N-1
X1(k+1) = X1(k+1) + x1(n+1) * exp(-1i * 2 * pi * k * n / N);
X2(k+1) = X2(k+1) + x2(n+1) * exp(-1i * 2 * pi * k * n / N);
end
end
disp('The DFT of X1 is :')
disp('The DFT of X2 is :')
disp(X1)
disp(X2)
Y_circular = X1 .* X2;
y_circular = zeros(1, N);
for n = 0:N-1
for k = 0:N-1
y_circular(n+1) = y_circular(n+1) + Y_circular(k+1) * exp(1i * 2 * pi * k * n /
N);
end
end
y_circular = real(y_circular) / N;
N_linear = N1 + N2 - 1;
x1_padded = [x1, zeros(1, N_linear-N)];
x2_padded = [x2, zeros(1, N_linear-N)];
X1_padded = zeros(1, N_linear);
X2_padded = zeros(1, N_linear);
for k = 0:N_linear-1
for n = 0:N_linear-1
X1_padded(k+1) = X1_padded(k+1) + x1_padded(n+1) * exp(-1i * 2 * pi * k * n /
N_linear);
X2_padded(k+1) = X2_padded(k+1) + x2_padded(n+1) * exp(-1i * 2 * pi * k * n /
N_linear);
Y_linear = X1_padded .* X2_padded;
y_linear = zeros(1, N_linear);
for n = 0:N_linear-1
for k = 0:N_linear-1 end end
y_linear(n+1) = y_linear(n+1) + Y_linear(k+1) * exp(1i * 2 * pi * k * n /
N_linear);
y_linear = real(round(y_linear)) / N_linear;
figure; end end
subplot(2, 1, 1);
stem(0:N-1, y_circular, 'filled');
title('Circular Convolution using DFT and IDFT');
xlabel('n');
ylabel('y_{circular}[n]');
subplot(2, 1, 2);
stem(0:N_linear-1, y_linear, 'filled');
title('Linear Convolution using DFT and IDFT');
xlabel('n');
ylabel('y_{linear}[n]');
9Design and implementation of digital low pass FIR filter using a window
fs = 1000;
fc = 100;
N = 50;
wc = 2 * pi * fc / fs;
n = 0:N;
hd = (wc/pi) * sinc(wc * (n - N/2) / pi);
h = hd .* hamming(N+1)';
disp('FIR Filter Coefficients:');
disp(h);
[H, f] = freqz(h, 1, 1024, fs);
figure;
plot(f, abs(H));
title('Magnitude Response of the FIR Low-Pass Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
figure;
stem(n, h);
title('Impulse Response of the FIR Low-Pass Filter');
xlabel('Sample index (n)');
ylabel('Amplitude');
grid on;
t = 0:1/fs:1;
x = sin(2*pi*50*t) + sin(2*pi*200*t);
y = filter(h, 1, x);
figure;
subplot(2,1,1);
plot(t, x);
title('Original Signal (Sum of 50 Hz and 200 Hz)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t, y);
title('Filtered Signal (After FIR Low-Pass Filtering)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
10 Design and implementation of digital high pass FIR filter using a window
fs = 1000;
fc = 100;
N = 50;
window_type = 'hamming';
h=highpass_fir_filter(fs, fc, N, window_type);
disp('High-Pass FIR Filter Coefficients:');
disp(h);
[H, f] = freqz(h, 1, 1024, fs);
figure;
plot(f, abs(H));
title('Magnitude Response of the FIR High-Pass Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
figure;
stem(0:N, h);
title('Impulse Response of the FIR High-Pass Filter');
xlabel('Sample index (n)');
ylabel('Amplitude');
grid on;
t = 0:1/fs:1;
x = sin(2*pi*50*t) + sin(2*pi*200*t);
y = filter(h, 1, x);
figure;
subplot(2,1,1);
plot(t, x);
title('Original Signal (Sum of 50 Hz and 200 Hz)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t, y);
title('Filtered Signal (After FIR High-Pass Filtering)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
11 Design and implementation of digital IIR Butterworth low pass
fs = 1000;
fc = 100;
order = 4;
Wn = 2 * fc / fs;
[b, a] = butter(order, Wn, 'low');
disp('Butterworth Filter Coefficients:');
disp('Numerator coefficients (b):');
disp(b);
disp('Denominator coefficients (a):');
disp(a);
[H, f] = freqz(b, a, 1024, fs);
figure;
plot(f, abs(H));
title('Magnitude Response of the Butterworth Low-Pass Filter');
xlabel('Frequency (Hz)');
ylabel('Magnitude');
grid on;
figure;
plot(f, angle(H));
title('Phase Response of the Butterworth Low-Pass Filter');
xlabel('Frequency (Hz)');
ylabel('Phase (radians)');
grid on;
t = 0:1/fs:1;
x = sin(2*pi*50*t) + sin(2*pi*200*t);
y = filter(b, a, x);
figure;
subplot(2,1,1);
plot(t, x);
title('Original Signal (Sum of 50 Hz and 200 Hz)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;
subplot(2,1,2);
plot(t, y);
title('Filtered Signal (After Butterworth Low-Pass Filtering)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;