To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
The primary repository for this project is hosted at git://github.com/rmeddis/MAP.git .
This repository is a read-only copy which is updated automatically every hour.
root / utilities / UTIL_FFT.m @ 38:c2204b18f4a2
History | View | Annotate | Download (1.45 KB)
| 1 | 38:c2204b18f4a2 | rmeddis | function [fft_powerdB, fft_phase, frequencies, fft_ampdB]=... |
|---|---|---|---|
| 2 | UTIL_FFT(getFFTsignal, dt, referenceAmplitude) |
||
| 3 | % UTIL_FFT |
||
| 4 | % [fft_powerdB, fft_phase, frequencies, fft_ampdB]= UTIL_FFT(getFFTsignal, dt, referenceAmplitude) |
||
| 5 | |||
| 6 | x=length(getFFTsignal); % adjust the length of the signal to a power of 2 for FFT |
||
| 7 | n=2; |
||
| 8 | while n<=x |
||
| 9 | n=n*2; |
||
| 10 | end |
||
| 11 | n=round(n/2); |
||
| 12 | getFFTsignal=getFFTsignal(1:n); |
||
| 13 | frequencies = (1/dt)*(1:n/2)/n; |
||
| 14 | |||
| 15 | fft_result = fft(getFFTsignal, n); % Compute FFT of the input signal. |
||
| 16 | fft_power = fft_result .* conj(fft_result); % / n; % Compute power spectrum. |
||
| 17 | % Dividing by 'n' we get the power spectral density. |
||
| 18 | % fft_power = fft_result .* conj(fft_result) / n; % Compute power spectralDensity. |
||
| 19 | |||
| 20 | % Prepare the FFT for display |
||
| 21 | fft_power=fft_power(1:length(fft_power)/2); % remove mirror frequencies |
||
| 22 | % fft_powerdB = UTIL_amp2dB (fft_power, max(fft_power)); % convert to dB |
||
| 23 | fft_powerdB = 10*log10(fft_power); % convert to dB |
||
| 24 | |||
| 25 | % amplitude spectrum |
||
| 26 | if nargin<3 |
||
| 27 | referenceAmplitude=28e-6; % for SPL |
||
| 28 | end |
||
| 29 | % refAmpdB= referenceAmplitude^0.5; |
||
| 30 | fft_ampdB = 10*log10(fft_power/referenceAmplitude); % convert to dB |
||
| 31 | % peak_fft_powerdBSPL=max(fft_ampdB) |
||
| 32 | |||
| 33 | |||
| 34 | fft_phase = angle(fft_result); % Compute the phase spectrum. |
||
| 35 | fft_phase=fft_phase(1:length(fft_phase)/2); % remove mirror phases |
||
| 36 | jags=find(diff(fft_phase)>0); % unwrap phase |
||
| 37 | for i=jags, |
||
| 38 | fft_phase(i+1:end)=fft_phase(i+1:end)-2*pi; |
||
| 39 | end |