How to use the convolution function rather than filter for signal
Afficher commentaires plus anciens
Hi, I would like to ask how I can apply the convolution for the following code, rather than applying the filter function (note: for Fourier Transform)
Could please anyone help me.
B=[0.5 0.5]; % coefficient of the x(n), x(n-1)
A= [1 -1 0.5];% coefficient of the y(n), y(n-1), y(n-2)
fs=10000;
n=0:1000;
f1=100;
f2=3000;
x=2*sin(2*pi*f1/fs*n)+4*sin(2*pi*f2/fs*n); % input signal
y=filter(B,A,x);% filter
nfft_of_fft = length(y);% number of samples
yf1 = fft(y,nfft_of_fft);%fourier transform function
yf1_mag = abs(yf1);% to make the y-axis more than 0 (absolute value)
yf1_mag_norm = yf1_mag/max(yf1_mag);%normlized the magnitude
yf1_xaxis=fs/2*(0:nfft_of_fft/2-1)/(nfft_of_fft/2);%frequency
plot(yf1_xaxis,yf1_mag_norm(1:nfft_of_fft/2),'r');% plot DEFT
title('Fourier Transform y(n)')
xlabel('Frequency (Hz)')
ylabel('Magnitude')
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Digital Filter Design dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!