In: Computer Science
2. Please use Matlab to generate two sine waves of 100 Hz and 10 Hz frequencies, respectively. Both sine waves will have a peak value of 1 (peak to peak value of 2). The sampling rate is 1000 Hz (fs = 1000 Hz) and the total data point is 1000 points for each wave. Combine the two sine waves into one. Plot the combined waveform (1 point).
Then, perform fft on the combined waveform. Plot the frequency amplitude spectrum from 1 to 0.5*fs. Make sure you label the x axis properly. (1 point).
Show the complete code (1 point).
Shorten the data point from 1000 to 100. Perform fft on the combined waveform again. Plot the result (0.5 point). Do you observe broadening in peaks (yes or no, you do not need to explain)? (0.5 point)
clc;
Fs=1000;
f1=100;
f2=10;
t=0:1/Fs:0.4;
x1=sin(2*pi*f1*t);
x2=sin(2*pi*f2*t);
x=x1+x2;
nfft=1000; % length of fft
X=fft(x,nfft); %fft calculation
X=X(1:nfft/2);
mx=abs(X); % magnitude response
f=(0:nfft/2-1)*Fs/nfft; % frequency vector
t2=0:1/Fs:.001; %discrete time vector
figure(1)
plot(t,x); %signal plot
grid on
title('Given Signal')
xlabel('Time')
ylabel('Amplitude')
figure(2)
plot(f,mx,'r')
title('Spectrum of sine wave')
xlabel('Frequency')
ylabel('Amplitude')
xlim([1,0.5*Fs])
Part 2 : When Fs=100 Hz
clc;
Fs=100;
f1=100;
f2=10;
t=0:1/Fs:0.4;
x1=sin(2*pi*f1*t);
x2=sin(2*pi*f2*t);
x=x1+x2;
nfft=1000; % length of fft
X=fft(x,nfft); %fft calculation
X=X(1:nfft/2);
mx=abs(X); % magnitude response
f=(0:nfft/2-1)*Fs/nfft; % frequency vector
t2=0:1/Fs:.001; %discrete time vector
figure(1)
plot(t,x); %signal plot
grid on
title('Given Signal')
xlabel('Time')
ylabel('Amplitude')
figure(2)
plot(f,mx,'r')
title('Spectrum of sine wave')
xlabel('Frequency')
ylabel('Amplitude')
xlim([1,0.5*Fs])
Here you can observe the broading in peaks for Fs=100 as compared to fs=1000.
The reason is as the number of samples of x(t) decrease,so the width of peaks looks broader.
Please dont downvote please