rotated plot gone wrong

2 visualizzazioni (ultimi 30 giorni)
Sonia
Sonia il 21 Dic 2022
Commentato: William Rose il 21 Dic 2022
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);

Risposte (2)

Voss
Voss il 21 Dic 2022
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 il 21 Dic 2022
Change
[w,rh]=freqz(h,1,64);
to
[rh,w]=freqz(h,1,64);
Good luck.
  1 Commento
William Rose
William Rose il 21 Dic 2022
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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by