how to calculate the spectrum fourier ?
이전 댓글 표시
%%load an audio file %% [test,fs]=wavread('huth2.wav'); %% loads a file huth2.wav into the matrix test fs is the sampling frequency
size_of_file=size(test) %%checks the size of file in bytes %%
time=(1/fs)*length(test); %%calculate the time spacing %%
t=linspace(0,time,length(test)); %%specifies the time array ‘t’
plot(t,test); %plots the signal %%
xlabel('time (sec)'); ylabel('relative signal strength') axis([0 time -1.5 1.5])
%%% to play sound %%% soundsc(test,fs) pause;
%%%echo testout=test; N=10000; % delay amount N/44100 seconds for n=N+1:length(test) testout(n)=test(n)+test(n-N); % approximately ¼ second echo end
soundsc(testout,fs) % signal with new echo Y = fft(test); F=-fs/2:fs/(N-1):fs/2; Z=fftshift(Y)/fs; plot(F,abs(Z)); ____________________________________________________________
when I plot(F,abs(Z)) shows me Error using plot Vectors must be the same lengths.
how can I solve this error
답변 (1개)
Wayne King
2013년 12월 8일
What is the length of test? You do not give us that. You create your frequency vector based on:
N=10000;
But is that the size of test?
The output of fft() is a vector the same length as test. So
F = -fs/2:fs/(N-1):fs/2; % or something similar
Only works when the length of test is 10000.
카테고리
도움말 센터 및 File Exchange에서 Spectral Measurements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!