0% found this document useful (0 votes)
2 views

DSP-CLP-01

it's my dsp course lab clp

Uploaded by

akashbani86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

DSP-CLP-01

it's my dsp course lab clp

Uploaded by

akashbani86
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

 Lab report 01

i) General MATLAB Commands:


a. MATLAB Command: X=[1:15]
Output:

Details: Simple matrix generation


Ans: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

b. MATLAB Command: X=[1:2:18]


Output:

Details: single row matrix generation. [start: step: End]


Ans: 1 3 5 7 9 11 13 15 17

c. MATLAB Command: Y=linspace(2,16,5)


Output:
Details: Single row matrix generation. Formation by [start, end, no of data]

d. MATLAB Command: T=2*pi*100

Output:

Details: for MATLAB, π = pi, T=2 πf

e. MATLAB Command: sin(60*pi/180)

Output:

Details: MATLAB angle values are in Radians. Radians to Degree conversion-


180
Degree = * Radian
π

f. MATLAB Command: 100*exp(-6)


Output:

Details: ‘exp’ means exponential; 100e-6

g. MATLAB Command: 20e-10

Output:

Details: ‘e’ denoted power of 10; 20 ∗ 10-10

h. MATLAB Command: (log10(100))^10

Output:

Details: Logarithm Command on MATLAB- logBasePower; Example: log 1010;


log10 means= loge10 (default)

i. MATLAB Command: (log2(10))^5


Output:

Details: 2 Base Logarithm

j. MATLAB Command: (log(100))^10

Output:

Details: e Base Logarithm

k. MATLAB Command:
X= 0:2:16; Y=2*X;
T=linspace(0,2*pi*100);
X=sin(T); Y=cos(T);
plot(X)
plot(Y)
subplot(3,1,1)
plot(X)
subplot(3,1,2)
plot(Y)
subplot(3,1,3)
plot(X,Y)
Output:

Details: plotting X and Y respect to T. Formation of subplot (Row, column,


position). Subplot:

1,1 1,2 1,3


2,1 2,2 2,3
3,1 3,2 3,3

i) Matlab Commands for Matrix:


a. Simple Matrix: a=[1,2,3;10,12,14;-7,-8,-9]
Output:

b. Matrix Operation:
A=[1 10 30 ; -50 -40 -60 ; 90 70 80 ];
B=[15 18 21 ; -12 20 24 ; 2 4 6];
C=[3 4 5 ; 25 -30 18; 14 27 39];
i) A+B+C
ii) A+B-C
iii) A+B-C-10
iv) A/C
v) A*B*C
vi) 2*A
vii) A^2
vii) A.^2
Output:

c. Matrix Generation:
Matrix Operation: zeros(2,2); ones(3,3); rand(2,3)
Output:

d. Transpose, Determinant and Inverse Matrix:


Matrix Operation: S=[10 9 8; 6 -6 -5; 4 3 2]
i) S'
ii) det(S)
iii) inv(S)
Output:

Details: Here,
W’=Transpose Matrix
det(W)=Determinant of W
inv(W)= inverse matrix of W

e. For Loop:
Matrix Operation:
for i = 1:4:20
x = i^4
end

Output:

Details: For index = expression Statement group x


End
The output of this code: x = 1,25,81,169,289

f. Nested For Loop:


Matrix Operation:
m=3;
n=5;
for i=1:m
for j=1:n
f(i,j)=i;
end
end
f
Output:

g. Logical Operator:
Matrix Operation:
x=4; y=6;
if x<1 & y<1
z=0
elseif x>1 & y<1
z=1
elseif x>1 | y<1
z=2
end

Output:

Details: Logical Operators with IF Else Statement:


Symbol Meaning & AND, | OR, ~ NOT
The output of this code: z = 2
h. Solving Linear Equation:
Matrix Operation: 12x + 20y − 18z = 0
−2x + 4y − 15z = 9
3x - 3y − 3z = -6
 Method 1:
A=[12 20 -1;-2 1 -15; 1 1 -1];
b=[0;-9;-6];
x=inv(A)*b
x=A\b
Output:

 Method 2
syms x y z
[x,y,z]=solve([12*x+20*y-z==0,-2*x+y-15*z==-9,x+y-z==-6],[x,y,z])
Output:
Student Works:
1. Think about A and B are the last two digits of your ID-

B
a. sin(AB°) + cot(BA°) + tan-1 + Be-BA + A*10-A + (log10B)AB + (logeBA)A
A

Solution: As my ID is 222901002. Here, A=0 & B=2

Output:

2. Solve the following equation-

