You are on page 1of 11

PRG 1

% Program to generate sinusoidal waveform based on recursive difference % equation clc; clear all; close all; x = [0 0 ones(1,50)]; y_ics =[1 1]; h = recur_diff(x,y_ics); % input sequence % initializing past outputs % sub-function call

plot(h); % printing output grid title('Sinusoidal Waveform'); xlabel('Time'); ylabel('Amplitude'); % subfunction function y = recur_diff(x,y_ics); y(1) = y_ics(1); y(2) = y_ics(2); for k=3:(length(x)+2) y(k)=1.91996*y(k-1)-0.99998*y(k-2); % recursive operation end

OUTPUT:

Sinusoidal Waveform 1.5

0.5 Amplitude

-0.5

-1

-1.5

10

20

30 Time

40

50

60

PRG 2

% Program to find DFT of given signal

clc; clear all; close all; N = input('Enter the value of N(Value of N in N-Point DFT): '); x = input('Enter the sequence for which DFT is to be calculated: '); n=[0:N-1]; k=[0:N-1]; WN=exp(-1*j*2*pi/N); %Twiddle factor nk=n'*k; W=WN.^nk; X=x*W; MagX=abs(X); % Magnitude of calculated DFT PhaseX=angle(X)*180/pi; % Phase of the calculated DFT subplot(2,1,1); plot(k,MagX); title('Magnitude Spectrum of calculated DFT'); xlabel('N') ylabel('Magnitude') subplot(2,1,2); plot(k,PhaseX); title('Phase Spectrum of the calculated DFT'); xlabel('N') ylabel('phase')

OUTPUT:

Enter the value of N(Value of N in N-Point DFT): Enter the sequence for which DFT is to be calculated:

8 [1 1 1 1 1 1 0 0]

Magnitude Spectrum of calculated DFT 6

Magnitude

4 5 N Phase Spectrum of the calculated DFT

200 100 phase 0 -100 -200

3 N

% Program to find IDFT of given signal

N = input('Enter the value of N(Value of N in N-Point DFT): '); X = input('Enter the sequence for which IDFT is to be calculated: '); n=[0:N-1]; k=[0:N-1]; WN=exp(1*j*2*pi/N); nk=n'*k; W=WN.^nk; x=X*W; x = x/N; disp('The IDFT of given sequence is'); disp(real(x));

OUTPUT: Enter the value of N(Value of N in N-Point DFT): Enter the sequence for which IDFT is to be calculated: The IDFT of given sequence is 1.0000 0.7500 0.5000 0.2500 1.0000 0.7500 8 [5, 0, 1-i, 0, 1, 0, 1+j, 0] 0.5000 0.2500

PRG 3

Frequency response of a given system given in (Transfer Function/ Difference equation form)
Aim :- To find the frequency response of the system given by difference equation y(n) 5 y(n1) = x(n) + 4 x(n1) Apparatus Used:- System with MATLAB R2008 Theory: Procedure:- 1) Open MATLAB 2) Open new M-file 3) Type the program 4) Save in current directory 5) Compile and Run the program 6) For the output see command window\ Figure window Program:b = [1, 4]; %Numerator coefficients a = [1, -5]; %Denominator coefficients w = -2*pi: pi/256: 2*pi; [h] = freqz(b, a, w); subplot(2, 1, 1), plot(w, abs(h)); xlabel('Frequency \omega'), ylabel('Magnitude'); grid subplot(2, 1, 2), plot(w, angle(h)); xlabel('Frequency \omega'), ylabel('Phase - Radians'); grid

OUTPUT:

1.5

Magnitude

0.5 -8

-6

-4

-2

0 Frequency

4 Phase - Radians 2 0 -2 -4 -8

-6

-4

-2

0 Frequency

PRG 4:
% Program to determine the Power Spectrum of given signal clc; clear all; close all; N = 512; fs = N; %sampling frequency t = 0:1/fs:0.2; x = 2*sin(2*pi*200*t); %input signal plot(x); title('Given Signal'); xlabel('Time'); c = xcorr(x); c1 = c(1:length(t)); F = fft(c,N); % figure,plot(t,abs(F)); f = 1000*(0:N-1)/N; figure,plot(f,abs(F)); title('Frequency content of x'); xlabel('frequency (Hz)');

OUTPUT:

Given Signal 2 1.5 1 0.5 0 -0.5 -1 -1.5 -2

20

40

60 Time

80

100

120

Frequency content of x 12000

10000

8000

6000

4000

2000

100

200

300

400 500 600 frequency (Hz)

700

800

900

1000

PRG 5

System function is given by

H ( z) =

b0 1 + a1 z + a 2 z 2
1

% Program to generate sinusoidal signal through filtering clc; clear all; close all; fs = 1000; t0 = 1/fs; f = 5; % sampling frequency

imp = [1; zeros(999,1)]; %Input - Impulse b0=2*sin(2*pi*f*t0); a1=-2*cos(2*pi*f*t0); a2=1; num = [b0]; den = [1 a1 a2]; y = filter(num,den,imp); figure,plot(y); title('Sine Wave')

OUTPUT:

Sine Wave 2.5 2 1.5 1 0.5 0 -0.5 -1 -1.5 -2 -2.5

100

200

300

400

500

600

700

800

900

1000

You might also like