rotated plot gone wrong
조회 수: 1 (최근 30일)
이전 댓글 표시
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);
댓글 수: 0
답변 (2개)
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.
댓글 수: 0
William Rose
2022년 12월 21일
댓글 수: 1
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 Center 및 File Exchange에서 Measurements and Spatial Audio에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!