MATLAB CODE PLEASE.. For all of this project we will assume a sampling rate of F
ID: 2249958 • Letter: M
Question
MATLAB CODE PLEASE..
For all of this project we will assume a sampling rate of Fs 4,410 Hz (and that is NOT a typo... it is NOT the more standard 44.1kHz value often used for audio). PROCEDURE: Part I. DFT of Single Sinusoid and the Use of the Hamming Window Create a MATLAB function (not a script!) called DFT_1_Sine.m that does the processing described below. It should take in the following input variables: fl in Hz, N in samples, Nzp in samples. It should do the following 1. Create a row vector called x having N samples taken at a rate of Fs 4410 Hz of a sinusoid with frequency of fl Hz, amplitude of 1 and phase of 0 2. Compute the DFT of this sinusoid in x using zero-padding out to the value Nzp and plot its magnitude in dB versus frequency in Hz. This plot should be put in the top of two subplots Now create the “Hamming window" of length N using the Hamming command as follows: w hamming(N) 3. a. Note that this creates a column vector whereas your x vector is a row vector b. So convert w into a row vector (there are several ways you can do this!) 4. In a separate figure plot your Hamming window versus a time index vector n 5. Now create the "windowed" signal xw by multiplying element-wise x times w 6. Compute the DFT of this windowed sinusoid in xw using zero-padding out to the value Nzp and plot its magnitude in dB versus frequency in Hz. This plot should be put in the bottom of two subplots, under the plot of the DFT of the non-windowed sinusoid. Now explore the results of this function for a few values of fl and N (always choosing Nzp to give an appropriately fine grid for the case you are considering). Show a few different representative results in your report; at least one should show the full axis range from the plot command but the rest should be zoomed in to better show the result (this zoom can be done by hand and need not be part of your function)Explanation / Answer
function DFT_1_sin(f1,N,Nzp)
Fs=4410;
t=0:1/Fs:N;
x=sin(2.*pi.*f1.*t);
X=fft(x,Nzp);
f=linspace(0,Fs,Nzp);
subplot(211);
plot(f,20.*log(abs(X)));
title('non-windowed sinusoid');
xlabel('frequency(Hz)');
ylabel('magnitude(dB)');
w=hamming(N);
w=transpose(w);
y=x.*w;
Y=fft(y,Nzp);
subplot(212);
stem(f,20.*log(abs(Y)));
xlabel('frequency(Hz)');
ylabel('magnitude(dB)');
title('windowed sinusoid');
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.