How do I plot the impulse response of a sound?

조회 수: 15 (최근 30일)
Ashley Rudolph
Ashley Rudolph 2019년 12월 3일
댓글: Ashley Rudolph 2019년 12월 11일
My assignment is to write a Matlab program that generates sounds using parametric resonators. The ultimate goal is to produce an interesting sound built from concatenated and/or summed outputs from these second order resonators. I can start with an 8kHz sample rate and produce decaying tones at frequencies of my choice. I need to plot some pulse responses and frequency responses.
I believe I have the frequency response at 8K Hz using the freqz() function. I'm not sure how to get the impulse response. Here is my code so far:
% Resonance program in matlab
fs=input('please enter a value for fs'); % Audio sampling rate (Hz)
N = 2*fs; % 2 seconds of data, time length
w0 = pi/8; % frequency - 16 cycles to go around unit circle
R = .999;
a1 = -2.*R.*cos(w0);
a2 = R*R;
G = (1-R).*sqrt(1-2*R*cos(2*w0)+R*R);
b0= G;
b = b0; % feed forward
a = [1 a1 a2]; % feedback
[H,w]=freqz(b,a,2^12);
plot(w, abs(H));
xlabel('Radians per Sample');
ylabel('Magnitude');
title('Frequency Response at 8000 Hz');
I = filter(b,a,[1,zeros(1,500)]); %impulse response
stem ([0:500],I);
xlabel('Samples');
ylabel('Amplitude');
title('Impulse Response at 8000 Hz');
pls=[1 zeros(1,N-1)]';
hpls=filter(b,a,pls);
plot (hpls);
soundsc(hpls, fs);
xlabel('radians per sample');
ylabel('Magnitude');
title('Sound for 2 Second');
Thanks in advance!

채택된 답변

Mahesh Taparia
Mahesh Taparia 2019년 12월 9일
Hi Ashley,
You can use impz, an inbuilt function in MATLAB to find the impulse response of discrete system. After finding transfer function, instead of using 'imfilter' you can use the below command to find the impulse response:
impz(b,a,16000,8000);
For more information, you can refer to documentation page of impz here.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by