rotated plot gone wrong

1 次查看(过去 30 天)
Sonia
Sonia 2022-12-21
评论: William Rose 2022-12-21
I have the following code in matlab and the image "Figure 2" is plot 3 of the code but it should not come out like this. Please help me correct the code and make the image look like the image "Figure_1YES". This is te audio
fc1=0.125;
fc2=0.25;
f=[fc1,fc2];
h=fir1(64,f,'bandpass');
[data]=audioread("Domini_Fil.wav");
figure();
plot(data)
filteredData=filtfilt(h,1,data);
figure();
plot(filteredData);
[w,rh]=freqz(h,1,64);
w_pi=(w/pi)*6;
figure();
plot(abs(w_pi),abs(rh));
figure();
fft_input=fft(data);
plot(abs(fft_input));
figure();
fft_output=fft(filteredData);
plot(abs(fft_output));
%sound(data);
sound(filteredData);
pause(d+1);

回答(2 个)

Voss
Voss 2022-12-21
You've got the outputs from freqz reversed:
[w,rh]=freqz(h,1,64);
The frequency response is first, and the angular frequencies are second:
[rh,w]=freqz(h,1,64);
Try it like that.

William Rose
William Rose 2022-12-21
Change
[w,rh]=freqz(h,1,64);
to
[rh,w]=freqz(h,1,64);
Good luck.
  1 个评论
William Rose
William Rose 2022-12-21
The attached code is your code, but now the horizontal axis scale is time in seconds (instead of sample number) or frequency in Hertz (instead of frequency sample number). Using actual physical units such as secodns and Hertz helps the viewer understand the data better, in most cases. You can determine the frequencies in Hertz by getting the sampling rate in Hz, fs, from audioread().
I combined plots 1 and 2 into a single figure to make it easier to compare the signal before and after filtering. I did the same thing with plots 4 and 5. I also changed the frequency axis scale to show only the frequencies of the FFT up to the Nyquist frequency. The FFT amplitude above the Nyquist frequency is the mirror image of the FFT amplitude below the Nyquist frequency, so the data above conveys no additional information. That is why I choose not to include it in the plot.
Good luck with your work.

请先登录,再进行评论。

类别

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