Skip to main content

Posts

Showing posts from December, 2021

Matlab Code to obtain DFT and plot its magnitude and phase response

Matlab Code:-   clc; clear all; close all; x=input('Enter the sequence: '); N=length(x); Wn=exp((-j*2*pi)/N);%Twiddle factor fprintf('Twiddle Factor=%f+j(%f)\n',real(Wn),imag(Wn)); disp('Magnitude and phase of Twiddle Factor:');     fprintf('|Wn|=%f    ',Wn);     fprintf('angle Wn=%f\n', angle(Wn));  fprintf('\n');  for k=1:N     X(k)=0; end %Calculation of DFT for k=1:N     for n=1:N         X(k)=X(k)+(x(n)*Wn^((k-1)*(n-1)));     end end %Printing the DFT fprintf('DFT of x(n) is:\n'); disp(X); fprintf('\n'); fprintf('X(k)\tMagnitude\tPhase\n\n'); for k=1:N     fprintf('X(%d)\t%f\t%f\n',k-1,X(k),angle(X(k))); end %To plot the magnitude and phase of the DFT subplot(1,2,1); stem(X,'linewidth',1.5); xlabel('k--->'); ylabel('magnitude--->'); title('Magnitude Response'); grid on; subplot(1,2,2); stem(angle(X),'linewidth',1.5); xlabel('k--->'); ylabel('

Matlab Code for Circular Convolution using Matrix Method and also not using cconv method

Matlab Code:   clc; clear all; close all; %Circular Convolution by Matrix Method x=input('Enter the first sequence: '); h=input('Enter the second sequence: '); n=max(length(h),length(x)); A=0; %To obtain a circular matrix for i=1:n     if i==1         for j=1:n             A(i,j)=x(j); %first row stores all the elements of x(n)         end     else     for j=1:n         if(j==1)             A(i,j)=x(n-i+2); %first column of rows from i=2 to n are x(n),                                                                                x(n-i+2),...,x(3),x(2)         else             A(i,j)=A(i-1,j-1); % the last (n-1) elements of present row is the                                                      fist (n-1) elements of the previous row          end     end     end end disp(A); X=A*h';  %To calculate matrix multiplication disp("Circular Convolution by Matrix Method:"); disp(X'); %Calculating Circular Convolution with out using cconv function disp('Wit

PN Sequence Generator Circuit Design in Multisim

 I tried doing a PN Sequence generator using a shift register in Multisim but it didn't work. However this one with d flip flops and xor gate did work somewhat. Here is the circuit.       Components Required:      1. 4D Flip Flops      2. XOR Gate      3. Function Generator for Clock Pulses      4. Oscilloscope       Circuit Design  :        Output:- Red Square waves- Clock Pulses Blue waves- PN sequence Hope this helps!