SSP Lab1
SSP Lab1
CALICUT
Code:
Output:
SNR value calculation:
Inferences:
As you can see for the first FIR filter we have taken the following specification (alpha = 0.4; sigma^2
= 0.25, D =1, A=0.1, P=2).
• The signal to noise ratio for the noisy signal is 7.40.
• The signal to noise ratio for the estimated signal for L2 tap is 9.18.
• So, there is a significant increase in the SNR for estimated signal.
• From a signal plot we can see that the range of error signal is much lesser than x(n) – y(n).
• From the power spectral density curves we can see that the estimated signal is close to the
original signal.
• And the Noisy signal y(n) He’s going to the sigma^2(in this case 0.25) value when n tends to
infinity.
• PSD at f = 0 Hz is 2.3
So the frequency value corresponding to the PSD value 1.15 = 1350.2 Hz
That is bandwidth is 1350.2 Hz
Code:
% L=2, alpha = 0.3; sigma^2 = 0.3, D =1, A=0.5, P=1
clear all;
close all;
clc;
N=100;
alpha =0.3;
a = 0.5;
P = 1;
sigma_2 = 0.3;
v = randn(1,N);
x = zeros(N);
x(1) = v(1);
y = zeros(N);
k = -N/2:1:N/2-1;
r_x = P * alpha.^abs(k);
% random signal generation
for i = 2:1:N
x(i) = P*alpha*x(i-1) + v(i);
end
subplot(5,1,1);
stem(k,x);
title('Generated Random Signal (X)');
%subplot(4,1,2);
%stem(k,r_x);
%title('Autocorrelated Function (r_x)');
% noisy signal generation
r = normrnd(0,sqrt(sigma_2),N);
for i = 2:1:N
y(i) = x(i)+ a*x(i-1) + r(i);
end
subplot(5,1,2);
stem(k,y);
title('Y (Noisy Signal)');
% estimated signal X_hat calculation
x_hat = zeros(N);
A = [1.85 0.92; 0.92 1.85];
B = [1.15 ;0.345];
W = inv(A )*B;
w0 = W(1);
w1 = W(2);
for i = 2:1:N
x_hat(i) = w0*y(i) + w1*y(i-1);
end
subplot(5,1,3);
stem(k,x_hat);
title('x_h (Estimated Signal)');
e = zeros(N);
for i = 2:1:N
e(i) = x(i) - x_hat(i);
end
subplot(5,1,4);
stem(k,e);
title('error signal');
m = zeros(N);
for i = 2:1:N
m(i) = y(i) - x(i);
end
subplot(5,1,5);
stem(k,m);
title('x(n) -y(n)')
% Error and SNR claculation of the estimated signal
MMSE = P - B.' * W;
fprintf('Minimum Mean Squared Error(Estimated)\n');
disp(MMSE);
SNR = P/MMSE;
fprintf('Signal to Noise Ratio(Estimated)\n');
disp(SNR);
% Error and SNR calculation of noisy signal
Total_noise_power = a*a*P +sigma_2;
SNR_original = P/Total_noise_power;
fprintf('Signal to Noise Ratio(Original)\n');
disp(SNR_original);
fprintf('SNR(Estimated) is improved that SNR(Original )');
% Power Spectral Density of the random signal
N=100;
w = -3:0.0001:3;
neu = 1-alpha*alpha;
deno = P*(1+alpha*alpha-2*alpha*cos(w));
p_x = (neu)./(deno);
figure;
subplot(3,1,1);
Fs = 8000;
fq = (w*Fs)/(2*pi);
plot(fq,p_x);
title('Power spectral density of x')
p_y = ((1+a^2)+ 2*a*cos(w)).*p_x + sigma_2;
% Power Spectral Density of Noisy signal
subplot(3,1,2);
plot(fq,p_y);
title('Power spectral density of y')
% Power Spectral Density of Estimated signal
p_x_hat = (w0^2 +w1^2+2*w0*w1*cos(w) ).*p_y;
subplot(3,1,3);
plot(fq,p_x_hat);
title('Power spectral density of x_h')
Output:
SNR value calculation:
Code:
% L=2, alpha = 0.7; sigma^2 = 0.25, D =1, A=1.5, P=1
clear all;
close all;
clc;
N=100;
alpha =0.7;
a = 1.5;
P = 1;
sigma_2 = 0.25;
v = randn(1,N);
x = zeros(N);
x(1) = v(1);
y = zeros(N);
k = -N/2:1:N/2-1;
r_x = P * alpha.^abs(k);
% random signal generation
for i = 2:1:N
x(i) = P*alpha*x(i-1) + v(i);
end
subplot(4,1,1);
stem(x);
title('Generated Random Signal (X)');
subplot(4,1,2);
stem(k,r_x);
title('Autocorrelated Function (r_x)');
% noisy signal generation
r = normrnd(0,sqrt(sigma_2),N);
for i = 2:1:N
y(i) = x(i)+ a*x(i-1) + r(i);
end
subplot(4,1,3);
stem(k,y);
title('Y (Noisy Signal)');
% estimated signal X_hat calculation
x_hat = zeros(N);
A = [5.6 4.51; 4.51 5.6];
B = [2.05 ;1.435];
W = inv(A )*B;
w0 = W(1);
w1 = W(2);
for i = 2:1:N
x_hat(i) = w0*y(i) + w1*y(i-1);
end
subplot(4,1,4);
stem(k,x_hat);
title('x_h (Estimated Signal)');
% Error and SNR claculation of the estimated signal
MMSE = P - B.' * W;
fprintf('Minimum Mean Squared Error(Estimated)\n');
disp(MMSE);
SNR = P/MMSE;
fprintf('Signal to Noise Ratio(Estimated)\n');
disp(SNR);
% Error and SNR calculation of noisy signal
Total_noise_power = a*a*P +sigma_2;
SNR_original = P/Total_noise_power;
fprintf('Signal to Noise Ratio(Original)\n');
disp(SNR_original);
fprintf('SNR(Estimated) is improved that SNR(Original )');
% Power Spectral Density of the random signal
N=100;
w = -3:0.0001:3;
neu = 1-alpha*alpha;
deno = P*(1+alpha*alpha-2*alpha*cos(w));
p_x = (neu)./(deno);
figure;
subplot(3,1,1);
Fs = 8000;
fq = (w*Fs)/(2*pi);
plot(fq,p_x);
title('Power spectral density of x')
p_y = ((1+a^2)+ 2*a*cos(w)).*p_x + sigma_2;
% Power Spectral Density of Noisy signal
subplot(3,1,2);
plot(fq,p_y);
title('Power spectral density of y')
% Power Spectral Density of Estimated signal
p_x_hat = (w0^2 +w1^2+2*w0*w1*cos(w) ).*p_y;
subplot(3,1,3);
plot(fq,p_x_hat);
title('Power spectral density of x_h')
Output:
SNR value calculation:
Signal plots:
PSD of x(n), y(n), and x_hat(n):
Inferences:
As you can see for the first FIR filter we have taken the following specification (alpha = 0.7; sigma^2
= 0.25, D =1, A=1.5, P=1).
• The signal to noise ratio for the noisy signal is 0.4.
• The signal to noise ratio for the estimated signal for L2 tap is 4.42.
• So, there is a significant increase in the SNR for estimated signal.
• From a signal plot we can see that the range of error signal is almost same as x(n) – y(n). This
is because due to A=1.5 the main component of noisy signal is the echo.
• From the power spectral density curves we can see that the estimated signal is close to the
original signal.
• As we can see the SNR value is smaller than the previous one because here we’re taking P = 1
that is decreasing the overall SNR value both in case of noisy signal and estimated signal.
• The MMSE is 0.225 ,which is higher than the previous case because here the power of the
noise increases due to the increase in sigma^2 and A.
• The main part of noise power is the power of echo signal.
Code:
% L=2, alpha = 0.4; sigma^2 = 0.25, D =1, A=0.1, P=1
%FIR
clear all;
close all;
clc;
N=100;
alpha =0.4;
sigma_2 =0.25;
P = 1;
a=0.1;
v = randn(1,N);
x = zeros(N);
x(1) = v(1);
y = zeros(N);
k = -N/2:1:N/2-1;
r_x = P * alpha.^abs(k);
% random signal generation
for i = 2:1:N
x(i) = P*alpha*x(i-1) + v(i);
end
subplot(5,1,1);
stem(k,x);
title('Generated Random Signal (X)');
%subplot(4,1,2);
%stem(k,r_x);
%title('Autocorrelated Function (r_x)');
% noisy signal generation
r = normrnd(0,sqrt(sigma_2),N);
for i = 2:1:N
y(i) = x(i)+ a*x(i-1) + r(i);
end
subplot(4,1,2);
stem(k,y);
title('Y (Noisy Signal)');
% estimated signal X_hat calculation
x_hat = zeros(N);
A = [1.85 0.92; 0.92 1.85];
B = [1.15 ;0.345];
W = inv(A )*B;
w0 = W(1);
w1 = W(2);
for i = 2:1:N
x_hat(i) = w0*y(i) + w1*y(i-1);
end
subplot(4,1,3);
stem(k,x_hat);
title('x_h (Estimated Signal)');
e = zeros(N);
for i = 2:1:N
e(i) = x(i) - x_hat(i);
end
subplot(5,1,4);
stem(k,e);
title('error signal');
m = zeros(N);
for i = 2:1:N
m(i) = y(i) - x(i);
end
subplot(5,1,5);
stem(k,m);
title('x(n) -y(n)')
% Error and SNR claculation of the estimated signal
MMSE = P - B.' * W;
fprintf('Minimum Mean Squared Error(Estimated)\n');
disp(MMSE);
SNR = P/MMSE;
fprintf('Signal to Noise Ratio(Estimated)\n');
disp(SNR);
% Error and SNR calculation of noisy signal
Total_noise_power = a*a*P +sigma_2;
SNR_original = P/Total_noise_power;
fprintf('Signal to Noise Ratio(Original)\n');
disp(SNR_original);
fprintf('SNR(Estimated) is improved that SNR(Original )');
% Power Spectral Density of the random signal
N=100;
w = -3:0.0001:3;
neu = 1-alpha*alpha;
deno = P*(1+alpha*alpha-2*alpha*cos(w));
p_x = (neu)./(deno);
figure;
subplot(3,1,1);
Fs = 8000;
fq = (w*Fs)/(2*pi);
plot(fq,p_x);
title('Power spectral density of x')
p_y = ((1+a^2)+ 2*a*cos(w)).*p_x + sigma_2;
% Power Spectral Density of Noisy signal
subplot(3,1,2);
plot(fq,p_y);
title('Power spectral density of y')
% Power Spectral Density of Estimated signal
p_x_hat = (w0^2 +w1^2+2*w0*w1*cos(w) ).*p_y;
subplot(3,1,3);
plot(fq,p_x_hat);
title('Power spectral density of x_h')
Output:
SNR value calculation:
Inferences:
As you can see for the first FIR filter we have taken the following specification (alpha = 0.4; sigma^2
= 0.25, D =1, A=0.1, P=1).
• The signal to noise ratio for the noisy signal is 3.84.
• The signal to noise ratio for the estimated signal for L2 tap is 4.03.
• So, there is a significant increase in the SNR for estimated signal.
• From a signal plot we can see that the range of error signal is much lesser than x(n) – y(n).
• From the power spectral density curves we can see that the estimated signal is close to the
original signal.
• And the Noisy signal y(n) He’s going to the sigma^2(in this case 0.25) value when n tends to
infinity.
• The overall SNR value decreases because the overall power also decreases for P=1.
Code:
%IIR filter
% L=2, alpha = 0.4; sigma^2 = 0.25, D =1, A=0.1, P=1
clear all;
close all;
clc;
N=100;
alpha =0.4;
sigma_2 =0.25;
P = 1;
a=0.1;
v = randn(1,N);
x = zeros(N);
x(1) = v(1);
y = zeros(N);
k = -N/2:1:N/2-1;
r_x = P * alpha.^abs(k);
% random signal generation
for i = 2:1:N
x(i) = P*alpha*x(i-1) + v(i);
end
subplot(5,1,1);
stem(x);
title('Generated Random Signal (X)');
%subplot(4,1,2);
%stem(k,r_x);
%title('Autocorrelated Function (r_x)');
% noisy signal generation
w = normrnd(0,sqrt(sigma_2),N);
for i = 2:1:N
y(i) = x(i)+ a*x(i-1) + w(i);
end
subplot(5,1,2);
stem(k,y);
title('Y (Noisy Signal)');
% estimated signal X_hat calculation
x_hat = zeros(N);
B = [2.08 ;0.83; 0.18];
w0 = 0.08;
w1 = 0.74;
w2 = 0.01;
W = [w0 ;w1 ;w2];
for i = 2:1:N
x_hat(i) = 0.74*y(i) + 0.01*y(i-1)+ 0.08*y(i+1);
end
subplot(5,1,3);
stem(k,x_hat);
title('x_h (Estimated Signal)');
e = zeros(N);
for i = 2:1:N
e(i) = x(i) - x_hat(i);
end
subplot(5,1,4);
stem(k,e);
title('error signal');
m = zeros(N);
for i = 2:1:N
m(i) = y(i) - x(i);
end
subplot(5,1,5);
stem(k,m);
title('x(n) -y(n)')
% Error and SNR claculation of the estimated signal
MMSE = P - B.' * W;
fprintf('Minimum Mean Squared Error(Estimated)\n');
disp(MMSE);
SNR = P/MMSE;
fprintf('Signal to Noise Ratio(Estimated)\n');
disp(SNR);
% Error and SNR calculation of noisy signal
Total_noise_power = a*a*P +sigma_2;
SNR_original = P/Total_noise_power;
fprintf('Signal to Noise Ratio(Original)\n');
disp(SNR_original);
fprintf('SNR(Estimated) is improved that SNR(Original )');
% Power Spectral Density of the random signal
N=100;
w = -pi:0.0001:pi;
alpha =0.4;
neu = 1-alpha*alpha;
deno = (1+alpha*alpha-2*alpha*cos(w));
p_x = (neu)./(deno);
figure;
subplot(2,1,1);
Fs = 8000;
fq = (w*Fs)/(2*pi);
plot(fq,p_x);
title('Power spectral density of x')
p_y = (1.01+ 0.2*cos(w)).*p_x + sigma_2;
% Power Spectral Density of Noisy signal
subplot(2,1,2);
plot(fq,p_y);
title('Power spectral density of y')
Power Spectral Density of Estimated signal
p_x_hat = (w0^2 +w1^2+2*w0*w1*cos(w) ).*p_y;
subplot(3,1,3);
plot(w,p_x_hat);
title('Power spectral density of x_h')
Output:
SNR value calculation:
Minimum Mean Squared Error(Estimated)
0.2176
Code:
%cloured noise FIR
% L=2, alpha = 0.4; sigma^2 = 0.25, D =1, A=0.1, P=1
clear all;
close all;
clc;
N=100;
alpha =0.4;
sigma_2 =0.25;
P = 1;
a=0.1;
v = randn(1,N);
x = zeros(N);
x(1) = v(1);
y = zeros(N);
k = -N/2:1:N/2-1;
r_x = P * alpha.^abs(k);
% random signal generation
for i = 2:1:N
x(i) = P*alpha*x(i-1) + v(i);
end
subplot(5,1,1);
stem(x);
title('Generated Random Signal (X)');
%subplot(5,1,2);
%stem(k,r_x);
%title('Autocorrelated Function (r_x)');
% noisy signal generation
r = zeros(N);% White Noise
for i = 2:1:N
r(i) = sqrt(sigma_2/2)*v(i-1) + sqrt(sigma_2/2)*v(i);
end
for i = 2:1:N
y(i) = x(i)+ a*x(i-1) + r(i);
end
subplot(5,1,2);
stem(k,y);
title('Y (Noisy Signal)');
% estimated signal X_hat calculation
x_hat = zeros(N);
A = [1.34 0.645; 0.645 1.34];
B = [1.04 ;0.42];
W = inv(A)*B;
w0 = W(1);
w1 = W(2);
for i = 2:1:N
x_hat(i) = w0*y(i) + w1*y(i-1);
end
subplot(5,1,3);
stem(k,x_hat);
title('x_h (Estimated Signal)');
e = zeros(N);
for i = 2:1:N
e(i) = x(i) - x_hat(i);
end
subplot(5,1,4);
stem(k,e);
title('error signal');
m = zeros(N);
for i = 2:1:N
m(i) = y(i) - x(i);
end
subplot(5,1,5);
stem(k,m);
title('x(n) -y(n)')
% Error and SNR claculation of the estimated signal
MMSE = P - B.' * W;
fprintf('Minimum Mean Squared Error(Estimated)\n');
disp(MMSE);
SNR = P/MMSE;
fprintf('Signal to Noise Ratio(Estimated)\n');
disp(SNR);
% Error and SNR calculation of noisy signal
Total_noise_power = a*a*P +sigma_2;
SNR_original = P/Total_noise_power;
fprintf('Signal to Noise Ratio(Original)\n');
disp(SNR_original);
fprintf('SNR(Estimated) is improved that SNR(Original )');
% Power Spectral Density of the random signal
N=100;
w = -3:0.0001:3;
neu = 1-alpha*alpha;
deno = P*(1+alpha*alpha-2*alpha*cos(w));
p_x = (neu)./(deno);
figure;
subplot(3,1,1);
Fs = 8000;
fq = (w*Fs)/(2*pi);
plot(fq,p_x);
title('Power spectral density of x')
p_y = ((1+a^2)+ 2*a*cos(w)).*p_x + sigma_2*(1+cos(w));
% Power Spectral Density of Noisy signal
subplot(3,1,2);
plot(fq,p_y);
title('Power spectral density of y')
% Power Spectral Density of Estimated signal
p_x_hat = (w0^2 +w1^2+2*w0*w1*cos(w) ).*p_y;
subplot(3,1,3);
plot(fq,p_x_hat);
title('Power spectral density of x_h')
Output:
SNR value calculation:
Inferences:
As you can see for the first FIR filter we have taken the following specification (alpha = 0.4; sigma^2
= 0.25, D =1, A=0.1, P=2). But in this case we are taking coloured noise rather than white noise.
• The signal to noise ratio for the noisy signal is 3.84.
• The signal to noise ratio for the estimated signal for L2 tap is 5.36.
• So, there is a significant increase in the SNR for estimated signal.
• From a signal plot we can see that the range of error signal is much lesser than x(n) – y(n).
• From the power spectral density curves we can see that the estimated signal is close to the
original signal.
• And the Noisy signal y(n) He’s going to the sigma^2(in this case 0.25) value when n tends to
infinity.
• In case of coloured noise the snr improvement is the highest.
In the following section some of the theoretical calculations are added which is needed to implement
the above experiments.