Down Sampling: All All
Down Sampling: All All
clc;
clear all;
close all;
N=50;
n=0:1:N-1;
x=sin(2*pi*n/20)+sin(2*pi*n/15)
M=2;
x1=x(1:M:N);
n1=1:1:N/M;
subplot(2,1,1),stem(n,x)
xlabel('n'),ylabel('x')
title('input sequence')
subplot(2,1,2),stem(n1-1,x1)
xlabel('n'),ylabel('x1')
title('downsampled sequence')
OUTPUT WAVEFORM
UPSAMPLING
clc;
clear all;
close all;
N=10;
n=0:1:N-1;
x=sin(2*pi*n/10)+sin(2*pi*n/5)
L=3;
x1=[zeros(1,L*N)];
n1=1:1:L*N;
j=1:L:L*N;
x1(j)=x;
subplot(2,1,1),stem(n,x)
xlabel('n'),ylabel('x')
title('input sequence')
subplot(2,1,2),stem(n1,x1)
xlabel('n'),ylabel('x1')
title('upsampled sequence')
OUTPUT WAVEFORM
clc;
clear all;
close all;
n=0:1:1023;
x=1/4*sinc(1/4*(n-512)).^2
i=1:1024;
y=[zeros(1,2048)];
y(2*i)=x
f=-2:1/512:2;
h1=freqz(x,1,2*pi*f)
h2=freqz(y,1,2*pi*f)
subplot(3,1,1),plot(f,abs(h1))
xlabel('feequency'),ylabel('magnitude')
subplot(3,1,2),plot(f,abs(h2))
xlabel('feequency'),ylabel('magnitude')
y1=[zeros(1,3072)];
y1(3*i)=x
h3=freqz(y1,1,2*pi*f)
subplot(3,1,3),plot(f,abs(h3))
xlabel('frequency'),ylabel('magnitude')
OUTPUT WAVEFORM
b=[1 2 1];
a=[1 -2 4];
n=5;
b=[b zeros(1,n-1)];
[x,r]=deconv(b,a);
disp(x)
OUTPUT:
x (0) = 1, (1) = = 4, x(2) 5, x x (3) = -6, (4) = -32
NOISE CANCELLATION
clear
close all
order=2;
size=2;
fs=8192;
t=[0:1/fs:size];
N=fs*size;
f1=35/2;
f2=99/2;
voice=cos(2*pi*f1*t);
subplot(4,1,1)
plot(t,voice);
title('voice (don''t have access to)')
noise=cos(2*pi*f2*t.^2);
%increasy frequency noise
%noise=.1*rand(1,length(voice));
%white noise
primary=voice+noise;
subplot(4,1,2)
plot(t,primary)
title('primary = voice + noise (input1)')
ref=noise+.25*rand;
subplot(4,1,3)
plot(t,ref)
title('reference (noisy noise) (input2)');
w=zeros(order,1);
%noisy noise
mu=.006;
for i=1:N-order
buffer = ref(i:i+order-1);
%current 32 points of reference
desired(i) = primary(i)-buffer*w; %dot product reference and coeffs
w=w+(buffer.*mu*desired(i)/norm(buffer))';
%update coeffs
end
subplot(4,1,4)
plot(t(order+1:N),desired)
title('Adaptive output (hopefully it''s close to "voice")')
OUTPUT
CROSS-CORRELATION
x=[1,3,5,7];
h=[2,4,6,8];
y=corr(x,h);
figure;
subplot(3,1,1);
stem(x);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 1');
subplot(3,1,2);
stem(fliplr(y));
stem(h);
xlabel('n->');
ylabel('Amplitude->');
title('Input sequence 2');
subplot(3,1,3);
stem(fliplr(y));
xlabel('n->');
ylabel('Amplitude->');
title('Output sequence');
disp('The resultant is');
plot(y);
OUTPUT
clc;
clear all;
close all;
F=input('enter the highest normalized frequency component');
D=input('enter the decimation factor');
n=0:1:1024;
xd=F/2*sinc(F/2*(n-512)).^2;
%subplot(5,1,2),stem(n,xd)
f=-2:1/512:2
h1=freqz(xd,1,pi*f);
subplot(2,1,1),plot(f,abs(h1))
xd1=F/2*sinc(F/2*(n-512)*D).^2;
h2=freqz(xd1,1,pi*f*D);
subplot(2,1,2),plot(f,abs(h2))
axis([-2 2 0 1])
OUTPUT
enter the highest normalized frequency component.25
enter the decimation factor3
OUTPUT WAVEFORM
OUTPUT WAVEFORM
clc;
clear all;
close all;
F=input('enter the highest normalized frequency component');
D=input('enter the decimation factor');
n=0:1:1024;
%input sequense
xd=F/2*sinc(F/2*(n-512)).^2;
f=-2:1/512:2;
h1=freqz(xd,1,pi*f);%frequency response
subplot(3,1,1),plot(f,abs(h1));
xlabel('frequency'),ylabel('magnitude')
title('frequency response of input sequence')
%checking for aliasing
if(F*D<=1)
xd1=F/2*sinc(F/2*(n-512)*D).^2;
h2=freqz(xd1,1,pi*f*D);
subplot(3,1,2),plot(f,abs(h2))
axis([-2 2 0 1]);
h2=freqz(xd1,1,pi*D)
subplot(3,1,3),plot(f*D,abs(h2))
axis([-2*D 2*D 0 1])
else
%design antialiasing filter
p=fir1(127,1/D);%filter
xf=filter(p,1,xd);
h4=freqz(xf,1,pi*f);%output of filter
subplot(3,1,2),plot(f,abs(h4))
xlabel('frequency'),ylabel('magnitude')
title('frequency response of output of antialiasing filter')
i=1:1:1024/D;
xr=xf(i*D)%output of down sampler
h5=freqz(xr,1,pi*f*D);% frequency response at the output of down sampler
subplot(3,1,3),plot(f*D,abs(h5));
xlabel('frequency'),ylabel('magnitude')
title('frequency response of output of downsampler')
end
OUTPUT
enter the highest normalized frequency component.25
enter the decimation factor5
OUTPUT WAVEFORM
AUTO-CORRELATION
clear all;
x=[1,2,3,4];
y=xcorr(x,x);
figure;
subplot(2,1,1);
stem(x);
ylabel('Amplitude->');
xlabel('n->');
title('Input sequence');
subplot(2,1,2);
stem(fliplr(y));
ylabel('amplitude');
xlabel('n->');
title('Output sequence');
disp('the resultant is ');
fliplr(y)