0% found this document useful (0 votes)
9 views8 pages

DSP Experiments

The document contains MATLAB code for various signal processing experiments, including autocorrelation, cross-correlation, quantization, decimation, upsampling, linear and circular convolution, and frequency analysis. Each experiment is designed to demonstrate specific signal processing techniques and includes plotting of original and processed signals. The code snippets are structured to facilitate understanding of the underlying concepts in signal processing.

Uploaded by

hema22050.ec
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)
9 views8 pages

DSP Experiments

The document contains MATLAB code for various signal processing experiments, including autocorrelation, cross-correlation, quantization, decimation, upsampling, linear and circular convolution, and frequency analysis. Each experiment is designed to demonstrate specific signal processing techniques and includes plotting of original and processed signals. The code snippets are structured to facilitate understanding of the underlying concepts in signal processing.

Uploaded by

hema22050.ec
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
You are on page 1/ 8

EXP-3

AUTOCORRELATION CODE:

t = linspace(0, 100, 2000);

y = 0.8 * sin(t) + 0.8 * sin(2 * t);

[c, ind] = xcorr(y, "biased");

plot(ind, c)

CROSS CORRELATION CODE:

t = linspace(0, 100, 2000);

x = 0.5 * cos(t) + 0.9 * tan(2 * t);

y = 0.8 * sin(t) + 0.8 * sin(2 * t);

[c, ind] = xcorr(x,y, "biased");

plot(ind, c)

EXP-7

clc;

clear;

close;

fs = 1000;

t = 0:1/fs:1;

x = sin(2 * %pi * 10 * t);

num_bits = 3;

L = 2^num_bits;

xmin = min(x);

xmax = max(x);

q_step = (xmax - xmin) / (L - 1);

x_quantized_index = floor((x - xmin) / q_step);

x_quantized = x_quantized_index * q_step + xmin;

subplot(2,1,1);

plot2d(t, x, style=1);

title("Original Signal");
subplot(2,1,2);

plot2d(t, x_quantized, style=[2, -1]);

title("Truncated Quantized Signal");

disp("Quantization completed.");

EXP-8

clc;

clear;

close;

fs = 1000;

t = 0:1/fs:1;

f = 10;

x = sin(2 * %pi * f * t);

num_bits = 3;

L = 2^num_bits;

q_step = (max(x) - min(x)) / (L - 1);

x_quantized = round(x / q_step) * q_step;

subplot(2,1,1);

plot2d(t, x, style=1);

title("Original Signal");

xlabel("Time (s)");

ylabel("Amplitude");

subplot(2,1,2);

plot2d(t, x_quantized, style=2);

title("Quantized Signal (Rounding)");

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);

title("Original Discrete Signal");

xtitle("Original Discrete Signal", "n", "x[n]");

subplot(2,1,2);

plot2d3(n_down, y);

title("Decimation of a discrete-time signal by a factor of 3.");

xtitle("Downsampled Signal", "n", "y[n]");

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");

xtitle("Original Signal", "n", "Amplitude");

subplot(2,1,2);

y_axis = 1:(L * N);

plot2d3(y_axis, y);

title("Upsampled Signal");

xtitle("Upsampled Signal", "n", "Amplitude");

LINEAR CONVOLUTION

clc;

clf;

clear all;

x =input('enter the first sequence:');

y =input('enter the second sequence:');

n =convol(x,y);

subplot(2,2,1);

plot2d3(x);

title('first sequence');

xlabel('n−−−−−−>');

ylabel('amp−−−−>');

subplot(2,2,2);

plot2d3(y);

title ('second sequence') ;

xlabel ( ' n−−−−−−> ' ) ;

ylabel ( 'amp−−−−> ' ) ;

subplot (2,2,3) ;

plot2d3(n);
title ( 'convolved sequence') ;

xlabel( ' n−−−−−−> ' ) ;

ylabel ( 'amp−−−−> ' ) ;

disp( 'The Convolved Sequences' ) ;

disp(n);

COSINE

f=0.2;

t=0:0.1:10;

x=cos(2*%pi*t*f);

plot2d3(t,x)

title(' cosine wave ');

xlabel(' t ');

ylabel(' x ');

SINE

f=0.2;

t=0:0.1:10;

x=sin(2*%pi*t*f);

plot2d3(t,x)

title(' sine wave ');

xlabel(' t ');

ylabel(' x ');

UNIT STEP

t=0:4;

y=ones(1,5);

subplot(2,1,1);

plot2d3(t,y);

xlabel('time');

ylabel('amplitude');

title('Unit Step Discrete Signal');


SINC SIGNAL

t=-10:0.2:10;

x=sinc(t);

plot2d3(t,x)

title(' sinc wave ');

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)

title(' exponential wave ');

xlabel(' t ');

ylabel(' x ');

FREQUENCY ANALYSIS

BasebandFrequency = 10e3;

SamplingFrequency = 1e6;

BufferLength = 200;

n = 0:(BufferLength - 1);

BasebandSignal = sin(2*%pi*n / (SamplingFrequency/BasebandFrequency));

plot(n, BasebandSignal)

BasebandDFT = fft(BasebandSignal);

BasebandDFT_magnitude = abs(BasebandDFT);

plot(BasebandDFT_magnitude)
CIRCULAR CONVOLUTION

clc;

clf;

clear all;

g = input('Enter the first sequence : ');

h = input('Enter the second sequence : ');

N1 = length(g);

N2 = length(h);

N = max(N1, N2);

N3 = N1 - N2;

if (N3 >= 0) then

h = [h, zeros(1, N3)];

else

g = [g, zeros(1, -N3)];

end

for n = 1:N

y(n) = 0;

for i = 1:N

j = n - i + 1;

if (j <= 0) then

j = N + j;

end

y(n) = y(n) + g(i) * h(j);

end

end

disp('The resultant signal is : ');

disp(y);

subplot(3, 1, 1);

plot2d3(g);
title('first input sequence');

subplot(3, 1, 2);

plot2d3(h);

title('second input sequence');

subplot(3, 1, 3);

plot2d3(y);

title('convolved sequence');

You might also like