Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc
- clear all
- % n= (-10:10);%generating independent variables
- x = input('input the first sequence: ')
- h = input('input the second sequence:')
- subplot(3,1,1);
- stem(x);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('x');
- title('x(n)-1019151220');
- subplot(3,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h');
- title('h(n)-101915122');
- %for linear convuution length
- N1=length(x);
- N2=length(h);
- N=N1+N2-1;
- xn=[x,zeros(1,N-N1)];
- hn=[h,zeros(1,N-N2)];
- y=zeros(1,N);
- %circular convulution length
- for i=0:N-1
- for j=0:N-1
- z=mod(i-j,N);
- y(i+1) = y(i+1) + xn(j+1).*hn(z+1);
- end
- z;
- end
- disp('Linear convulution using circular covulution sequence is given as (101915122): ');y
- subplot(3,1,3);
- stem(y);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Linear convulution using circutlar convulution-101915122');
- _______________________________________________________________
- 4b
- clc
- clear all
- % n= (-10:10);%generating independent variables
- x = input('input the first sequence: ')
- h = input('input the second sequence:')
- subplot(3,1,1);
- stem(x);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('x');
- title('x(n)-1019151220');
- subplot(3,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h');
- title('h(n)-101915122');
- %for linear convuution length
- N1=length(x);
- N2=length(h);
- N=N1+N2-1;
- xn=[x,zeros(1,N-N1)];
- hn=[h,zeros(1,N-N2)];
- y=zeros(1,N);
- %circular convulution length
- for i=0:N-1
- for j=0:N-1
- z=mod(i-j,N);
- y(i+1) = y(i+1) + xn(j+1).*hn(z+1);
- end
- z;
- end
- disp('Linear convulution using circular covulution sequence is given as (101915122): ');
- y
- subplot(3,1,3);
- stem(y);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Linear convulution using circutlar convulution-101915122');
- ______________________________________________________________
- % 4c
- clc;
- clear all;
- % n= (-10:10);%generating independent variables
- %humesha start from 1:n array me store krane k liye
- x = input('input the first sequence: ')
- h = input('input the second sequence:')
- subplot(4,1,1);
- stem(x);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('x');
- title('x(n)-101915122');
- subplot(4,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h');
- title('h(n)-101915122');
- m=length(x);
- n=length(h);
- hn=[h,zeros(1,m-1)];
- xn=[x,zeros(1,n-1)];
- y=zeros(1,m+n-1);
- for i=1:m+n-1
- sum=0;
- for j=1:i
- sum=sum+(xn(j)*hn(i-j+1));
- end
- y(i)=sum;
- end
- % disp('Linear convolution is given as (101915122): ');
- y;
- subplot(4,1,3);
- stem(y);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Linear convulution-101915122');
- %code or circular ---->
- %find the linear convulution ----> jitna extra aa rha uuse add krr do pehle dosre (see graph nb) ---->
- %length of linear convulution peeche se iteration start krrna
- N=max(n,m); %defines the output buffer
- p=zeros(1,N);
- q=zeros(1,N);
- z=zeros(1,N);
- for i=1:N
- %z(i) me store krana
- p(i)=y(i);
- end
- p;
- for i=1:m+n-1-N
- q(i)=y(N+i);
- %add last wala to first circularly
- end
- q;
- for i=1:N
- z(i)=p(i)+q(i);
- %add last wala to first circularly
- end
- disp('Circular convolution using linear convolution is given as (101915122): ')
- z
- subplot(4,1,4);
- stem(z);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('z(n)');
- title('Circular convulution using Linear convulution-101915122');
- % 4d
- clc;
- clear all;
- n= (-10:10);%generating independent variables
- x = input('input the first sequence: ')
- h = input('input the second sequence:')
- N1=length(x);
- N2=length(h);
- N=max(N1,N2);
- disp('dft of x(n)= X(k)')
- xf=fft(x,N)
- disp('dft of h(n)= H(k)')
- hf=fft(h,N)
- disp('multiplication of X(k) and H(k)= Y(k)')
- yk=xf.*hf
- disp('idft of Y(k) = y(n)')
- yn=ifft(yk)
- disp('circular convulution of x(n) and h(n) (101915122)')
- y=cconv(x,h,N)
- subplot(4,1,1);
- stem(x);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('x(n)');
- title('x(n) - 101915122');
- subplot(4,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h(n)');
- title('h(n) - 101915122');
- subplot(4,1,3);
- stem(yn);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Circular convultion by IDFT-101915122');
- subplot(4,1,4);
- stem(y);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Circular convultion by inbuit function-101915122');
Advertisement
Add Comment
Please, Sign In to add comment