Ashish DSP

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 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 % retain current graph in figure. hold on; 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

(i) Output of unit impulse function.

(ii) Output of unit step function.

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<=4 y=4; else if i==5 y=1; else y=0; end end stem(i,y); % plotting the output % labeling of axis. xlabel('n'); ylabel('x(n)'); title('graph of given function') hold on; % retain current graph in figure end

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 the command window. clear all 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*(n110)).*(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)'); % defining the length of x axis of signal 4. n3=-10:9; 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)');

3.output of various signal. output

Program 4(i)- program for calculating convolution


clear all % clear the screen. % create a dialog box. prompt = {'Enter sequence A:' 'Position of origin:' 'Enter A:','Position origin:','Enter sequence B:','Position of origin:' 'Position origin:'}; dlg_title = 'Inputs for convolution'; convolution' num_lines = 1; % define no. of line in input dialog box. def = {'1 2 3 4','1' '1','1 1 1 1','1'}; % assigning value answer = inputdlg(prompt,dlg_title,num_lines,def); % Create and open input dialog box. a=str2num(answer{1}) % To convert a member of the cell array to }) a number, use str2nm. aposition =str2num(answer{2}) b=str2num(answer{3}) bposition=str2num(answer{4}) m=length(a); % length of any array. n=length(b); o=m+n-1; y=zeros(1,o); for k=1:o for j=max(1,k+1-n): min(k,m) %find convolution y(k)=y(k)+a(j)*b(k-j+1); y(k)=y(k)+a(j)*b(k end end y

Input dialog box.

Output of given convolution.


a= 1 2 3 4

aposition = 1

b= 1 1 1 1

bposition = 1

y= Columns 1 through 6 1 Column 7 4 3 6 10 9 7

Program 6-find the correlation of two signal. find


%input dialog box prompt = {'Enter sequence A:' 'Position of origin:' 'Enter A:','Position origin:','Enter sequence B:','Position of origin:' 'Position origin:'}; dlg_title = 'Inputs for convolution'; convolution' num_lines = 1; % define no. of line in input dialog box. def = {'1 2 3 4','1' '1','1 1 1 1','1'}; }; % assigning value answer = inputdlg(prompt,dlg_title,num_lines,def); % Create and open input dialog box. a=str2num(answer{1}) % To convert a member of the cell array to a number, use str2nm. aposition =str2num(answer{2}) b=str2num(answer{3}) bposition=str2num(answer{4}) b1=fliplr(b); % folding about y axis. m=length(a); a); % length of any array. n=length(b1); o=m+n-1; y=zeros(1,o); for k=1:o for j=max(1,k+1-n): min(k,m) -n): %find correlation y(k)=y(k)+a(j)*b1(k-j+1); y(k)=y(k)+a(j)*b1(k end end y

Input dialog box

Output of correlation of given 2 signal.


a = Columns 1 through 6 2 1 Column 7 -3 2 -1 3 7

aposition = 1

b = Columns 1 through 6 1 4 1 Columns 7 through 8 -2 5 -1 2 -2

bposition = 4

y = Columns 1 through 6 10 -14 33 -9 19 36

Columns 7 through 12 0 16 -7 Columns 13 through 14 5 -3 7 13 -18

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 %adding noise in input signal. xa=awgn(x,20); 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)

Output of filter.

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); % labeling x and y axis. xlabel('t'); 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);

Output of audio filterd signal.

You might also like