Académique Documents
Professionnel Documents
Culture Documents
clc;
clear all;
close all;
a=input('Enter the starting point of x[n]=');
b=input('Enter the starting point of h[n]=');
x=input('Enter the co-efficients of x[n]=');
h=input('Enter the co-efficients of h[n]=');
y=conv(x,h);
subplot(3,1,1);
p=a:(a+length(x)-1);
stem(p,x);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=b:(b+length(h)-1);
stem(q,h);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=a+b:length(y)+a+b-1;
stem(n,y);
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('LINEAR CONVOLUTION');
Input:
starting point of x[n]=0
starting point of h[n]=0
co-efficients of x[n]=[1 2 3 4 5]
co-efficients of h[n]=[1 1 1]
y[n]= 1 3 6 9 12 9 5
%GENERATION OF SINE WAVE
clf;
n=0:100;
f=0.05;
a=4;
x=a*sin(2*pi*f*n);
subplot(2,2,1);
stem(n ,x,'k.');
xlabel('Sine');
axis([0 100 -4 4]);
grid on;
%NOISY SIGNAL; SINE + NOISE
z=x';
y1 = wgn(101,1,2);
y2 = y1+z;
subplot(2,2,2);
stem(n,y2,'k.');
xlabel('Sine + Noise');
axis([0 100 -6 6]);
grid on;
%AVERAGE FILTER
M = input('Number of input samples = ');
b=ones(M,1)/M;
subplot(2,2,3);
stem(b,'k.');
xlabel('Average Filter');
grid on;
%REMOVAL OF NOISE FROM SIGNAL
g = conv(b,y2);
subplot(2,2,4);
stem(g,'k.');
xlabel('Convolution');
axis([0 100 -4.5 4.5]);
grid on;
Input:
input samples = 10
clf;
a = 0;
while (a==0)
x1=input('Type in the first sequence:');
x2=input('Type in the second sequence:');
y= xcorr(x1,x2);
stem(y,'b-');
xlabel('Time Index n'); ylabel('Amplitude');
grid on;
title('Correlation between x1 & x2');
a=input('Enter "0" to continue and "1" to quit:');
end
Input:
first sequence:[1 2 3 4 5]
second sequence:[1 1 1 1]
%Generation of a Sine Wave
clf;
n=0:100;
f=0.05;
a=4;
x=a*sin(2*pi*f*n);
subplot(3,2,1);
stem(x,'k.');
xlabel('Sine wave');
axis([0 100 -4 4]);
grid on;
%Generation of Noise
y1 = wgn(100,1,2);
subplot(3,2,3);
stem(y1,'k.');
xlabel('Random noise');
grid on;
% Autocorrelation of Noise
y2=xcorr(y1,y1);
subplot(3,2,4);
stem(y2,'k.');
xlabel('Its autocorrelation');
axis([0 100 -350 450]);
grid on;
%Sine + Noise
x=a*sin(2*pi*f*n);
z=x';
y1 = wgn(101,1,2);
y2 = y1+z;
subplot(3,2,5);
stem(y2,'k.');
xlabel('(a) Sine with noise');
axis([0 100 -6.5 6.5]);
grid on;
clf;
close all;
x=[1,2,3];
h=[1,1,1,1,1];
y=conv(x,h);
subplot(3,1,1)
p=0:(length(x)-1);
stem(p,x);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=0:(length(h)-1);
stem(q,h);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=0:length(y)-1;
stem(n,y);
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('LINEAR CONVOLUTION');
INPUT:
y[n]= 1 3 6 6 6 5 3
clc;
clf;
close all;
x=[1,2,3,4,5];
h=[1];
y=conv(x,h);
subplot(3,1,1)
p=0:(length(x)-1);
stem(p,x);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=0:(length(h)-1);
stem(q,h);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=0:length(y)-1;
stem(n,y);
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('LINEAR CONVOLUTION');
INPUT:
y[n]= 1 2 3 4 5
clc;
clf;
close all;
x=[1,-2,0,2,1];
h=x;
y=conv(x,h);
subplot(3,1,1)
p=0:(length(x)-1);
stem(p,x);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('INPUT x(n)');
subplot(3,1,2);
q=0:(length(h)-1);
stem(q,h);
grid on;
xlabel('Time');
ylabel('Amplitude');
title('IMPULSE RESPONSE h(n)');
subplot(3,1,3);
n=0:length(y)-1;
stem(n,y);
grid on;
disp(y)
xlabel('Time');
ylabel('Amplitude');
title('LINEAR CONVOLUTION');
INPUT:
y[n]= 1 -4 4 4 -6 -4 4 4 1