0% found this document useful (0 votes)
8 views7 pages

Signal Processing Operations and Filters

Uploaded by

preamgowda756
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views7 pages

Signal Processing Operations and Filters

Uploaded by

preamgowda756
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program to perform the following operations on signals.

a) Signal addition, b) Signal multiplication,


c)Scaling, d) Shifting, e)Folding
n = -10:10;
x1 = sin(0.2*pi*n);
x2 = cos(0.2*pi*n);
signal_addition = x1 + x2;
signal_multiplication = x1 .* x2;
scaling_factor = 2;
scaled_signal = scaling_factor * x1;
shift_amount = 3;
shifted_signal = circshift(x1, shift_amount);
folded_signal = fliplr(x1);
figure;
subplot(3,2,1);
stem(n, x1, 'filled');
title('Original Signal x1');
xlabel('n');
ylabel('x1[n]');
subplot(3,2,2);
stem(n, x2, 'filled');
title('Original Signal x2');
xlabel('n');
ylabel('x2[n]');
subplot(3,2,3);
stem(n, signal_addition, 'filled');
title('Signal Addition: x1[n] + x2[n]');
xlabel('n');
ylabel('x1[n] + x2[n]');
subplot(3,2,4);
stem(n, signal_multiplication, 'filled');
title('Signal Multiplication: x1[n] * x2[n]');
xlabel('n');
ylabel('x1[n] * x2[n]');
subplot(3,2,5);
stem(n, scaled_signal, 'filled');
title(['Scaled Signal: ' num2str(scaling_factor) ' * x1[n]']);
xlabel('n');
ylabel([num2str(scaling_factor) ' * x1[n]']);
figure;
subplot(2,2,1);
stem(n, shifted_signal, 'filled');
title(['Shifted Signal: x1[n-' num2str(shift_amount) ']']);
xlabel('n');
ylabel(['x1[n-' num2str(shift_amount) ']']);
subplot(2,2,2);
stem(n, folded_signal, 'filled');
title('Folded Signal: x1[-n]');
xlabel('n');
ylabel('x1[-n]');
Program to perform convolution of two given sequences
x1 = [1, 2, 3, 4]
x2 = [1, -1, 2]
N1 = length(x1);
N2 = length(x2);
N = N1 + N2 - 1;
x1_padded = [x1, zeros(1, N2-1)]
x2_padded = [x2, zeros(1, N1-1)]
y = zeros(1, N);
for n = 1:N
for k = 1:N1
if (n-k+1 > 0 && n-k+1 <= N2)
y(n) = y(n) + x1_padded(k) * x2_padded(n-k+1);
end
end
end
4)disp(y)
n_result = 0:N-1;
figure;
subplot(3,1,1);
stem(0:N1-1, x1, 'filled');
title('Sequence x1');
xlabel('n');
ylabel('x1[n]');
subplot(3,1,2);
stem(0:N2-1, x2, 'filled');
title('Sequence x2');
xlabel('n');
ylabel('x2[n]');
subplot(3,1,3);
stem(n_result, y, 'filled');
title('Convolution of x1 and x2');
xlabel('n');
ylabel('y[n]');
a = [1 -0.9];
b = 1;
[H, z] = tf2zpk(b, a);
zplane(b, a);
title('Pole-Zero Plot of H(z)');
xlabel('Real Part');
ylabel('Imaginary Part');
[H_ejw, w] = freqz(b, a, 'whole');
subplot(2,1,1);
plot(w/pi, abs(H_ejw));
title('Magnitude Response |H(e^{j\omega})|');
xlabel('\omega / \pi');
ylabel('|H(e^{j\omega})|');
subplot(2,1,2);
plot(w/pi, angle(H_ejw));
title('Phase Response ?H(e^{j\omega})');
xlabel('\omega / \pi');
ylabel('Phase (radians)');
n = 0:20;
h = filter(b, a, [1 zeros(1, length(n)-1)]);
figure;
stem(n, h, 'filled');
title('Impulse Response h(n)');
xlabel('n');
ylabel('h[n]');
5Computation of N point DFT of a given sequence
x = [1, 2, 3, 4];
N = length(x);
x = [x, zeros(1, N-length(x))];
X = zeros(1, N);
for k = 0:N-1
for n = 0:N-1
X(k+1) = X(k+1) + x(n+1) * exp(-1i * 2 * pi * k * n / N);
end
end
disp('the N poiny DFT is:')
disp(X)
k = 0:N-1;
magnitude_spectrum = abs(X);
phase_spectrum = angle(X);
figure;
subplot(2,1,1);
stem(k, magnitude_spectrum, 'filled');
title('Magnitude Spectrum');
xlabel('Frequency Index k');
ylabel('|X(k)|');
subplot(2,1,2);
stem(k, phase_spectrum, 'filled');
title('Phase Spectrum');
xlabel('Frequency Index k');
ylabel('?X(k) (radians)');

