how to calculate the spectrum fourier ?
1 view (last 30 days)
Show older comments
%%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
0 Comments
Answers (1)
Wayne King
on 8 Dec 2013
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.
0 Comments
See Also
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!