Breaking

Be Strong Let's Try!

Friday, 30 July 2021

Basics of Digital Signal Processing (Impulse,Unit Step,Exponential Function and Perform operations)

 We will learn about these things their generating and operating basic sequences.

 • Generate Delta (Impulse) Function.
 • Generate Unit Step Function
. • Generate Exponential Function.
 • Generate sinusoidal function.
 • Perform operations (scaling, shifting) on above functions.

The Unit Delta (Impulse) function: often called the discrete time impulse or the unit impulse. It is denoted by δ[n].
Creation of Unit Impulse and Unit Step sequences: A unit impulse sequence I[n] of length N can be generated using the MATLAB command I= [1 zeros (1, N-1)]; Similarly, a unit step sequence S[n] of length N can be generated using the MATLAB command S= [ones (1, N)] The Exponential Function: Finally, an exponential sequence is defined by Exponential signal = A𝛼 

We will perforn the following task for practice:

Task 1:
a) Write a generic Matlab code to generate a unit impulse and unit step
b) Plot the signal by taking the value of A=2 and taking the value of “𝛼” equal to -4, -0.5, 0.5, 4. Plot all the sequences in a single figure using “subplot” command. Give your interpretation about the sequences. 
c) Write a generic Matlab code to generate a sinusoidal length 50, frequency 0.08, amplitude 2.5 and phase shift 90 degrees and display it. 
We will also perform FOLDING OF SIGNAL,ADDITION,SHIFTING AND MULTIPLICATION lets start.

CODE:

n = -10:10 ;

Unit_Impulse = n==0;

Unit_Step = n>=0;

subplot(2,1,1)

stem(n,Unit_Impulse)

title('Unit Impulse')

subplot(2,1,2)

stem(n,Unit_Step)

title('Unit Step')

OUTPUT:




PART (B):

CODE:

n=-10:0.1:10;

A=2;

N1 = A ((-4).^n);

subplot(2,2,1)

plot(n,N1)

title(' ALPHA : - 4 ')

N2 = A ((-0.5).^n);

 subplot(2,2,2)

plot(n,N2)

title(' ALPHA : - 0.5 ')

N3=A ((0.5).^n);

subplot(2,2,3)

plot(n,N3)

title(' ALPHA : 0.5 ')

N4=A ((4).^n);

subplot(2,2,4)

plot(n,N4)

title(' ALPHA : 4 ')

 

 

 

 

 OUTPUT:







PART (C):

CODE:
N=0:50;     %THIS IS THE LENGTH

F=0.08;     %THIS IS THE FREQUENCY

A=2.5;      %THIS IS THE AMPLITUDE

Angle = 90;

X = A sin(((2 pi F) N) + Angle);

plot(X)

title('SINUSODAL SIGNAL')

 

OUTPUT:






 TASK 2:
if  x1(𝒏) = [𝟏𝟏 −𝟏𝟑 𝟏𝟓 𝟕 −𝟗] 
-2 ≤ n ≤ 2
 x2(𝒏) = [−𝟏𝟐 𝟏𝟒 𝟔 –𝟖 5]
 0 ≤ n ≤ 4 
a) Write a MATLAB function for signal shifting, and shift given signals by 5 and -6 respectively.
b) Write a MATLAB function for signal flipping and flip above signals. 
c)Generate and plot the following sequences: 
x[n] = 3 ∗ 𝛿[𝑛 − 10] + 15 ∗ 𝛿[𝑛 + 7] -15 ≤ n ≤ 15 x[n] = n * u[n] + u[n-10] + u[n-20] + 10𝛼 −0.8[𝑛−5] [u[n-20]-u[n-30]] -30 ≤ n ≤ 30 Where a=2.



PART (A)

CODE:

Function
:

function [shifted] = shifting(n,x)

shifted = n + x;

Script :
n1 = -2:2;

n2 = 0:4;

x1 = [11 -13 15 7 -9];

x2 = [-12 14 6 -8 5];

s_x1 = shifting(n1,5);

s_x2 = shifting(n2,-6);

subplot(2,2,1)

stem(n1,x1)

title('Original x1')

subplot(2,2,2)

stem(s_x1,x1)

title('x1 shifted by 5')

subplot(2,2,3)

stem(n2,x2)

title('Original x2')

subplot(2,2,4)

stem(s_x2,x2)

title('x2 shifted by -6')

OUTPUT:



PART (B):

CODE:

Function
:

function [flipped] = flipping(n)

flipped = -n;

Script :
n1 = -2:2;

n2 = 0:4;

x1 = [11 -13 15 7 -9];

x2 = [-12 14 6 -8 5];

f_x1 = flipping(n1);

f_x2 = flipping(n2);

subplot(2,2,1)

stem(n1,x1)

title('Original x1')

subplot(2,2,2)

stem(f_x1,x1)

title('Flipped x1')

subplot(2,2,3)

stem(n2,x2)

title('Original x2')

subplot(2,2,4)

stem(f_x2,x2)

title('Flipped x2')

 

OUTPUT:


PART (C):

CODE:

%Generating x1

