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?
7 views (last 30 days)
Show older comments
yfft=fft(y); % fft of original signal
N=length(y);
f=(-1/2:1/N:1/2-1/N)*fs;
plot(f,k);
0 Comments
Accepted Answer
Wayne King
on 29 Apr 2013
Edited: Wayne King
on 29 Apr 2013
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 Comments
More Answers (0)
See Also
Categories
Find more on Spectral Measurements 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!