Generation of Sinusoidal Waveform: Aim:-To Generate The Following Signals Using MATLAB
Generation of Sinusoidal Waveform: Aim:-To Generate The Following Signals Using MATLAB
Generation of Sinusoidal Waveform: Aim:-To Generate The Following Signals Using MATLAB
1
TRR ENGINEERING COLLEGE
Sine signal clc; clear all; close all; disp('SINE SIGNAL'); N=input('Enter Number of Samples : '); n=0:.1:N x=sin(n) stem(n,x); xlabel('Time'); ylabel('Amplitude'); title('sine Signal'); Output:- SINE SIGNAL Enter Number of Samples : 16
2
TRR ENGINEERING COLLEGE
3
TRR ENGINEERING COLLEGE
Result:magnitude response 1
|x(k)|
0.5
k phase response 4 3
arg(xk)
2 1 0
3 x
4
TRR ENGINEERING COLLEGE
5
TRR ENGINEERING COLLEGE
Output:-
6
TRR ENGINEERING COLLEGE
7
TRR ENGINEERING COLLEGE
amplitude
4 2 0
amplitude
0 2 4 n 6 8
0 -0.5 -1
4 n
8
TRR ENGINEERING COLLEGE
9
TRR ENGINEERING COLLEGE
10
15
20 25 30 time (milliseconds)
35
40
45
50
10
TRR ENGINEERING COLLEGE
Frequency content of y 80 70 60 50 40 30 20 10 0
50
100
150
350
400
450
500
11
TRR ENGINEERING COLLEGE
Program:%FIR Filter design window techniques clc; clear all; close all; rp=input('enter passband ripple='); rs=input('enter the stopband ripple='); fp=input('enter passband freq='); fs=input('enter stopband freq='); f=input('enter sampling freq= '); beta=input('enter beta value=); wp=2*fp/f; ws=2*fs/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1; end c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n '); if(c==1) y=rectwin(n1); disp('Rectangular window filter response'); end
12
TRR ENGINEERING COLLEGE
if (c==2) y=triang(n1); disp('Triangular window filter response'); end if(c==3) y=kaiser(n1,beta); disp('kaiser window filter response'); end b=fir1(n,wp,y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); plot(o/pi,m); title('LPF'); ylabel('Gain in dB-->'); xlabel('(a) Normalized frequency-->');
Output:enter passband ripple 0.02 enter the stopband ripple 0.01 enter passband freq 1000 enter stopband freq 1500 enter sampling freq 10000 enter beta value 5 enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1
13
TRR ENGINEERING COLLEGE
14
TRR ENGINEERING COLLEGE
15
TRR ENGINEERING COLLEGE
Program:clc; clear all; close all; rp=input('enter passband ripple='); rs=input('enter the stopband ripple='); fp=input('enter passband freq='); fs=input('enter stopband freq='); f=input('enter sampling freq= '); beta=input('enter beta value='); wp=2*fp/f; ws=2*fs/f; num=-20*log10(sqrt(rp*rs))-13; dem=14.6*(fs-fp)/f; n=ceil(num/dem); n1=n+1; if(rem(n,2)~=0) n1=n; n=n-1;
16
TRR ENGINEERING COLLEGE
end c=input('enter your choice of window function 1. rectangular 2. triangular 3.kaiser: \n '); if(c==1) y=rectwin(n1); disp('Rectangular window filter response'); end if (c==2) y=triang(n1); disp('Triangular window filter response'); end if(c==3) y=kaiser(n1,beta); disp('kaiser window filter response'); end b=fir1(n,wp,'high',y); [h,o]=freqz(b,1,256); m=20*log10(abs(h)); plot(o/pi,m); title('HPF'); ylabel('Gain in dB-->'); xlabel('(b) Normalized frequency-->');
Output:enter passband ripple 0.02 enter the stopband ripple 0.01 enter passband freq 1000 enter stopband freq 1500 enter sampling freq 10000 enter beta value 5 enter your choice of window function 1. rectangular 2. triangular 3.kaiser: 1
17
TRR ENGINEERING COLLEGE
Rectangular Window:
2.Triangular Window
18
TRR ENGINEERING COLLEGE
3 Kaiser Window
19
TRR ENGINEERING COLLEGE
Apparatus:-Personal computer with MATLAB software. Program:clc; clear all; clf; ap=4;%pass band attenuation in db as=30;%stop band attenuation in db fp=400;%stop band frequency in hz fs=800;%stop band frequency in hz f=2000;%the sampling frequency in hz omp=2*fp/f; oms=2*fs/f; [n,wn]=buttord(omp,oms,ap,as); [b,a]=butter(n,wn,'low'); w=0:0.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); grid; ylabel('gain in db'); xlabel('normalised frequency'); title('magnitude response'); subplot(2,2,2); plot(om/pi,an); grid; ylabel('phase in radians'); xlabel('normalized frequency'); title('phase response');
20
TRR ENGINEERING COLLEGE
Output:-
magnitude response 40 4
phase response
phase in radians
0 0.5 normalised frequency 1
gain in db
20
2 0 -2 -4
-20
21
TRR ENGINEERING COLLEGE
Apparatus:-Personal computer with MATLAB software. Program:clc; clear all; ap=0.4;%pass band attenuation in db as=30;%stop band attenuation in db fp=400;%stop band frequency in hz fs=800;%stop band frequency in hz f=2000;%the sampling frequency in hz wp=2*fp/f; ws=2*fs/f; %to find cutoff frequency and order of the filter [n,wn]=buttord(wp,ws,ap,as); %system function of the filter [b,a]=butter(n,wn,'high'); w=0:0.01:pi; [h,om]=freqs(b,a,w); m=20*log10(abs(h)); [h,om]=freqs(b,a,w); m=20*log10(abs(h)); an=angle(h); subplot(2,2,1); plot(om/pi,m); grid; ylabel('gain in db'); xlabel('normalised frequency'); title('magnitude response'); subplot(2,2,2); plot(om/pi,an); grid; ylabel('phase in radians'); xlabel('normalized frequency'); title('phase response');
22
TRR ENGINEERING COLLEGE
Output:-
magnitude response 10 0 4
phase response
phase in radians
0 0.5 normalised frequency 1
2 0 -2 -4
gain in db
23
TRR ENGINEERING COLLEGE
24
TRR ENGINEERING COLLEGE
Output:input sequence 2 1 0 -1 -2
10
15
25 30 35 n downsampled sequence
20
40
45
50
2 1
x1
0 -1 -2
10 n
15
20
25
25
TRR ENGINEERING COLLEGE
26
TRR ENGINEERING COLLEGE
Output:-
input sequence 2 1 0 -1 -2
n upsampled sequence 2 1
x1
0 -1 -2
10
15 n
20
25
30
27
TRR ENGINEERING COLLEGE
28
TRR ENGINEERING COLLEGE
ylabel(Amplitude);
Output:-
29
TRR ENGINEERING COLLEGE