# Sampling of a Sinusoidal Signal and finding the DTFT

**The question was :**

Write a MATLAB function, x = SinSamples(A, w, θ, d, ws), that generates a discrete-time sinusoidal signal x[n] obtained by sampling x(t), (Assume that x(t) is a sinusoidal segment with amplitude A, frequency ω, phase θ and duration ), with sampling frequency ω_s.

```
function SinSamples(A,w,teta,d,w_s)
clc;
fprintf(' This program will read and sample a sin signal.n The parameters are amplitude A , frequency w , phase "teta" and d for duration. n This program was written for the Ele 409 DSP Lab course. n By = John Roach nn');
pause(2);
f = w/(2*pi);
T = 1/f;
tmin = 0;
dt = T/100;
dt1 = 1/(w_s/(2*pi));
t = tmin:dt:d;
t1 = tmin:dt1:d;
x = A*sin(w*t+teta);
x1 = A*sin(w*t1+teta);
subplot(2,1,1);
plot(t,x,'r');
hold on
stem(t1,x1);
title('The sampled and original signal');
xlabel('frequency'), ylabel('amplitude');
grid on;
hold on
subplot(2,1,2)
N=(fs/2)*linspace(-1,1,length(x1));
stem(N,fftshift(abs(fft(x1))));
title('Sampled signal at frequency-domain');
xlabel('frequency'), ylabel('amplitude');
grid on;
```

For sample code ;

```
SinSamples(1,2*pi*1000,pi/6,0.002,2*pi*16000)
```

The output is;

This program will read sample a sin signal. The parameters are amplitude A , frequency w , phase "teta" and d for duration. This program was written for the Ele 409 DSP Lab course.

and