i want frequency domain spectrum of an audio file and i want to set frequency range of about 3 kHz. it is showing range upto 10 kHz. how can i modify it?
3 次查看(过去 30 天)
显示 更早的评论
yfft=fft(y); % fft of original signal
N=length(y);
f=(-1/2:1/N:1/2-1/N)*fs;
plot(f,k);
0 个评论
采纳的回答
Wayne King
2013-4-29
编辑:Wayne King
2013-4-29
You have a couple things here. For one, you are creating a frequency vector with 0 frequency at the center. Do you really need the "negative" and "positive" frequency content? If so, then do the following:
fs = 1e4;
t = 0:1/fs:1-1/fs;
y = cos(2*pi*1000*t)+1/2*sin(2*pi*2000*t)+randn(size(t));
DF = fs/length(y);
ydft = fftshift(fft(y));
N = length(y);
f=(-1/2:1/N:1/2-1/N)*fs;
plot(f,abs(ydft))
set(gca,'xlim',[-3000 3000]);
If that is not necessary:
fs = 1e4;
t = 0:1/fs:1-1/fs;
y = cos(2*pi*1000*t)+1/2*sin(2*pi*2000*t)+randn(size(t));
ydft = fft(y);
% assuming length(y) is even
f = 0:fs/length(y):fs/2;
plot(f,abs(ydft(1:length(y)/2+1)))
You can easily just extract the Fourier transform coefficients that correspond to [-3000 3000] or [0 3000] if that is what you want. Since the frequency interval between elements in ydft is just fs/length(y), just pull out the elements corresponding to the frequencies you want.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!