1. Use MatLab to construct a 10 second sample of cosine wave hav- ing a temporal
ID: 2249894 • Letter: 1
Question
1. Use MatLab to construct a 10 second sample of cosine wave hav- ing a temporal frequency f- 440 Hertz (if your piano is in tune, this is A above middle C). The number of samples per second should be some integer times the frequency of the tone. If Fs is the sampling frequency and x is the signal, you can use the command "soundx,Fs)" to play the signal through the speakers on your computer. Plot 4 periods of the signal at Fs-4f. Does it look much like a cosine wave? Increase Fs until it looks smooth. Use MatLab to estimate the power of the sampled signal and compare it with a theoretical calculation of the power for a cosine of the same fre- quency and amplitude. Discuss what is happening as you increase Fs.Explanation / Answer
Hello,
Please find the answer attached as under. Please give a thumbs up rating if you find the answer useful! Have a rocking day ahead!
The matlab code for the entire question is posted below. The code first samples the given cos wave at a multiple of 8 times the given frequency. The later part of the code samples the wave at 10, 12, 16 and 32 multiples. The power for each wave is directly output on the screen. The second figure contains the plots of all 4 cosine waves sampled differently. As the sampling rate increases, the cos wave starts to look more smooth. However, the power calculations are not affected much, since the cose wave has only one frequency component, and this component is obtained by sampling at double the base frequency, i.e. 2*f. Please verify using the Matlab code below.
********************************Matlab Code***********************
t_end = 10; % end time for simulation
f = 440; % freq of cosine wave
N = 8; % sampling freq multiple
Fs = N*f;
t = 0:1/Fs:t_end; % time vector for simulation
y = cos(2*pi*f*t);
sound(y,Fs) % playing the sound
figure;
plot(t(1:4*Fs/f),y(1:4*Fs/f)) % plotting the first 4 period
grid;
xlabel('Time(s)')
ylabel('Amplitude')
title('First four periods of sampled cosine wave');
pRMS = (1/sqrt(2))^2 % finding power
N1=10;N2=12;N3=16;N4=32; % defining four sampling multiples for 4 waves
Fs1 = N1*f;
Fs2 = N2*f;
Fs3 = N3*f;
Fs4 = N4*f;
t1 = 0:1/Fs1:t_end;
t2 = 0:1/Fs2:t_end;
t3 = 0:1/Fs3:t_end;
t4 = 0:1/Fs4:t_end;
y1 = cos(2*pi*f*t1);
y2 = cos(2*pi*f*t2);
y3 = cos(2*pi*f*t3);
y4 = cos(2*pi*f*t4);
figure; % plotting 4 sampled cosine waves in one fig
subplot(4,1,1)
plot(t1(1:4*Fs1/f),y1(1:4*Fs1/f))
xlabel('Time(s)')
ylabel('Fs=10*f')
pRMS1 = rms(y1)^2 % power of first signal
subplot(4,1,2)
plot(t2(1:4*Fs2/f),y2(1:4*Fs2/f))
xlabel('Time(s)')
ylabel('Fs=12*f')
pRMS2 = rms(y2)^2
subplot(4,1,3)
plot(t3(1:4*Fs3/f),y3(1:4*Fs3/f))
xlabel('Time(s)')
ylabel('Fs=16*f')
pRMS3 = rms(y3)^2
subplot(4,1,4)
plot(t4(1:4*Fs4/f),y4(1:4*Fs4/f))
xlabel('Time(s)')
ylabel('Fs=32*f')
pRMS4 = rms(y4)^2
**************************************** End of code*****************************
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.