prg 1
TRANSCRIPT
-
8/2/2019 PRG 1
1/11
PRG 1% Program to generate sinusoidal waveform based on recursive difference% equation clc;clear all ;
close all ; x = [0 0 ones(1,50)]; % input sequencey_ics =[1 1]; % initializing past outputs h = recur_diff(x,y_ics); % sub-function call plot(h); % printing outputgridtitle( 'Sinusoidal Waveform' );xlabel( 'Time' );ylabel( 'Amplitude' );
% subfunctionfunction 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:
-
8/2/2019 PRG 1
2/11
0 10 20 30 40 50 60-1.5
-1
-0.5
0
0.5
1
1.5Sinusoidal Waveform
Time
A m p
l i t u
d e
PRG 2
-
8/2/2019 PRG 1
3/11
% 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 factornk=n'*k;W=WN.^nk;X=x*W;MagX=abs(X); % Magnitude of calculated DFTPhaseX=angle(X)*180/pi; % Phase of the calculated DFTsubplot(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:
-
8/2/2019 PRG 1
4/11
Enter the value of N(Value of N in N-Point DFT): 8Enter the sequence for which DFT is to be calculated: [1 1 1 1 1 1 0 0]
0 1 2 3 4 5 6 70
2
4
6Magnitude Spectrum of calculated DFT
N
M a g n
i t u
d e
0 1 2 3 4 5 6 7-200
-100
0
100
200Phase Spectrum of the calculated DFT
N
p h a s e
% Program to find IDFT of given signal
-
8/2/2019 PRG 1
5/11
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): 8Enter the sequence for which IDFT is to be calculated: [5, 0, 1-i, 0, 1, 0, 1+j, 0]
The IDFT of given sequence is
1.0000 0.7500 0.5000 0.2500 1.0000 0.7500 0.5000 0.2500
PRG 3
-
8/2/2019 PRG 1
6/11
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 equationy(n) 5 y(n1) = x(n) + 4 x(n1)
Apparatus Used:- System with MATLAB R2008
Theory:
Procedure:- 1) Open MATLAB2) Open new M-file3) Type the program4) Save in current directory5) Compile and Run the program6) For the output see command window\ Figure window
Program:-
b = [1, 4]; %Numerator coefficientsa = [1, -5]; %Denominator coefficientsw = -2*pi: pi/256: 2*pi;[h] = freqz(b, a, w);subplot(2, 1, 1),
plot(w, abs(h));xlabel('Frequency \omega'), ylabel('Magnitude');
gridsubplot(2, 1, 2), plot(w, angle(h));xlabel('Frequency \omega'), ylabel('Phase - Radians'); grid
OUTPUT:
-
8/2/2019 PRG 1
7/11
-8 -6 -4 -2 0 2 4 6 80.5
1
1.5
Frequency
M a g n
i t u
d e
-8 -6 -4 -2 0 2 4 6 8-4
-2
0
2
4
Frequency
P h a s e -
R a
d i a n s
-
8/2/2019 PRG 1
8/11
PRG 4:
% Program to determine the Power Spectrum of given signal clc;clear all ;
close all ; N = 512;fs = N; %sampling frequencyt = 0:1/fs:0.2;x = 2*sin(2*pi*200*t); %input signalplot(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:
-
8/2/2019 PRG 1
9/11
0 20 40 60 80 100 120-2
-1.5
-1
-0.5
0
0.5
1
1.5
2Given Signal
Time
0 100 200 300 400 500 600 700 800 900 10000
2000
4000
6000
8000
10000
12000Frequency content of x
frequency (Hz)
PRG 5
-
8/2/2019 PRG 1
10/11
System function is given by
22
11
0
1)(
++
= z a z a
b z H
% Program to generate sinusoidal signal through filtering clc;clear all ;close all ; fs = 1000; % sampling frequencyt0 = 1/fs;f = 5; 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:
-
8/2/2019 PRG 1
11/11
0 100 200 300 400 500 600 700 800 900 1000-2.5
-2
-1.5
-1
-0.5
0
0.5
1
1.5
2
2.5Sine Wave