i need to get the maximum amplitude in this code but my final answer is wrong

2 ビュー (過去 30 日間)
dulanga
dulanga 2019 年 4 月 16 日
コメント済み: dulanga 2019 年 4 月 17 日
The data file
i get 28400 as the answer but the answer is wrong plus the question want its to 1 dp so i am fairly certain my code is wrong please help
load('data.mat');
dt=t(2)-t(1);% t vector has equally spaced t so this seprates t values
N=length(t);
F=fft(f,N); %fast fourier transform of f/N
Fshifted=fftshift(F);%place 0 frequency in the centre
Fmag=abs(Fshifted);%magnitude of fshifted
nu_NY=(1/dt)/2;%nquist frequency
nu=linspace(0,nu_NY,N/2+1);%spectrum of frequncy vals associated with FFT frequencies
%adding postive and negative frequncies
F1=Fmag((N/2)+1:N);
F2=Fmag(N/2:-1:1);
a=[F1,0]+[0,F2];
%plotting amplitued vs assoicated frequencies
plot(nu,a)

採用された回答

Star Strider
Star Strider 2019 年 4 月 16 日
i am fairly certain my code is wrong
So am I.
Try this:
D = load('Data.mat');
f = D.f;
t = D.t;
dt=t(2)-t(1);% t vector has equally spaced t so this seprates t values
N=numel(t);
F=fft(f)/N; %fast fourier transform of f/N
Fshifted=fftshift(F);%place 0 frequency in the centre
Fmag=abs(Fshifted);%magnitude of fshifted
nu_NY=(1/dt)/2;%nquist frequency
nu=linspace(-nu_NY,nu_NY,N);%spectrum of frequncy vals associated with FFT frequencies
%adding postive and negative frequncies
F1=Fmag((N/2)+1:N);
F2=Fmag(N/2:-1:1);
% a=[F1,0]+[0,F2];
%plotting amplitued vs assoicated frequencies
plot(nu,abs(Fshifted)*2)
[pks,locs] = findpeaks(abs(Fshifted)*2, 'MinPeakHeight',10);
fprintf(1,'Peak Frequencies & Amplitudes:\n\tFrequency\tAmplitude\n')
fprintf(1,'\t%8.4f\t%8.4f\n', [nu(locs); pks])
producing:
Peak Frequencies & Amplitudes:
Frequency Amplitude
-7.9790 14.2000
8.0290 14.2000
My changes are primarily with respect to ‘nu’, although I also correctly scaled the result of your fft call. I added a call to findpeaks (link). (I did not delete parts of your code that I believe to be irrelevant to what you want to do.)
  3 件のコメント
Star Strider
Star Strider 2019 年 4 月 17 日
As always, my pleasure.
dulanga
dulanga 2019 年 4 月 17 日
hey star could u help me in this too i want to make frequncies higher than 3500 zero and amplify the remianing onces.
the unfiltered waw file-
this is my code i still get high pitches sounds...plz help
[y,fs]=audioread('unfiltered_sound.wav1');
f=fft(y);
[ind,~] = find(f>=3500);
b = f;
b(ind) = 0;
c = b*3000;
x=ifft(c);
filename = 'filtered_sound.wav';
audiowrite(filename,c,fs);
clear c fs

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFourier Analysis and Filtering についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by