a. 17x1+2x2+1x3+5x4=4

5x1+6x2+7x3+1x4=-1

9x1-10x2+11x3+12x4=10

13x1+14x2+15x3-9x4= 6
Output:

Report Questions:
1
1. sin(225°) + cot(30°) + tan-1( ) + 10e-10 + 9*10-2 + (log1010)3 + (loge10)5
2

Output:

2. Try the following commands for the matrix W

10 −12 30
W = 55 95 200
−70 5 2

A=W(3,2)
B=W(1,1)

C=W(3,3)

D=W(2,2)

E=A+B

F = √ ln ⁡∨C−D∨¿ ¿ + sin (B)

Output:

 Lab report 02
clc;
clear all;
close all;
% Continuous-Time Step Signal
t = -5:0.01:5; % Time vector (continuous domain)
u_t = t >= 0; % Unit step function
subplot(3,1,1);
plot(t, u_t, 'b', 'LineWidth', 2);
xlabel('Time (t)');
ylabel('Amplitude');
title('Continuous-Time Unit Step Signal');
grid on;
axis([-5 5 -0.2 1 2]);

% Discrete-Time Step Signal


n = -5:5; % Discrete time vector (integer values)
u_n = n >= 0; % Unit step function (discrete)
subplot(3,1,1);
stem(n, u_n, 'b', 'LineWidth', 2);
xlabel('n (Discrete Time)');
ylabel('Amplitude');
title('Discrete-Time Unit Step Signal');
grid on;
axis([-5 5 -0.2 1 2]);

% Continuous-Time Ramp Signal


t = -0.3:0.1:0.3; % Time vector (continuous domain)
r_t = t .* (t >= 0); % Ramp function: r(t) = t for t >= 0, 0 for t < 0
subplot(3,1,1);
plot(t, r_t, 'b', 'LineWidth', 2); % Blue line with width 2
xlabel('Time (t)');
ylabel('Amplitude');
title('Continuous-Time Ramp Signal');
grid on;
axis([-5 5 -0.2 1 2]);

% Discrete-Time Ramp Signal


t = -5:10; % Time vector (discrete domain)
r_t = t .* (t >= 0); % Ramp function: r(t) = t for t >= 0, 0 for t < 0
subplot(3,1,1);
stem(t, r_t, 'b', 'LineWidth', 2); % Blue line with width 2
xlabel('Time (t)');
ylabel('Amplitude');
title('Discrete-Time Ramp Signal');
grid on;
axis([-5 5 -0.2 1 2]);

% Continuous-Time Impulse Signal


t = -5:0.01:5; % Time vector (continuous domain)
i_t = (t == 0); % Impulse at t = 0, approximated as 1 at t=0 and 0
elsewhere
subplot(3,1,2);
plot(t, i_t, 'r', 'LineWidth', 2); % Red line with width 2
xlabel('Time (t)');
ylabel('Amplitude');
title('Continuous-Time Impulse Signal');
grid on;
axis([-5 5 -0.2 1 2]);

% Discrete Pulse Signal


t = -0.5:0.1:0.5; % Time vector (discrete domain)
i_t = (t == 0); % Impulse at t = 0, approximated as 1 at t=0 and 0
elsewhere
subplot(3,1,2);
stem(t, i_t, 'r', 'LineWidth', 2); % Red line with width 2
xlabel('Time (t)');
ylabel('Amplitude');
title('Discrete-Time Impulse Signal');
grid on;
axis([-5 5 -0.2 1 2]);

 Lab report 03
%signal addition

n = 0:5;
x1 = [1 2 3 4 5 6];
x2 = [6 5 4 3 2 1];
y = x1 + x2;
stem(n, y);

%multiplication of two discrete signal

n = 0:5;
x1 = [1 2 3 4 5 6];
x2 = [6 5 4 3 2 1];
y = x1 ./ x2;
stem(n, y);

%multiplication by scalar value discrete signal

n = 0:5;
x1 = [1 2 3 4 5 6];
dsp = 2;
y = dsp * x1;
stem(n, y);

%time shifting

n = 0:5;
x1 = [1 2 3 4 5 6];
shift = 2;
n_shifted = n + shift;
stem(n_shifted, x1);

%folding

n = 0:5;
x1 = [1 2 3 4 5 6];
n_folding = -n;
stem(n_folding, x1);
xlabel('n'); ylabel('Amplitude'); title('Folding of sequence');
grid on;

%Sample Summation

x = [1 2 3 4 5 6];
sum_x = sum(x);
disp(['Summation of samples: ', num2str(sum_x)]);

%Sample Multiplication