n1 = -15:15;

I1 = (n1-10)==0;

I2 = (n1+7)==0;

x1 = 3 I1 + 15 I2;

%Generating x2

n2 = -30:30;

U1 = n2>=0;

U2 = (n2-10)>=0;

U3 = (n2-20)>=0;

U4 = (n2-30)>=0;

Angle = 2;

D = (Angle).^(-0.8. (n2-5));

x2 = n2. U1 + U2 + U3 + (10. D. (U3-U4));

%Plotting

subplot(2,1,1)

stem(n1,x1)

title('x1')

subplot(2,1,2)

stem(n2,x2)

title('x2')

 

OUTPUT:


Task 3:(How to Design An Equilizer)
Use any audio for equilizer and record that aduio and use Matlab Coding for generation of signal. a) You have to design the GUI in Matlab to control the gain of each band of frequencies as shown in the figure.

CODE:

function slider1_Callback(hObject, eventdata, handles)

global f

f(1) = get(handles.slider1,'Value');

set(handles.edit1,'String',f(1));

 

function slider2_Callback(hObject, eventdata, handles)

global f

f(2) = get(handles.slider1,'Value');

set(handles.edit2,'String',f(2));

 

function slider3_Callback(hObject, eventdata, handles)

global f

f(3) = get(handles.slider1,'Value');

set(handles.edit3,'String',f(3));

 

function  slider4_Callback(hObject, eventdata, handles)

global f

f(4) = get(handles.slider1,'Value');

set(handles.edit4,'String',f(4));

 

function slider5_Callback(hObject, eventdata, handles)

global f

f(5) = get(handles.slider1,'Value');

set(handles.edit4,'String',f(5));

 

function pushbutton1_Callback(hObject, eventdata, handles)

global x Fs;

[x, Fs]= audioread('C:\Users\MyAudio.wav');

function pushbutton2_Callback(hObject, eventdata, handles)

graph();

function graph()

global C x;

global Fs;

Fs=8800;

[a,b]=Filters();

y=0;

for i=1:5

    y=y+filter(10^(C(i)/20) b{i},a{i},x);

end

plot(y)

xlabel('Frequency [kHz]');

ylabel('Magnitude [Db]');

title('Caracteristica egalizorului audio')

grid on;

function [a,b]=Filters()

%Filtrul 1

global Fs;

Rp1=0.5;

Rs1=30;

Fp1=4.1e3/(Fs/2);                    

Fs1=4.5e3/(Fs/2);                    

n1=cheb1ord(Fp1,Fs1,Rp1,Rs1);

[b1,a1]=cheby1(n1,Rp1,Fp1,'low');

 

 

 

 

%Filtrul 2

Rp2=0.5;

Rs2=30;

Fp2=1e3 [4.25,8.75]/(Fs/2);                  

Fs2=1e3 [3.9,9.35]/(Fs/2);

n2=cheb1ord(Fp2,Fs2,Rp2,Rs2);

[b2,a2]=cheby1(n2,Rp2,Fp2);

%Filtrul 3

Rp3=0.5;

Rs3=30;

Fp3=1e3 [8.95,13.25]/(Fs/2);                  

Fs3=1e3 [8.35,13.65]/(Fs/2);

n3=cheb1ord(Fp3,Fs3,Rp3,Rs3);

[b3,a3]=cheby1(n3,Rp3,Fp3);

%Filtrul 4

Rp4=0.5;

Rs4=30;

Fp4=1e3 [13.4,16.8]/(Fs/2);

Fs4=1e3 [13,17.5]/(Fs/2);

n4=cheb1ord(Fp4,Fs4,Rp4,Rs4);

[b4,a4]=cheby1(n4,Rp4,Fp4);

%Filtrul 5

Rp5=0.5;

Rs5=30;

Fp5=1e3 17/(Fs/2);                 

Fs5=1e3 17.4/(Fs/2);

n5=cheb1ord(Fp4,Fs4,Rp4,Rs4);

[b5,a5]=cheby1(n5,Rp5,Fp5,'high');

a={a1,a2,a3,a4,a5};

b={b1,b2,b3,b4,b5};

 

%Executes on button press in pushbutton3.

function pushbutton3_Callback(hObject, eventdata, handles)

set(handles.edit1,'String',0);

set(handles.edit2,'String',0);

set(handles.edit3,'String',0);

set(handles.edit4,'String',0);

set(handles.edit4,'String',0);

set(handles.slider1,'Value',0);

set(handles.slider2,'Value',0);

set(handles.slider3,'Value',0);

set(handles.slider2,'Value',0);

set(handles.slider5,'Value',0);

cla;

function pushbutton4_Callback(hObject, eventdata, handles)

global C;

[a,b]=Filters();

y=0;

global x;

for k=1:5

    y=y+filter(10^(C(k)/20) b{k},a{k},x);

end

sound(y);

function pushbutton5_Callback(hObject, eventdata, handles)

clear sound;

 

 

 

OUTPUT:

GUI:




After Running The Code and Recording the voice:













No comments:

Post a Comment

Pages