Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
matlab:freqplots [2010/01/14 19:42] 127.0.0.1 external edit |
matlab:freqplots [2017/02/26 20:31] (current) mike |
||
---|---|---|---|
Line 8: | Line 8: | ||
FILE: plotfft.m | FILE: plotfft.m | ||
- | <code matlab> | + | <file matlab plotfft.m> |
- | function e = plotfft(in); | + | function e = plotfft(in,sampleRate); |
% | % | ||
% This function computes the FFT of an input and plots it on a easy to read plot. The function also | % This function computes the FFT of an input and plots it on a easy to read plot. The function also | ||
Line 18: | Line 18: | ||
% Copyright (c) 2009 | % Copyright (c) 2009 | ||
% | % | ||
- | MIN_dB = -180; % minimum of 140 db below 0dB; | + | MIN_dB = -120; % minimum of 120 db below 0dB; |
- | %win = hanning(length(in))'; % not as good as a hamming window | + | win = hanning(length(in))'; |
- | win = hamming(length(in))'; | + | %win = hamming(length(in))'; |
winsq = win.*win; | winsq = win.*win; | ||
bb = in.*winsq; | bb = in.*winsq; | ||
c = fft(bb); | c = fft(bb); | ||
- | l = floor(length(in)/2)+1; | + | if nargin < 2 |
+ | sampleRate = 1.0; | ||
+ | end | ||
+ | |||
+ | l = floor(length(in)/2)+1; | ||
idx = [[l+1:length(in)] [1:l]]; | idx = [[l+1:length(in)] [1:l]]; | ||
c = c(idx); | c = c(idx); | ||
Line 33: | Line 37: | ||
% trim to MIN | % trim to MIN | ||
- | x = find(e < MIN_dB); %trim to 140dB | + | x = find(e < MIN_dB); %trim to MIN_db |
e(x) = MIN_dB; | e(x) = MIN_dB; | ||
Line 41: | Line 45: | ||
t = linspace(-0.5,0.5,length(in));; % works for odd input lengths | t = linspace(-0.5,0.5,length(in));; % works for odd input lengths | ||
end | end | ||
- | plot(t,e); | + | plot(t*sampleRate,e); |
grid on; | grid on; | ||
xlabel('fs'); | xlabel('fs'); | ||
ylabel('dB'); | ylabel('dB'); | ||
+ | |||
title(['Normalized Frequency Plot (peak= ' int2str(max(d)) 'dB)']) | title(['Normalized Frequency Plot (peak= ' int2str(max(d)) 'dB)']) | ||
- | </code> | + | </file> |