How i do i get the value of a fft bin?

조회 수: 9 (최근 30일)
Denny Muttathil
Denny Muttathil 2016년 12월 18일
댓글: Denny Muttathil 2016년 12월 18일
Hello Community!
First of all, half of this code is taken from this website. Because i needed a part of it since it is for a project. Anyway to my problem: If look at the line, where i put the comment 'L,M,H', where i am defining the frequency range. Afterwards i use the "find", so that the code knows, which value it should take in Low indices, Medium Indices and High Indices and so on... Then values are being averaged and the value from the variable ML is 0.1254. How do i know, which values are being used to get this number. I want to see it in the command window.
clear all;
Fs = 1000; % Sampling frequency
T = 1/Fs; % Sampling period
L = 1000; % Length of signal
t = (0:L-1)*T; % Time vector
% Form a signal containing a 50 Hz sinusoid
% of amplitude 0.7 and a 120 Hz sinusoid of amplitude 1.
S = 0.4 + 0.7*sin(2*pi*50*t) + sin(2*pi*120*t) ;
%Corrupt the signal with zero-mean white noise with a variance of 4.
X = S + 2*randn(size(t));
% Plot the noisy signal in the time domain. It is difficult to identify
% the frequency components by looking at the signal X(t).
plot(1000*t(1:50),X(1:50))
title('Signal Corrupted with Zero-Mean Random Noise')
xlabel('t (milliseconds)')
ylabel('X(t)')
%%Compute the Fourier transform of the signal.
Y = fft(X);
% Compute the two-sided spectrum P2. Then compute the single-sided
% spectrum P1 based on P2 and the even-valued signal length L.
P2 = abs(Y/L);
P1 = P2(1:L/2+1);
P1(2:end-1) = 2*P1(2:end-1);
% Define the frequency domain f and plot the single-sided amplitude
% spectrum P1. The amplitudes are not exactly at 0.7 and 1,
% as expected, because of the added noise.
% On average, longer signals produce better frequency approximations.
f = Fs*(0:(L/2))/L;
%%L,M,H bands
% start & stop frequency defenition of bands
fL = [ 30, 120 ]; %fL steht für die niedrigen Frequenzen. Hier werden die Eckfrequenzen definiert.
fM = [ 80, 250 ]; %fM steht für die mittleren Frequenzen. Hier werden die Eckfrequenzen definiert.
fH = [ 200, 1000 ]; %fH steht für die hohen Frequenzen. Hier werden die Eckfrequenzen definiert.
% indices of bands
LI = find((f>=fL(1))&(f<=fL(2))); % Die Funktion "find" listet alle 0er und 1er-Elemente
MI = find((f>=fM(1))&(f<=fM(2)));
HI = find((f>=fH(1))&(f<=fH(2)));
% mean values of bands
ML = mean(P1(LI));
MM = mean(P1(MI));
MH = mean(P1(HI));

채택된 답변

Image Analyst
Image Analyst 2016년 12월 18일
You can just put them on their own lines:
P1(LI)
P1(MI)
P1(HI)
You do know that your frequency bands overlap, and that your low frequency band does not contain the lowest frequencies, right?
  댓글 수: 1
Denny Muttathil
Denny Muttathil 2016년 12월 18일
@Imgae Analyst Yes i am aware of that. The values for the frequency band were chosen rather randomely. Anyway thanks for helping me. It seems really simple, but i am new to matlab, so it was really confusing for me.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Discrete Fourier and Cosine Transforms에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by