You are on page 1of 5

SONAR ASSIGNMENT-1

Ex1. Generate the sine wave of 1 kHz with sampling frequency of 10 kHz with
constant amplitude and with initial phase of

(i) 0 rad

Ex-1.1
fs=10000; %sampling frequency
t=0:1/fs:1-0.5/fs; %time
A=1; %amplitude
f=1000; %frequency
fi=0; %phase (calculated form deg. to rad.)
x = A*cos(2*pi*f*t+fi); %signal
X=fft(x); %FFT
df=fs/length(X); %frequency resolution
f=(0:1:length(X)/2)*df; %frequency axis
subplot(2,1,1);
M=abs(X)/length(x)*2; %amplitude spectrum
plot(f,M(1:length(f)));
subplot(2,1,2);
P=angle(X)*180/pi; %phase spectrum (in deg.)
plot(f,P(1:length(f)));
Ex-1.1

Ex-1.2 phase= pi/3 rad.


fs=10000; %sampling frequency
t=0:1/fs:1-0.5/fs; %time
A=1; %amplitude
f=1000; %frequency
fi=pi/3*pi/180; %phase (calculated form deg. to rad.)
x = A*cos(2*pi*f*t+fi); %signal
X=fft(x); %FFT
df=fs/length(X); %frequency resolution
f=(0:1:length(X)/2)*df; %frequency axis
subplot(2,1,1);
M=abs(X)/length(x)*2; %amplitude spectrum
plot(f,M(1:length(f)));
subplot(2,1,2);
P=angle(X)*180/pi; %phase spectrum (in deg.)
plot(f,P(1:length(f)));
Ex-1.2

Ex-1.3 phase= pi/6 rad.


fs=10000; %sampling frequency
t=0:1/fs:1-0.5/fs; %time
A=1; %amplitude
f=1000; %frequency
fi=pi/6*pi/180; %phase (calculated form deg. to rad.)
x = A*cos(2*pi*f*t+fi); %signal
X=fft(x); %FFT
df=fs/length(X); %frequency resolution
f=(0:1:length(X)/2)*df; %frequency axis
subplot(2,1,1);
M=abs(X)/length(x)*2; %amplitude spectrum
plot(f,M(1:length(f)));
subplot(2,1,2);
P=angle(X)*180/pi; %phase spectrum (in deg.)
plot(f,P(1:length(f)));
Ex-1.3

Ex-2 Linear Chirp signal of with starting frequency of 100 Hz ending frequency
of 2 KHz and duration of 1 sec.

Fs=1000; % sample rate

tf=1; % 1 seconds

t=0:1/Fs:tf-1/Fs;

f1=100;

f2=2000; % start @ 100 Hz, go up to 2KHz

semi_t=0:1/Fs:(tf/2-1/Fs);

sl=2*(f2-f1/2);

f1=f1*semi_t+(sl.*semi_t/2);

f2=f1(end)+f2*semi_t-sl.*semi_t/2;

f=[f1 f2];

y=1.33*cos(2*pi*f.*t);

plot(t,y)
Ex-2

You might also like