cosomyr
2008-12-13, 07:37
下列的程序, 老師說有錯誤, 但是我實在找不出來
老師還要我解釋 畫出的兩個圖 到底代表什麼, 我也不是很清楚
我用了註解功能, 把我想的出來的, 都寫上去了 但是不一定對
有人可以幫我一下嘛? 謝謝 真的感激不盡
我已經花了5個小時在上面了 真的 都快哭出來了
1) 找出syntax 的錯誤
2) 解釋一下這兩個 subplot 到底在建立什麼樣的模型?
橫軸座標的單位可以提供一下嗎?
謝謝
function mysteryfunction
f0 = 261.625; %frequency of the wave
harm = 3.*f0; %the harmonic is in 3 times of the fequency
npts = 8192; %2^13; it's a power of 2
freq = linspace(-1e4,1e4,npts);
cspect = zeros(size(freq)); %generate a series of 0
%10 = bandwidth;
%compute the harmonic in both positive side and negative side
lv = (abs(freq - f0)<10)|(abs(freq+f0)<10);
lv2 = (abs(freq - harm)<10)|(abs(freq+harm)<10);
cspect(lv) = 1; %define the amplitude of a specific frequency shows on the plot
cspect(lv2) = 0.25; %define the amplitude of the harmonic shows on the plot
ctime = fftshift(fft(fftshift(cspect))); %fourier transform using FFT
tt = ((-npts./2):((npts./2)-1))./2e4; %frequency span = 2e4
figure
subplot(2,1,1)
plot(freq,cspect,'-r') %shows where the two harmonics located (v.s frequency)
subplot(2,1,2)
plot(tt,real(ctime),'-r') %plot the undulation
xlim([-.02 .02])
老師還要我解釋 畫出的兩個圖 到底代表什麼, 我也不是很清楚
我用了註解功能, 把我想的出來的, 都寫上去了 但是不一定對
有人可以幫我一下嘛? 謝謝 真的感激不盡
我已經花了5個小時在上面了 真的 都快哭出來了
1) 找出syntax 的錯誤
2) 解釋一下這兩個 subplot 到底在建立什麼樣的模型?
橫軸座標的單位可以提供一下嗎?
謝謝
function mysteryfunction
f0 = 261.625; %frequency of the wave
harm = 3.*f0; %the harmonic is in 3 times of the fequency
npts = 8192; %2^13; it's a power of 2
freq = linspace(-1e4,1e4,npts);
cspect = zeros(size(freq)); %generate a series of 0
%10 = bandwidth;
%compute the harmonic in both positive side and negative side
lv = (abs(freq - f0)<10)|(abs(freq+f0)<10);
lv2 = (abs(freq - harm)<10)|(abs(freq+harm)<10);
cspect(lv) = 1; %define the amplitude of a specific frequency shows on the plot
cspect(lv2) = 0.25; %define the amplitude of the harmonic shows on the plot
ctime = fftshift(fft(fftshift(cspect))); %fourier transform using FFT
tt = ((-npts./2):((npts./2)-1))./2e4; %frequency span = 2e4
figure
subplot(2,1,1)
plot(freq,cspect,'-r') %shows where the two harmonics located (v.s frequency)
subplot(2,1,2)
plot(tt,real(ctime),'-r') %plot the undulation
xlim([-.02 .02])