Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Practical 1 (Generation of Discrete Signals)
- //Unit Impluse Signal (1,for n=0 or 0,otherwise)
- y1 = zeros(1,21);
- y1(1,11) = 1;
- subplot(3,2,1);
- plot2d3(y1);
- title("Unit Impluse Signal");
- //Unit Step Signal (1, for n>=0 or 0, for n<0)
- y2 = zeros(1,21);
- y2(1,11:21) = 1;
- subplot(3,2,2);
- plot2d3(y2);
- title("Unit Step Signal");
- //Unit Ramp Signal (n,for n>=0 or 0,for n<0)
- y3=0:10;
- subplot(3,2,3);
- plot2d3(y3);
- title("Unit Ramp Signal");
- //Exponential Signal
- //Increasing
- t = -2:0.1:2;
- x = exp(t);
- subplot(3,2,4);
- plot(t,x);
- title("Exponential Increasing");
- //Decreasing
- t = -2:0.1:2;
- x = exp(-t);
- subplot(3,2,5);
- plot(t,x);
- title("Exponential Decreasing");
- //Practical 2 (Linear Convolution of two sequence)
- //Linear Convolution of two sequence
- x = [1,2,3,4];
- h = [1,1,1];
- l1 = length (x);
- l2 = length (h);
- L = l1+l2-1;
- x = [x,zeros(1,L-l1)];
- h = [h,zeros(1,L-l2)];
- y = zeros(1,L);
- for n=1:L;
- for k=1:n
- y(n) = y(n)+x(k)*h(n-k+1);
- end
- end
- disp(y);
- //Plotting
- ny = 0:L-1;
- subplot(3,1,1);
- plot2d3(ny,x);
- title("For x");
- subplot(3,1,2);
- plot2d3(ny,h);
- title("For h");
- subplot(3,1,3);
- plot2d3(ny,y);
- title("For y");
- //Practical 3 (Circular Convolution of two Sequence)
- //Circular Convolution of two sequence
- xn = [1,2,3,4];
- xn = mtlb_fliplr(xn);
- hn = [2,1,2,1];
- x1 = xn;
- h1 = hn;
- for i=1:length(xn);
- x1=[x1($)x1(1:$-1)];
- h1 = hn;
- ycc(i) = sum(x1.*h1);
- disp(ycc(i));
- end
- //Practical 4 (Perform Circular Convolution using DFT and IDFT)
- x1 = input("Enter Input Sequence for x1(n) : ");
- x2 = input("Enter Input Sequence for x2(n) : ");
- l1 = length(x1);
- l2 = length(x2);
- if l1 == l2 then
- a=fft(x1,-1);
- b=fft(x2,-1);
- x3 = a.*b;
- disp(x3);
- x4=ifft(x3);
- disp(x4);
- elseif l1<l2
- x1 = [x1,zeros(1,l2-l1)];
- a=fft(x1,-1);
- b=fft(x2,-1);
- x3 = a.*b;
- disp(x3);
- x4=ifft(x3);
- disp(x4);
- else
- x2 = [x2,zeros(1,l1-l2)];
- a=fft(x1,-1);
- b=fft(x2,-1);
- x3 = a.*b;
- disp(x3);
- x4=ifft(x3);
- disp(x4);
- end
- //Practical 5 ( Perform Linear convolution using circular convolution method)
- //Linear Convolution method using circular convolution method
- xn = [1,2,3,1,0,0];
- hn = [1,1,1,0,0,0];
- xn = mtlb_fliplr(xn);
- x1 = xn;
- h1 = hn;
- for i=1:length(xn);
- x1 = [x1($)x1(1:$-1)];
- h1 = hn;
- ycc(i) = sum(x1.*h1);
- disp(ycc(i));
- end
- //Practical 6 (Perform FFT and IFFT of a discrete sequence)
- //DSP Practical 6 (Butterfly Method)
- clear;
- x = [1,1,0,0,1,1,0,0];
- n = [0,4,2,6,1,5,3,7]+1;
- for i=1:8
- s=n(i);
- xn(i)=x(s);
- end
- //Stages
- O = xn;
- N = length(x);
- S = log2(N);
- cnt=1;
- //Stage 1
- for n=1:2:N-1
- w8_0=exp(-1*%i*2*%pi*0/N);
- f(cnt)=O(n)+O(n+1)*w8_0;
- f(cnt+1)=O(n)-O(n+1)*w8_0;
- cnt=cnt+2;
- end
- disp(f)
- //Stage 2
- cnt=1;
- for n=1:4:N-1
- w8_0=exp(-1*%i*2*%pi*0/N);
- w8_2=exp(-1*%i*2*%pi*2/N);
- G(cnt)=f(n)+f(n+2)*w8_0;
- G(cnt+2)=f(n)-f(n+2)*w8_0;
- G(cnt+1)=f(n+1)+f(n+3)*w8_2;
- G(cnt+3)=f(n+1)-f(n+3)*w8_2;
- cnt=cnt+4;
- end
- disp(G)
- //Stage 3
- cnt=1;
- for n = 1:N/2
- w8 = exp(-1*%i*2*%pi/N);
- X(cnt) = G(n)+G(n+4)*w8^(n-1);
- X(cnt+4) = G(n)-G(n+4)*w8^(n-1);
- cnt = cnt+1;
- end
- disp(X)
- //Practical 7 (To design a FIR filter using window technique)
- //DSP Practical 7 (Rectangle Window)
- clc;clear;
- tmin = 0;tmax = 1;
- t = linspace(tmin,tmax,256);
- [fir_time,fir_freq,fr] = wfir("lp",133,[.2,0],"re",[0,0]);
- subplot(2,2,1);
- title('h(n)');
- plot(fir_time);
- subplot(2,2,2);
- title('H(W)');
- plot(fir_freq);
- X = sin(2*%pi*t*64)+sin(2*%pi*t*128)+sin(2*%pi*t*256);
- subplot(2,2,3);
- Y = fft(X);
- title('Signal IFFT');
- plot(abs(Y));
- subplot(2,2,4);
- YF = abs(Y).*fir_freq;
- title('FIR Filtered Signal');
- plot(abs(YF));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement