DSP Experiments
DSP Experiments
AUTOCORRELATION CODE:
plot(ind, c)
plot(ind, c)
EXP-7
clc;
clear;
close;
fs = 1000;
t = 0:1/fs:1;
num_bits = 3;
L = 2^num_bits;
xmin = min(x);
xmax = max(x);
subplot(2,1,1);
plot2d(t, x, style=1);
title("Original Signal");
subplot(2,1,2);
disp("Quantization completed.");
EXP-8
clc;
clear;
close;
fs = 1000;
t = 0:1/fs:1;
f = 10;
num_bits = 3;
L = 2^num_bits;
subplot(2,1,1);
plot2d(t, x, style=1);
title("Original Signal");
xlabel("Time (s)");
ylabel("Amplitude");
subplot(2,1,2);
xlabel("Time (s)");
ylabel("Amplitude");
disp("Quantization completed.");
EXP-9
clc;
clear;
n = -12:12;
x = 12 - abs(n);
L = 3;
n_down = n(1:L:$);
y = x(1:L:$);
scf(0);
subplot(2,1,1);
plot2d3(n, x);
subplot(2,1,2);
plot2d3(n_down, y);
EXP-10
clc;
clear;
x = [1 2 3 4];
L = 3;
N = length(x);
y = zeros(1, L * N);
for i = 1:N
y(1 + (i - 1) * L) = x(i);
end
scf(0);
subplot(2,1,1);
x_axis = 1:N;
plot2d3(x_axis, x);
title("Original Signal");
subplot(2,1,2);
plot2d3(y_axis, y);
title("Upsampled Signal");
LINEAR CONVOLUTION
clc;
clf;
clear all;
n =convol(x,y);
subplot(2,2,1);
plot2d3(x);
title('first sequence');
xlabel('n−−−−−−>');
ylabel('amp−−−−>');
subplot(2,2,2);
plot2d3(y);
subplot (2,2,3) ;
plot2d3(n);
title ( 'convolved sequence') ;
disp(n);
COSINE
f=0.2;
t=0:0.1:10;
x=cos(2*%pi*t*f);
plot2d3(t,x)
xlabel(' t ');
ylabel(' x ');
SINE
f=0.2;
t=0:0.1:10;
x=sin(2*%pi*t*f);
plot2d3(t,x)
xlabel(' t ');
ylabel(' x ');
UNIT STEP
t=0:4;
y=ones(1,5);
subplot(2,1,1);
plot2d3(t,y);
xlabel('time');
ylabel('amplitude');
t=-10:0.2:10;
x=sinc(t);
plot2d3(t,x)
xlabel(' t ');
ylabel('x ');
RECTANGLE WAVE
clf;
t=linspace(0,10,50);
vm=5*squarewave(t);
plot2d3(t,vm)
EXP WAVE
t=-2:0.1:2;
x=exp(t);
plot2d3(t,x)
xlabel(' t ');
ylabel(' x ');
FREQUENCY ANALYSIS
BasebandFrequency = 10e3;
SamplingFrequency = 1e6;
BufferLength = 200;
n = 0:(BufferLength - 1);
plot(n, BasebandSignal)
BasebandDFT = fft(BasebandSignal);
BasebandDFT_magnitude = abs(BasebandDFT);
plot(BasebandDFT_magnitude)
CIRCULAR CONVOLUTION
clc;
clf;
clear all;
N1 = length(g);
N2 = length(h);
N = max(N1, N2);
N3 = N1 - N2;
else
end
for n = 1:N
y(n) = 0;
for i = 1:N
j = n - i + 1;
if (j <= 0) then
j = N + j;
end
end
end
disp(y);
subplot(3, 1, 1);
plot2d3(g);
title('first input sequence');
subplot(3, 1, 2);
plot2d3(h);
subplot(3, 1, 3);
plot2d3(y);
title('convolved sequence');