x = [1 2 3 4 5 6];
prod_x = prod(x);
disp(['Multiplication of samples: ', num2str(prod_x)]);

 Lab report 04
Converting a Continuous Time Signal into a Discrete Time Signal:

Input Code:

clc;
clear all;

fm = 10;%Signal Frequency(Hz)
fs_good = 40;%Proper Sampling(fs>2*fm)
fs_bad = 15;%Undwesampling(fs<2*fm)
t = 0:0.001:0.5;%Continuous time
x = cos(2*pi*fm*t);%Original signal

%Sampling at Nyquist Rate


n1 = 0:1/fs_good:0.5;
x1 = cos(2*pi*fm*n1);

%Undersampling(Aliasing)
n2 = 0:1/fs_bad:0.5;
x2 = cos(2*pi*fm*n2);
%Plot Results
figure;
subplot(3,1,1);
plot(t, x, 'b'); title('Original Continuous-Time Signal'); xlabel('Time'); ylabel('Amplitude'); grid
on;
subplot(3,1,2);
stem(n1, x1, 'r', 'filled'); title('Proper Sampling(fs>2fm)'); xlabel('Time'); ylabel('Amplitude');
grid on;
subplot(3,1,3);
stem(n2, x2, 'g','filled'); title('Alising(fs<2fm)'); xlabel('Time'); ylabel('Amplitude'); grid on;

Output:

Converting that Discrete Time Signal to Continuous Time Signal:

Input Code:

clc;
clear all;

fm = 10;%Original Signal Frequency(Hz)


fs = 40;%Sampling frequency(fs>2*fm to satisfy Nyquist theorem)
t = 0:0.001:0.5;%Continuous time
x = cos(2*pi*fm*t);%Original continuous time signal

%Sampling
n = 0:1/fs:1;%Sampled points
x_sampled=cos(2*pi*fm*n);%sampled signal

%Reconstruction using Sinc Interpolation


t_interp = linspace(0,1,1000);%High-resolution time vector
x_recon = sinc_interpolation(n, x_sampled, t_interp, fs);%Reconstructed signal

%Plot Results
figure;
subplot(3,1,1);
plot(t, x, 'b'); title('Original Continuous-Time Signal'); xlabel('Time'); ylabel('Amplitude'); grid
on;
subplot(3,1,2);
stem(n, x_sampled, 'r', 'filled'); title('Sampled Signal(Discrete Time)'); xlabel('Time');
ylabel('Amplitude'); grid on;
subplot(3,1,3);
plot(t_interp, x_recon, 'g'); title('Reconstructed Signal using Sins Interpolation'); xlabel('Time');
ylabel('Amplitude'); grid on;

%Function for Sinc Interpolation


function y = sinc_interpolation(n, x, t, fs)
y = zeros(size(t)); %Initialize output signal
for i = 1:length(n)
y = y + x(i) * sinc((t - n(i))*fs); %Apply sinc function
end
end

Output:
Student Works:

Consider an analog signal xa(t) = sin(20πt), 0 ≤ t ≤ 1. It is sampled at Ts = 0.01, 0.03, 0.05


and 0.1 sec intervals to obtain x(n). For each Ts plot x(n). Reconstruct the analog signal
ya(t) from the samples x(n) using the sinc interpolation (use ∆t = 0.001) and determine the
frequency in ya(t) from your plot. Comment on your results.

Input code:

clc;
clear all;

fm = 10; % Original Signal Frequency


fs = 40; % Sampling frequency (fs > 2*fm)
t = 0:0.001:1;
x = sin(2*pi*fm*t); % Original continuous-time signal

% Sampling
n = 0:1/fs:1;
x_sampled = sin(2*pi*fm*n); % Sampled signal (discrete-time)

% Reconstruction using Sinc Interpolation


t_interp = linspace(0, 1, 1000);
x_recon = sinc_interpolation(n, x_sampled, t_interp, fs);
% Plot Results
figure;

subplot(3,1,1);
plot(t, x, 'b');
title('Original Continuous-Time Signal');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(3,1,2);
stem(n, x_sampled, 'r', 'filled');
title('Sampled Signal (Discrete Time)');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

subplot(3,1,3);
plot(t_interp, x_recon, 'g');
title('Reconstructed Signal using Sinc Interpolation');
xlabel('Time (s)');
ylabel('Amplitude');
grid on;

% Function for Sinc Interpolation


function y = sinc_interpolation(n, x, t, fs)
y = zeros(size(t));
for i = 1:length(n)
y = y + x(i) * sinc((t - n(i)) * fs);
end
end

Output:

You might also like