MATLAB Answers


what are the hamming, fft, ifft functions?

Asked by SELDA
on 4 Jan 2013
% Signal parameters:
f = [ 440 880 1000 2000 ];      % frequencies   
M = 256;                        % signal length 
Fs = 5000;                      % sampling rate
% Generate a signal by adding up sinusoids:
x = zeros(1,M); % pre-allocate 'accumulator'
n = 0:(M-1);    % discrete-time grid 
for fk = f; 
    x = x + sin(2*pi*n*fk/Fs); 
% Filter parameters:
L = 257;    % filter length 
fc = 600;   % cutoff frequency 
% Design the filter using the window method:
hsupp = (-(L-1)/2:(L-1)/2);
hideal = (2*fc/Fs)*sinc(2*fc*hsupp/Fs);
h = hamming(L)' .* hideal; % h is our filter
% Choose the next power of 2 greater than L+M-1 
Nfft = 2^nextpow2(L+M-1);
% Zero pad the signal and impulse response:
xzp = [ x zeros(1,Nfft-M) ];
hzp = [ h zeros(1,Nfft-L) ];
X = fft(xzp); % signal
H = fft(hzp); % filter
Y = X .* H;
y = ifft(Y);
relrmserr=norm(imag(y))/norm(y) % check... should be zero
y = real(y);
subplot(2,1,1), plot(x)
subplot(2,1,2), plot(y)
grid on

my low pass filter works but I don't want to use hamming, fft and ifft. Instead of these I want to use hamming, fft, ifft functions. I found some codes about them but it didn't work. Could you help me please?


What are the symptoms of "it didn't work"?

I don't understand - you say you don't want to use those three functions and then you say you want to use them instead of themselves. What does all that mean? Do you want to use them or not?

on 6 Jan 2013

I'm really sorry about my bad english. for example in my filter there is fft function.But I must not use fft function.I have to use equation of fft. I wrote

w = .54 - .46*cos(2*pi*(0:L-1)'/(L-1)); instead of hamming

I wrote

N=length(x); for k=1:N X(k)=0; for n=1:N X(k)=X(k)+x(n).*exp(-1j.*2.*pi.*(n-1).*(k-1)./N); end end instead of fft

I wrote for o=1:L T(o)=0; for u=1:L T(o)=(1/L)*(T(o)+X(u).*exp(2.*pi.*j.*(o-1).*(u-1)./L)); end end instead of ifft

but these didn't work


No products are associated with this question.

1 Answer

Answer by Rick Rosson
on 5 Jan 2013
   >> doc filter
   >> doc fdatool
   >> doc fir1


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!