8Develop decimation in time radix-2 FFT algorithm


x = [1, 2, 3, 4, 5, 6, 7, 8];

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;

Common questions

Powered by AI

The FFT algorithm substantially reduces computational complexity from O(N^2) in DFT to O(N log N), allowing for faster processing of large datasets. This efficiency makes FFT advantageous for real-time signal processing tasks, where speed and resource management are critical. Additionally, FFT's recursive structure can leverage hardware optimizations and parallel processing .

The twiddle factor, exp(-2j * pi * (k-1) / N), is crucial for combining the even and odd parts of the FFT. It computes the needed phase shift for each frequency bin, ensuring the proper alignment and scaling of frequencies during the recombination of recursive FFT results. This factor is essential for the correct spectral decomposition in the Radix-2 FFT .

Applying a window function like Hamming in FIR filter design mitigates the side lobes of the filter’s frequency response, reducing leakage and improving selectivity. The Hamming window provides a moderate side lobe attenuation with a broad main lobe, balancing between reducing side lobes and preserving the important frequency components. This can significantly affect the filter's performance in minimizing aliasing and spectral leakage .

FIR filters like those designed using windows are inherently stable and exhibit a linear phase response, which is essential for applications requiring phase linearity. These are typically easier to design and implement. IIR filters, such as Butterworth filters, provide a sharper cutoff with fewer coefficients, making them computationally efficient for achieving precise cutoff characteristics. However, they might introduce phase distortion and potential instability without careful design .

Filter order and cutoff frequency directly influence the FIR filter's transition band and attenuation characteristics. A higher filter order generally sharpens the transition band, improving the cutoff precision but at the cost of increased computational complexity. The cutoff frequency sets the range that the filter passes, and an inaccurate selection can result in attenuation of desired components or a lack of attenuation of undesired ones .

The zero-padding of sequences x1 and x2 allows them to be of equal length for DFT operations, ensuring circular convolution mimics linear convolution. This padding leads to alignment of discrete signals in frequency domain, facilitating element-wise multiplication to achieve circular convolution. The zero-padding affects the time-domain reconstruction, highlighting the necessity to account for potential boundary artifacts after inverse transformations .

Signal addition involves the pointwise addition of two signals, x1 and x2, resulting in a new signal that combines the characteristics of both, often increasing the signal's amplitude range. In contrast, signal multiplication involves the pointwise product of the two signals, which tends to accentuate concurrent peaks and suppresses non-overlapping features. This operation results in a new signal highlighting the interaction between the two .

Circular shifting ensures that when elements of the signal are shifted beyond the bounds, they wrap around to the beginning, maintaining continuity without loss of data. This is particularly useful in applications where periodicity is assumed. In contrast, a linear shift would move elements outside the original range, potentially leading to data loss at boundaries .

The folding operation transforms the signal x1 into its time-reversed version, effectively flipping it along the vertical axis. Mathematically, if x1[n] is the original signal, the folded signal is x1[-n], resulting in a reversal of the sequence order .

Zero-padding ensures that the sequences are of equal length, preventing aliasing during circular convolution by forcing it to mimic linear convolution. For circular convolution, zero-padding helps differentiate between genuine periodicity and truncation artifacts. In linear convolution, sufficient zero-padding extends sequence lengths to avoid overlap of circular components, maintaining linear convolution characteristics .

You might also like