DSP 7

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

exp 7

Status Done

Course 📸 DSP
Priority LOW

function beq=a2dR(d,n)
%BEQ =A2DR(D,N) generates the decimal equivalent of beq binary
%representation
%magnitude part obtained by rounding
m=1;
d1=abs(d);
while fix(d1) >0
d1=abs(d)/(10^m);
m=m+1;
end
beq=0;d1 =d1+2^(-n-1);
for k = 1:n
beq =fix(d1*2)/(2^k )+beq;
d1 = (d1*2)-fix(d1*2);
end
beq = sign(d ).*beq.*10^(m-1);

clc;
clear all;
close all;
%PART A
%to design low pass filter
b=fir1(50,0.65,'low');
display(b);
%to generate pole zero diagram fir - only zeroes, no poles
figure(1);
zplane(b,1);
figure(2);
freqz(b,1,512);
% to truncation : 4=4 bits , we can change, take less than 16
bq =a2dR(b,4);
display(bq);
%generate pole zero diagram for bq
figure(3);
zplane(bq,1);
figure(4);
freqz(bq,1,512);

exp 7 1
1. A2DR Function
The following function is used to convert analog signals to digital.

The function takes two inputs: 1. d= input, 2. n= number of bits.

beq= used for generating decimal equivalent of beq binary response. (for each bit
this function goes on).

1. d1 * 2 : Multiplies the current value of d1 by 2. This operation effectively shifts the


decimal point of the number one position to the left, as in binary representation,
multiplying by 2 is equivalent to shifting one position to the left.

2. fix(d1 * 2) : Rounds down the result of d1 * 2 to the nearest integer toward


negative infinity. This operation effectively extracts the integer part of the result after
multiplying d1 by 2.

3. (d1 * 2) - fix(d1 * 2) : Calculates the fractional part of the number. By subtracting


the integer part from the multiplied value, you are left with the fractional part of the
original number after shifting the decimal point.

4. sign(d) : This function returns the sign of d . It returns 1 if d is positive, 0 if d is


zero, and -1 if d is negative. This part of the expression ensures that the sign of the
original number is preserved.

5. beq .* 10^(m - 1) : The binary representation beq is multiplied by 10 raised to the


power of m - 1 . Here, m represents the number of digits in the integer part of the
original number. Multiplying by 10^(m - 1) shifts the decimal point back to its original
position after the binary representation has been obtained. For example, if m is 3,
the binary representation is multiplied by 1000 to shift the decimal point three
positions to the right.

6. sign(d) .* beq .* 10^(m - 1) : This expression combines the sign of the original
number, the binary representation, and the scaling factor. It ensures that the binary
representation is correctly scaled and retains the sign of the original number.

Low pass filtering


Does attenuetion.

exp 7 2
51 coefficents (0:50), freq= 0.65, low pass

Pole zero:
Plotting the given signal in poles and zeros.

exp 7 3

You might also like