Вы находитесь на странице: 1из 3

Ex 5 part 1

f =100; %input freq in Hz


w = 2*pi*f; %input freq in rad
A1 =1 %signal Amp
start_time = 0 %time when simulation starts
end_time = 1/f;
Fs = 1000; %sampling freq
Ts =1/Fs; %sampling interval
t1 = start_time:Ts:end_time; %create time vector
S1 = A1*sin(w*t1); %compute one cycle
subplot(3,1,1)
stem(t1,S1)
title('Sine Input');
text(0.0062,0.65,'Amplitube = 1V') %place text at co-ordinates (0.0062,0.75
)
xlabel('time,seconds');
ylabel('Amplitude');
grid
%plot with new amp
Fs = 1000; %sampling freq
Ts = 1/Fs; %sampling interval
end_time = 1/f; %time when simulation ends (1 cycle)
t2 = start_time:Ts:end_time; %create time vector
A2 = 2; %new amp
S2 = A2*sin(w*t2); %compute one cycle
subplot(3,1,2)
stem(t2,S2)
text(0.0062,1.5,'Amplitude = 2V') %place text at co-ordinates (0.0
062,0.75)
xlabel('time,seconds');
ylabel('Amplitude');
grid
%plot with new amp
Fs = 1000; %sampling freq
Ts = 1/Fs; %sampling interval
end_time = 1/f; %time when simulation ends (1 cycle)
t3 = start_time:Ts:end_time; %create time vector
A3 = 10; %new amp
S3 = A3*sin(w*t3); %compute one cycle
subplot(3,1,3)
stem(t3,S3)
text(0.0062,1.5,'Amplitude = 10V') %place text at co-ordinates (0.0062,0.75
)
xlabel('time,seconds');
ylabel('Amplitude');
grid

Ex 5 part 2
f=100; %input frequency in Hertz
w=2*pi*f; %input frequency in radians
A=1; %signal amplitude
start_time=0; %time when simulation starts
end_time=2/f; %time when simulation ends in seconds
Fs=1000; %sampling frequency
Ts=1/Fs; %sampling interval
t=start_time:Ts:end_time; %the time vector
s1=A*sin(w*t) %compute waveform
%plot the sampled signal waveform
subplot(2,1,1);stem(t,s1) %plot the waveform
xlabel('seconds')
ylabel('amplitude') %label the axes
grid
%plot the signal spectrum
N=length(s1) %obtain number of sample points in input
fv=((0:N-2)/(Ts*(N-1))) %frequency vector with +ve frequencies
(ensure only N values)
f1=fft(s1,N-1) %do DFT/FFT
f1s=f1;
%f1s=fftshift(f1);
%fv=(0 N-2)/(Ts*(N-1)))-Fs/2
%frequency vector shift
%frequency scale to create ve val
ues
%(NB: symmetry property for DFT:
W(n)=W(n-k))
amp_f1s=abs(f1s)/((N-1)/2) %scale fft amplitude
subplot(2,1,2); plot(fv,amp_f1s) %plot scaled magnitude spectrum
%set the range to view
%change these values to get more readabl
e plots
Xmin=0; %lowest frequency to view
Xmax=200; %highest frequency to view only +ve half
of the spectrum
%spectrum is needed since its symmetrica
l
%lowest amplitude to view
Ymin=0;
Ymax=1.5*A;
axis([Xmin Xmax Ymin Ymax]);
grid
xlabel('frequency');
ylabel('magnitude'); %label the axes

Вам также может понравиться