Clipping

			
				% fft of a clipped waveform
				clc; clear;

				fi = 100;
				N = 512; % samples
				M = 17; % no. of cycles/bin
				fs = fi/M*N; % sample rate for coherency
				disp(fs);

				t = (0:N-1)/fs; % time vector
				x = sin(2*pi*fi*t); % signal

				subplot(4,1,1);
				plot(t,x); % time domain signal
				xlabel('time');
				ylabel('amplitude');
				title('signal');

				y = fft(x,N); % fft of clipped signal
				Y = abs(y(1:N/2+1)); % single-sided
				Ydb = mag2db(Y); % convert to db
				Ydb = Ydb - max(Ydb);
				n = 1:1:N/2+1;

				subplot(4,1,2);
				stairs(n,Ydb); % coherent FFT
				xlabel('samples');
				ylabel('magnitude');
				grid on;
				title('FFT');

				C_amp = 0.9999; % clipping amplitude
				x(x>C_amp) = C_amp;
				x(x<-1*C_amp) = -1*C_amp;

				subplot(4,1,3);
				plot(t,x); % clipped signal
				xlabel('time');
				ylabel('amplitude');
				title('signal clipped');

				y = fft(x,N); % fft of clipped signal
				Y = abs(y(1:N/2+1)); % single-sided
				Ydb = mag2db(Y); % convert to db
				Ydb = Ydb - max(Ydb);
				f = fs/2*linspace(0,1,N/2+1); % freq vector

				subplot(4,1,4);
				stairs(n,Ydb); % coherent FFT
				xlabel('samples');
				ylabel('magnitude');
				grid on;
				title('FFT clipped');
			
		
© 2018 Copyright. For individual use only. No liability is accepted for any consequences of using information on Testips.com.