Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1a
- % %PLOT UNIT STEP FUNCTION
- % t=[-10:1:10];
- % us=(t>=0);
- % subplot(2,2,1);
- % plot(t,us);
- % % plot(t,us);
- % xlabel('Values of t'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(t)');
- % title('UNIT STEP FUNCTION(CONT.)-102095004');
- %
- % %PLOT UNIT IMPULSE FUNCTION
- % t=[-10:1:10];
- % usi=(t==0);
- % subplot(2,2,3);
- % plot(t,usi);
- % xlabel('Values of t'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(t)');
- % title('UNIT IMPULSE FUNCTION(CONT.)-102095004');
- %
- % %PLOT UNIT STEP FUNCTION
- % t=[-10:1:10];
- % us=(t>=0); %BY DEFAULT VALUE IS 1
- % subplot(2,2,2);
- % stem(t,us);
- % stem(t,us);
- % xlabel('Values of n'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(n)');
- % title('UNIT STEP FUNCTION(DISCRETE)-102095004');
- %
- % %PLOT UNIT IMPULSE FUNCTION
- % t=[-10:1:10];
- % usi=(t==0);
- % subplot(2,2,4);
- % stem(t,usi);
- % xlabel('Values of n'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(n)');
- % title('UNIT IMPULSE FUNCTION(DISCRETE)-102095004');
- for x=-10:1:10
- if x>=0;
- a=1;
- hold on;
- else
- a=-1;
- hold on;
- end
- stem(x,a);
- xlabel('Values of n'); %FOR LABELING X AND Y
- ylabel('Amplitude x(n)');
- title('SIGNUM FUNCTION(DISCRETE)-102095004');
- end
- _______________________________________________________________
- 1b
- t=0:0.005:0.5;
- f=input('frequency=');
- duty1=input('duty1=');
- duty2=input('duty2=');
- duty3=input('duty3=');
- x=square(2*pi*f*t, duty1);
- y=square(2*pi*f*t, duty2);
- z=square(2*pi*f*t, duty3);
- % subplot(3,1,1)
- % stem(t,x);
- % title('Discrete Square Wave[duty cycle=25](102095004)');
- % xlabel('n');
- % ylabel('x(n)');
- % grid on;
- subplot(3,1,1)
- plot(t,x);
- title('Continuous Square Wave[duty cycle=25](102095004)');
- xlabel('t');
- ylabel('x(t)');
- grid on;
- % subplot(3,1,2)
- % stem(t,y);
- % title('Discrete Square Wave[duty cycle=50](102095004)');
- % xlabel('n');
- % ylabel('y(n)');
- % grid on;
- subplot(3,1,2)
- plot(t,y);
- title('Continuous Square Wave[duty cycle=50](102095004)');
- xlabel('t');
- ylabel('y(t)');
- grid on;
- % subplot(3,1,3)
- % stem(t,z);
- % title('Discrete Square Wave[duty cycle=75](102095004)');
- % xlabel('n');
- % ylabel('z(n)');
- % grid on;
- subplot(3,1,3)
- plot(t,z);
- title('Continuous Square Wave[duty cycle=75](102095004)');
- xlabel('t');
- ylabel('z(t)');
- grid on;
- _______________________________________________________________
- 1c
- a1=input('Amplitude1=');
- f1=input('Frequency1=');
- p1=input('phase1=');
- a2=input('Amplitude2=');
- f2=input('Frequency2=');
- p2=input('phase2=');
- t=(0:0.001:0.25);
- x1=a1*(sin((2*pi*f1*t)+ p1));
- subplot(2,1,1);
- plot(t,x1);
- grid on;
- title('Sine Wave[a=10,f=60,p=0] (102095004)');
- xlabel('t');
- ylabel('t(x)');
- x2=a2*(sin((2*pi*f2*t)+ p2));
- subplot(2,1,2);
- plot(t,x2);
- grid on;
- title('Sine Wave[a=20,f=60,p=pi] (102095004)');
- xlabel('t');
- ylabel('t(x)');
- ________________________________________________________________
- 2
- % %PLOT UNIT STEP FUNCTION
- % t=[-10:1:10];
- % us=(t>=0);
- % subplot(2,2,1);
- % plot(t,us);
- % % plot(t,us);
- % xlabel('Values of t'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(t)');
- % title('UNIT STEP FUNCTION(CONT.)-102095004');
- %
- % %PLOT UNIT IMPULSE FUNCTION
- % t=[-10:1:10];
- % usi=(t==0);
- % subplot(2,2,3);
- % plot(t,usi);
- % xlabel('Values of t'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(t)');
- % title('UNIT IMPULSE FUNCTION(CONT.)-102095004');
- %
- % %PLOT UNIT STEP FUNCTION
- % t=[-10:1:10];
- % us=(t>=0); %BY DEFAULT VALUE IS 1
- % subplot(2,2,2);
- % stem(t,us);
- % stem(t,us);
- % xlabel('Values of n'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(n)');
- % title('UNIT STEP FUNCTION(DISCRETE)-102095004');
- %
- % %PLOT UNIT IMPULSE FUNCTION
- % t=[-10:1:10];
- % usi=(t==0);
- % subplot(2,2,4);
- % stem(t,usi);
- % xlabel('Values of n'); %FOR LABELING X AND Y
- % ylabel('Amplitude x(n)');
- % title('UNIT IMPULSE FUNCTION(DISCRETE)-102095004');
- for x=-10:1:10
- if x>=0;
- a=1;
- hold on;
- else
- a=-1;
- hold on;
- end
- stem(x,a);
- xlabel('Values of n'); %FOR LABELING X AND Y
- ylabel('Amplitude x(n)');
- title('SIGNUM FUNCTION(DISCRETE)-102095004');
- end
- _______________________________________________________________
- 3
- %dft of seq
- clear all;
- clc;
- j=sqrt(-1);
- xn=input('Enter a sequence: ');
- N=length(xn);
- disp(N);
- xk=zeros(1,N);
- for k=0:1:N-1
- for n=0:1:N-1
- xk(k+1) = xk(k+1) + xn(n+1)*exp(-j*2*pi*k*n/N);
- end
- end
- disp('THE DFT SEQUENCE IS:');
- xk
- disp('THE MAGNITUDE SEQUENCE IS:');
- magxk=abs(xk)
- disp('THE PHASE SEQUENCE IS:');
- phaxk=angle(xk)
- wk=0:1:N-1
- subplot(5,1,1);
- stem(wk,xn);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('xn (db)');
- title('Input Sequence-102095004');
- subplot(5,1,2);
- stem(wk,xk);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('xk (db)');
- title('DFT-102095004');
- subplot(5,1,3);
- stem(wk,magxk);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('Magnitude(db)');
- title('Magnitude Spectrum-102095004');
- subplot(5,1,4);
- stem(wk,phaxk);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('Phase(degree)');
- title('Phase Spectrum-102095004');
- %IDFT
- N=length(xk);
- ixk=zeros(1,N);
- for k=0:1:N-1
- for n=0:1:N-1
- ixk(k+1) = ixk(k+1) + ((1/N)*(xk(n+1)*exp(j*2*pi*k*n/N)));
- end
- end
- disp('THE IDFT SEQUENCE IS:');
- ixk
- subplot(5,1,5);
- stem(wk,ixk);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('ixk (db)');
- title('IDFT-102095004');
- ______________________________________________________________
- 4a
- 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)-1020950040...................................................................................................................................................................................................................................................................................................................................................................................................................................................');
- subplot(3,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h');
- title('h(n)-102095004');
- %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 (102095004): ');y
- subplot(3,1,3);
- stem(y);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Linear convulution using circutlar convulution-102095004');
- _______________________________________________________________
- 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)-1020950040...................................................................................................................................................................................................................................................................................................................................................................................................................................................');
- subplot(3,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h');
- title('h(n)-102095004');
- %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 (102095004): ');y
- subplot(3,1,3);
- stem(y);
- xlabel('k'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Linear convulution using circutlar convulution-102095004');
- ______________________________________________________________
- 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)-102095004');
- subplot(4,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h');
- title('h(n)-102095004');
- 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 (102095004): ');
- y;
- subplot(4,1,3);
- stem(y);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Linear convulution-102095004');
- %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 (102095004): ')
- z
- subplot(4,1,4);
- stem(z);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('z(n)');
- title('Circular convulution using Linear convulution-102095004');
- _______________________________________________________________
- 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) (102095004)')
- y=cconv(x,h,N)
- subplot(4,1,1);
- stem(x);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('x(n)');
- title('x(n) - 102095004');
- subplot(4,1,2);
- stem(h);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('h(n)');
- title('h(n) - 102095004');
- subplot(4,1,3);
- stem(yn);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Circular convultion by IDFT-102095004');
- subplot(4,1,4);
- stem(y);
- xlabel('n'); %FOR LABELING X AND Y
- ylabel('y(n)');
- title('Circular convultion by inbuit function-102095004');
- _________________________________________________________________
- 5a
- clc;
- clear all;
- M=25;
- v = 0:1:M-1;
- rec=zeros(length(M-1));
- tr = zeros(length(M-1));
- ham = zeros(length(M-1));
- han = zeros(length(M-1));
- blk = zeros(length(M-1));
- for n=0:1:M-1
- rec(n+1)=1;
- ham(n+1) = 0.54-(0.46*cos((2*pi*n)/(M-1)));
- han(n+1) = 0.5*(1-cos((2*pi*n)/(M-1)));
- blk(n+1) = 0.42-(0.5*cos((2*pi*n)/(M-1)))+(0.08*cos((4*pi*n)/(M-1)));
- if n<=(M-1)/2
- tr(n+1)=(2*n)/(M-1);
- elseif n>(M-1)/2 && n<=M-1
- tr(n+1)=2-((2*n)/(M-1));
- end
- end
- figure
- title('Time domain response for fixed windows(102095004)');
- subplot(2,3,1)
- plot(v,rec,'b')
- title('rectangular')
- xlabel('t')
- ylabel('Amplitude')
- subplot(2,3,2)
- plot(v,tr,'m')
- title('triangular')
- xlabel('t')
- ylabel('Amplitude')
- subplot(2,3,3)
- plot(v,ham,'c')
- title('hamming')
- xlabel('t')
- ylabel('Amplitude')
- subplot(2,3,4)
- plot(v,han,'r')
- title('hanning')
- xlabel('t')
- ylabel('Amplitude')
- subplot(2,3,5)
- plot(v,blk,'g')
- title('blackman')
- xlabel('t')
- ylabel('Amplitude')
- xlim([0,M+2]);
- ylim([0,1.1]);
- N=1024
- xaxis= 0:1/N:(N-1)/N
- figure
- title('Frequency domain response for fixed windows(102095004)');
- subplot(2,3,1)
- fftrec= fft(rec,N)
- fyaxis= abs(fftrec/max(fftrec))
- yaxis= 20*log(fyaxis)
- plot(xaxis,fftshift(yaxis),'b')
- title('rectangular')
- xlabel('freq')
- ylabel('magnitude(db)')
- subplot(2,3,2)
- ffttr= fft(tr,N)
- fyaxis= abs(ffttr/max(ffttr))
- yaxis= 20*log(fyaxis)
- plot(xaxis,fftshift(yaxis),'m')
- title('triangular')
- xlabel('freq')
- ylabel('magnitude(db)')
- subplot(2,3,3)
- fftham= fft(ham,N)
- fyaxis= abs(fftham/max(fftham))
- yaxis= 20*log(fyaxis)
- plot(xaxis,fftshift(yaxis),'c')
- title('hamming')
- xlabel('freq')
- ylabel('magnitude(db)')
- subplot(2,3,4)
- ffthan= fft(han,N)
- fyaxis= abs(ffthan/max(ffthan))
- yaxis= 20*log(fyaxis)
- plot(xaxis,fftshift(yaxis),'r')
- title('hanning')
- xlabel('freq')
- ylabel('magnitude(db)')
- subplot(2,3,5)
- fftblk= fft(blk,N)
- fyaxis= abs(fftblk/max(fftblk))
- yaxis= 20*log(fyaxis)
- plot(xaxis,fftshift(yaxis),'g')
- title('blackman')
- xlabel('freq')
- ylabel('magnitude(db)')
- _____________________________________________________________
- 6a
- clc;
- clear all;
- %DEFINING PARAMETERES
- wp =input('Enter pass band frequency: ') * pi;
- ws =input('Enter stop band frequency: ') * pi;
- tr_width =abs(ws-wp);
- wc = (wp+ws)/2;
- %DEFINING WINDOW
- M = ceil(1.8*pi/tr_width);
- wn=(rectwin(M));
- n = -(M-1)/2:(M-1)/2;
- fc = wc/(2*pi);
- hd = 2*fc*(sinc(2*fc*n));
- h=hd.*wn';
- [HW,WW] = freqz(h,1);
- subplot(2,1,1);
- stem(n,wn);
- title('Rectangular Window 102095004');
- xlabel('n-->');
- ylabel('W[n]-->');
- subplot(2,1,2);
- plot(WW./pi,abs(HW));
- title('Low Pass Filter 12095004');
- xlabel('Normalised Freq-->');
- ylabel('Magnitude-->')
- ______________________________________________________________
- 6b
- clc;
- clear all;
- wp =input('Enter pass band frequency: ') * pi;
- ws =input('Enter stop band frequency: ') * pi;
- tr_width =abs(ws-wp);
- wc = (wp+ws)/2;
- M = ceil(6.1*pi/tr_width);
- wn=(triang(M));
- n = -(M-1)/2:(M-1)/2;
- fc = wc/(2*pi);
- hd = 2*fc*(sinc(2*fc*n));
- h=hd.*wn';
- [HW,WW] = freqz(h,1);
- subplot(2,1,1);
- stem(n,wn);
- title('Triangular Window 102095004');
- xlabel('n-->');
- ylabel('W[n]-->');
- subplot(2,1,2);
- plot(WW./pi,abs(HW));
- title('Low Pass Filter 102095004');
- xlabel('Normalised Freq-->');
- ylabel('Magnitude-->');
- ______________________________________________________________
- 7a
- clc;
- clear all;
- %DEFINING PARAMETERES
- wp =input('Enter pass band frequency: ') * pi;
- ws =input('Enter stop band frequency: ') * pi;
- tr_width =abs(ws-wp);
- wc = (wp+ws)/2;
- %DEFINING WINDOW
- M = ceil(6.6*pi/tr_width);
- wn=(hamming(M));
- n = -(M-1)/2:(M-1)/2;
- fc = wc/(2*pi);
- hd = -2*fc*(sinc(2*fc*n));
- h=hd.*wn';
- [HW,WW] = freqz(h,1);
- subplot(2,1,1);
- stem(n,wn);
- title('Hamming Window 102095004');
- xlabel('n-->');
- ylabel('W[n]-->');
- subplot(2,1,2);
- plot(WW./pi,abs(HW));
- title('Low Pass Filter 12095004');
- xlabel('Normalised Freq-->');
- ylabel('Magnitude-->')
- ______________________________________________________________
- 7b
- clc;
- clear all;
- %DEFINING PARAMETERES
- wp =input('Enter pass band frequency: ') * pi;
- ws =input('Enter stop band frequency: ') * pi;
- tr_width =abs(ws-wp);
- wc = (wp+ws)/2;
- %DEFINING WINDOW
- M = ceil(6.2*pi/tr_width);
- wn=(hanning(M));
- n = -(M-1)/2:(M-1)/2;
- fc = wc/(2*pi);
- hd = -2*fc*(sinc(2*fc*n));
- h=hd.*wn';
- [HW,WW] = freqz(h,1);
- subplot(2,1,1);
- stem(n,wn);
- title('Hanning Window 102095004');
- xlabel('n-->');
- ylabel('W[n]-->');
- subplot(2,1,2);
- plot(WW./pi,abs(HW));
- title('Low Pass Filter 12095004');
- xlabel('Normalised Freq-->');
- ylabel('Magnitude-->')
Advertisement
Add Comment
Please, Sign In to add comment