***Please simply modify the Matlab code below to provide the desired plots from
ID: 1715444 • Letter: #
Question
***Please simply modify the Matlab code below to provide the desired plots from the attached worksheet.
% Fourier Series and Fourier Transform
% 1. Generate a 2 kHz sinusoidal signal for 30 periods with sampling
% frequency Fs = 16 kHz. Obtain and plot the Fourier Transform magnitude of
% the signal. You should observe peaks at 2 kHz and -2 kHz in the spectrum.
Fs = 16000; % sampling freq
f = 2000; % signal freq
n = 1:1:30*Fs/f; % sample sequence from 1 to 240
t = 1/Fs; % seconds per sample
figure(1)
x = sin(2*pi*n*f/Fs);
f_x = fftshift(20*log10(abs(fft(x)/140)));
subplot(2,1,1)
plot(n,x)
grid on
%axis([0 48 -1.1 1.1])
xlabel('Samples (n)')
ylabel('Amplitude')
subplot(2,1,2)
f=(-0.5:1/240:0.5-1/240)*16;
plot(f,f_x); % peaks observed clearly at +/- 2 kHz
grid on
xlabel('Frequency (f_x)')
ylabel('Amplitude')
% 2. Generate 30 periods of the triangular signal below with period 1ms and
% Fs = 16 kHz.
% (sawtooth periodic function ramping from 0 at 0 ms to 1 at 1 ms repeating
% 3 times and ending at 3 ms.)
Fs = 16000; % sampling freq
f = 1000; % 1 kHz for period of 1 ms
n = 1:1:30*Fs/f; % sample sequence from 1 to 480
t = 1/Fs; % seconds per sample
figure(2)
x = sawtooth(2*pi*n*f/Fs)*0.5+0.5
subplot(2,1,1)
plot(n,x)
grid on
%axis([0 48 -0.1 1.1])
xlabel('Samples (n)')
ylabel('Amplitude')
% 3. Obtain and plot the Fourier Transform magnitude of the signal in (2).
% You should see a sequence of peaks at DC +/- 1 kHz, +/-2 kHz, +/-3 kHz,
% etc. These peaks (at harmonics of the fundamental frequency) represent
% the Fourier Series coefficients of the periodic signal.
subplot(2,1,2)
f_x = fftshift(20*log10(abs(fft(x)/140)));
f=(-0.5:1/480:0.5-1/480)*16;
plot(f,f_x);
grid on
xlabel('Frequency (f_x)')
ylabel('Amplitude')
Explanation / Answer
(a). Sinusoidal signal at 1 Khz:
t = [ 0 : 1 : 30 ];
f = 1000;
fs = 16000;
x = sin(2*pi*f/fs*t);
Plot(t,x);
Xlabel(‘time(seconds)’);
Ylable(‘amplitude’);
Title(‘sinusoid signal’);
Grid;
figure(1);
stem(t,x,'r');
figure(2);
stem(t*1/fs*1000,x,'r');
hold on;
plot(t*1/fs*1000,x);
(b). Sawtooth wave:
n=30;
T=1;
Ts=T/200;
Fs = 16000;
f = 1000;
t=-T/2 : Ts : T/2;
w=(2*pi)/T;
s = 0;
figure;
maxTerms = 6; % also use 10 and 30
for n = 0 : maxTerms - 1
s = s + ((2*n+1)^-2) * (cos((2*n+1)*w*t));
end
% Make wave start at 0
s = s - s(1);
plot(t,s)
grid on;
hold on;
maxTerms = 10;
for n = 0 : maxTerms - 1
s = s + ((2*n+1)^-2) * (cos((2*n+1)*w*t));
end
% Make wave start at 0
s = s - s(1);
plot(t,s)
maxTerms = 30;
for n = 0 : maxTerms - 1
s = s + ((2*n+1)^-2) * (cos((2*n+1)*w*t));
end ; % Make wave start at 0
s = s - s(1);
plot(t,s);
(OR TRY THIS CODE)
T = 30*(1/1000);
Fs = 16000;
dt = 1/Fs;
t = 0:dt:T-dt;
x = sawtooth(2*pi*50*t);
plot(t,x)
grid on
(C). Fourier Transform magnitude of the signal in (2) :
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.