ashish dsp
Post on 04-Apr-2018
229 Views
Preview:
TRANSCRIPT
-
7/31/2019 Ashish Dsp
1/14
Program 1-To impliment unit impulse and unit step
function.
(i) Unit impulse
function y = impulse_fn % declerition the function
for i=-10:1:10 % defining the range
if i==0
y=1;
else
y=0;
end
stem(i,y); % displaying th oputput
hold on; % retain current graph in figure.
end
(ii) unit step
function y = unitstep_fn % declerition the function
for i=-10:1:10 % defining the range
if i>=0
y=1;
else
y=0;end
stem(i,y); % displaying th oputput
hold on; % retain current graph in figure.
end
-
7/31/2019 Ashish Dsp
2/14
(i) Output of unit impulse
(ii) Output of unit step fu
function.
nction.
-
7/31/2019 Ashish Dsp
3/14
Program2-program for given function.
% progrm for given function.function y = function2() % decleration of function.
for i=-6:1:6 % range of x axis
if i>=-4 && i
-
7/31/2019 Ashish Dsp
4/14
-
7/31/2019 Ashish Dsp
5/14
Program3-write a program for various defined signal.
%making a impulse function
function y = imp(n,p) %function decleration.
y=[(n-p)==0];
% making a unit step function.
function y = step1(n,p) % function decleration.
y=[(n-p)>=0];
% implementing various defined function.
clear all % clear the command window.
n=-5:5; % defining the length of x axis of signal 1.
a=2*imp(n,-2)-imp(n,4); % a is defined the signal 1 and
calling imp function.
subplot(2,2,1); % making a ploting matrics.
stem(n,a); % stem function is used for ploting sampled signal.
xlabel('n'); % labeling x and y axis.
ylabel('x(n)');
n1=0:20; % defining the length of x axis of signal 2 .
b=n1.*(step1(n1,0)-step1(n1,10))+10*exp(-0.3*(n1-
10)).*(step1(n1,10)-step1(n1,20)); %b is defined the signal 2
and calling step function.subplot(2,2,2);
stem(n1,b);
xlabel('n1');
ylabel('x(n1)');
n2=0:50; % defining the length of x axis of signal 3.
c=cos(0.04*pi*n2)+0.2*rand(size(n2));%b is defined the signal 3.
subplot(2,2,3);
stem(n2,c);
xlabel('n2');
ylabel('x(n2)');
n3=-10:9; % defining the length of x axis of signal 4.d=[5 4 3 2 1]; %b is defined the signal 4.
e=[d d d d];
subplot(2,2,4);
stem(n3,e);
xlabel('n3');
ylabel('x(n3)');
-
7/31/2019 Ashish Dsp
6/14
3.output of various signal.
-
7/31/2019 Ashish Dsp
7/14
Program 4(i)- pro
clear all % cle
% create a dialog bo
prompt = {'Enter seq
sequence B:','Positi
dlg_title = 'Inputs
num_lines = 1;
def = {'1 2 3 4','1'
answer = inputdlg(pr
open input dialog bo
a=str2num(answer{1})
a number, use str2nm
aposition =str2num(a
b=str2num(answer{3})bposition=str2num(an
m=length(a);
n=length(b);
o=m+n-1;
y=zeros(1,o);
for k=1:o
for j=max(1,k+1-
y(k)=y(k)+a(
end
end
y
Input dialog box.
gram for calculating conv
ar the screen.
x.
uence A:','Position of origin:
on of origin:'};
for convolution';
% define no. of line in input
,'1 1 1 1','1'}; % assigni
ompt,dlg_title,num_lines,def);
x.
% To convert a member of the
.
nswer{2})
swer{4})
% length of any array.
n): min(k,m) %find con
j)*b(k-j+1);
lution
','Enter
dialog box.
ng value
% Create and
cell array to
volution
-
7/31/2019 Ashish Dsp
8/14
Output of given convolution.
a =
1 2 3 4
aposition =
1
b =
1 1 1 1
bposition =
1
y =
Columns 1 through 6
1 3 6 10 9 7
Column 7
4
-
7/31/2019 Ashish Dsp
9/14
Program 6-find th%input dialog box
prompt = {'Enter seq
sequence B:','Positi
dlg_title = 'Inputs
num_lines = 1;
of line in input dia
def = {'1 2 3 4','1'
value
answer = inputdlg(pr
open input dialog bo
a=str2num(answer{1})
a member of the cell
aposition =str2num(a
b=str2num(answer{3})bposition=str2num(an
b1=fliplr(b);
about y axis.
m=length(a);
any array.
n=length(b1);
o=m+n-1;
y=zeros(1,o);
for k=1:o
for j=max(1,k+1-
correlationy(k)=y(k)+a(
end
end
y
Input dialog box
e correlation of two sign
uence A:','Position of origin:
on of origin:'};
for convolution';
log box.
,'1 1 1 1','1'};
ompt,dlg_title,num_lines,def);
x.
array to a number, use str2nm
nswer{2})
swer{4})
n): min(k,m)
j)*b1(k-j+1);
l.
','Enter
% define no.
% assigning
% Create and
% To convert
.
% folding
% length of
%find
-
7/31/2019 Ashish Dsp
10/14
Output of correlation of given 2 signal.a =
Columns 1 through 6
2 -1 3 7
1 2
Column 7
-3
aposition = 1
b =
Columns 1 through 6
1 -1 2 -2
4 1
Columns 7 through 8
-2 5
bposition = 4
y =
Columns 1 through 6
10 -9 19 36
-14 33
Columns 7 through 12
0 7 13 -18
16 -7
Columns 13 through 14
5 -3
-
7/31/2019 Ashish Dsp
11/14
Program-8(i)-genralisation of signal with filter.
a=[1/4 1/4 1/4 1/4];
a1=ones(1,8);
x=[zeros(1,20) ones(1,20) zeros(1,10)]; %taking x as input
signal
xa=awgn(x,20); %adding noise in input signal.
f=filter(a,1,xa); %filtering the noise added
signal with order 1 filter.
f1=filter(a1,8,xa); %filtering the noise added
signal with order 8 filter.
subplot(2,2,1)
plot(x)
subplot(2,2,2) %making the plot array.
plot(xa) %plot yhe signal.
subplot(2,2,3)
plot(f)
subplot(2,2,4)
plot(f1)
-
7/31/2019 Ashish Dsp
12/14
Output of filter.
-
7/31/2019 Ashish Dsp
13/14
Program 8(ii)- genralisation of audio signal with
filter.
% Record your voice for 10 seconds.
myVoice = audiorecorder; %making audio recorder object.
disp('Start speaking.')
recordblocking(myVoice, 10);
disp('End of Recording.');
% Play back the recording.
play(myVoice);
% Store data in double-precision array.mydata = getaudiodata(myVoice);
subplot(3,1,1),plot(mydata); % Plot the waveform.
xlabel('t'); % labeling x and y axis.
ylabel('x(t)');
title(audio signal);
mydata1=awgn(mydata,20);
subplot(3,1,2),plot(mydata1);
xlabel('t'); % labeling x and y axis.
ylabel('x(t)');
title(noise added signal);
a=[1/7 1/7 1/7 1/7 1/7 1/7 1/7];
%filtering the noise added signal with order 1 filter.
f=filter(a,1,mydata1);
subplot(3,1,3)
plot(f) %plot yhe signal.
xlabel('t'); % labeling x and y axis.
ylabel('x(t)');
title(filtered signal);
-
7/31/2019 Ashish Dsp
14/14
Output of audio filterd si
nal.
top related